-
Notifications
You must be signed in to change notification settings - Fork 1
/
entrypoint.sh
executable file
·59 lines (50 loc) · 1.52 KB
/
entrypoint.sh
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh
set -e
usage () {
echo " -s specify ntp server sources e.g. '-s time.apple.com time.google.com'";
echo " -- to send arguments to chronyd e.g. '-- --help'";
exit 0;
}
numServers=0
setServers() {
sed -i '/server .*/d' /etc/chrony.conf
echo >> /etc/chrony.conf
echo "# NTP Servers" >> /etc/chrony.conf
old_IFS=$IFS
IFS=' '
for server in "$@"
do
numServers=$((numServers+1))
if [ "$server" = '--' ]; then
break
fi
echo "server $server iburst" >> /etc/chrony.conf
done
IFS=$old_IFS
}
while getopts "h?s" opt; do
case "$opt" in
h|\?) usage;;
s) shift; setServers "$@";;
* ) echo "Unknown option: -$OPTARG" >&2; exit 1;;
esac
done
shift "$numServers"
# Remove leftover pid file from previous runs
if [ -f /var/run/chrony/chronyd.pid ]; then
rm -f /var/run/chrony/chronyd.pid
fi
if [ $# -eq 0 ]; then
# https://chrony.tuxfamily.org/doc/3.3/chronyd.html
# -d = Don't detach from terminal and log to stdout/stderr
# -F = Enable system call filter (seccomp)
# in level 1 the process is killed when a forbidden system call is made,
# in level -1 the SIGSYS signal is thrown instead and
# in level 0 the filter is disabled (default 0).
# -s = Set the system clock from the computer’s real-time clock (RTC)
# or to the last modification time of the file specified by
# the driftfile directiv
exec /usr/local/sbin/chronyd -d -F 1 -s
fi
[ "$1" = '--' ] && shift
exec /usr/local/sbin/chronyd "$@"