1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
7 [ ! -f /var
/run
/chronyd.pid
] && (
8 /usr
/sbin
/chronyd
-f /etc
/chrony
/chrony.conf
15 config_get NTP_SERVERS
$CONFIG_SECTION TimeServers
16 config_get CLIENT_NETWORKS
$CONFIG_SECTION ClientAccessFrom
17 CHRONY_KEY
=$
(awk '/^1 / { print $2; }' /etc
/chrony
/chrony.keys
)
19 .
/lib
/functions
/network.sh
21 # Define servers and do a rapid series of time measurements
24 echo password
$CHRONY_KEY
25 for NTP_SERVER
in $NTP_SERVERS; do
26 echo add server
$NTP_SERVER
29 ) | chronyc
> /dev
/null
2>&1
30 # ... wait until a reference ID is found ...
31 while chronyc tracking |
grep 'Reference ID.*0.0.0.0' >/dev
/null
; do sleep 1; done
32 # ... and finally, adjust the time in a single step
33 # and allow clients to access the server
35 echo password
$CHRONY_KEY
37 for NETNAME
in $CLIENT_NETWORKS; do
39 if network_get_subnet subnet
"$NETNAME"; then
43 ) | chronyc
> /dev
/null
2>&1
48 [ -r /var
/run
/chronyd.pid
] && PID
=$
(cat /var
/run
/chronyd.pid
)
49 [ -n "$PID" ] && kill $PID
54 while [ -r /var
/run
/chronyd.pid
] ; do sleep 1; done