-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·43 lines (37 loc) · 1.01 KB
/
entrypoint.sh
File metadata and controls
executable file
·43 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh
set -e
getServiceIP () {
nslookup "$1" 2>/dev/null | grep -oE '(([0-9]{1,3})\.){3}(1?[0-9]{1,3})'
}
waitOrFail () {
maxTries=24
i=0
while [ $i -lt $maxTries ]; do
outStr="$($@)"
if [ $? -eq 0 ];then
echo "$outStr"
return
fi
i=$((i+1))
echo "==> waiting for a dependent service $i/$maxTries" >&2
sleep 5
done
echo "Too many failed attempts" >&2
exit 1
}
NTP_SERVICE_HOST=${NTP_SERVICE_HOST-"127.0.0.1"}
NTP_SERVICE_PORT=${NTP_SERVICE_PORT-"123"}
while getopts "h?d" opt; do
case "$opt" in
h|\?) echo "-d DNS lookup for service discovery"; exit 0;;
d) shift; NTP_SERVICE_HOST="$(waitOrFail getServiceIP "${1-"ntp-server"}")";;
esac
done
shift $((OPTIND-1))
export NTP_SERVER="$NTP_SERVICE_HOST:$NTP_SERVICE_PORT"
if [ $# -eq 0 ]; then
echo "rsntp - ntp server-address: $NTP_SERVER"
exec /usr/local/bin/rsntp -s "${NTP_SERVER}"
fi
[ "$1" = '--' ] && shift
exec /usr/local/bin/rsntp "$@"