2007-03-17 11:34:51 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
|
|
|
|
START=60
|
|
|
|
|
|
|
|
start() {
|
|
|
|
[ ! -f /var/run/chronyd.pid ] && (
|
|
|
|
/usr/sbin/chronyd -f /etc/chrony/chrony.conf
|
2008-01-14 10:38:27 +00:00
|
|
|
|
2007-03-17 11:34:51 +00:00
|
|
|
local NTP_SERVERS
|
|
|
|
local NTP_SERVER
|
|
|
|
local CLIENT_NETWORKS
|
|
|
|
local NETNAME
|
|
|
|
config_load ntpd
|
2009-07-26 11:39:11 +00:00
|
|
|
config_get NTP_SERVERS $CONFIG_SECTION TimeServers
|
|
|
|
config_get CLIENT_NETWORKS $CONFIG_SECTION ClientAccessFrom
|
2007-03-17 11:34:51 +00:00
|
|
|
CHRONY_KEY=$(awk '/^1 / { print $2; }' /etc/chrony/chrony.keys)
|
2012-05-29 01:47:55 +00:00
|
|
|
|
|
|
|
. /lib/functions/network.sh
|
2008-01-14 10:38:27 +00:00
|
|
|
|
2007-03-17 11:34:51 +00:00
|
|
|
# Define servers and do a rapid series of time measurements
|
|
|
|
# to get up to date
|
|
|
|
(
|
2008-01-14 10:38:27 +00:00
|
|
|
echo password $CHRONY_KEY
|
|
|
|
for NTP_SERVER in $NTP_SERVERS; do
|
|
|
|
echo add server $NTP_SERVER
|
|
|
|
done
|
|
|
|
echo burst 5/5
|
|
|
|
) | chronyc > /dev/null 2>&1
|
|
|
|
# ... wait until a reference ID is found ...
|
|
|
|
while chronyc tracking | grep 'Reference ID.*0.0.0.0' >/dev/null ; do sleep 1; done
|
|
|
|
# ... and finally, adjust the time in a single step
|
|
|
|
# and allow clients to access the server
|
2007-03-17 11:34:51 +00:00
|
|
|
(
|
2008-01-14 10:38:27 +00:00
|
|
|
echo password $CHRONY_KEY
|
|
|
|
echo makestep
|
|
|
|
for NETNAME in $CLIENT_NETWORKS; do
|
2012-05-29 01:47:55 +00:00
|
|
|
local subnet
|
|
|
|
if network_get_subnet subnet "$NETNAME"; then
|
|
|
|
echo allow $subnet
|
2008-01-14 10:38:27 +00:00
|
|
|
fi
|
|
|
|
done
|
2007-03-17 11:34:51 +00:00
|
|
|
) | chronyc > /dev/null 2>&1
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
|
|
|
[ -r /var/run/chronyd.pid ] && PID=$(cat /var/run/chronyd.pid)
|
2008-01-14 10:38:27 +00:00
|
|
|
[ -n "$PID" ] && kill $PID
|
2007-03-17 11:34:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
|
|
|
stop
|
|
|
|
while [ -r /var/run/chronyd.pid ] ; do sleep 1; done
|
|
|
|
start
|
|
|
|
}
|