merge r15139 to 8.09 (closes: #4718), bump release number
[openwrt/svn-archive/archive.git] / net / chrony / files / ntpd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3
4 START=60
5
6 start() {
7 [ ! -f /var/run/chronyd.pid ] && (
8 /usr/sbin/chronyd -f /etc/chrony/chrony.conf
9
10 local NTP_SERVERS
11 local NTP_SERVER
12 local CLIENT_NETWORKS
13 local NETNAME
14 config_load ntpd
15 config_get NTP_SERVERS $cfg1 TimeServers
16 config_get CLIENT_NETWORKS $cfg1 ClientAccessFrom
17 CHRONY_KEY=$(awk '/^1 / { print $2; }' /etc/chrony/chrony.keys)
18 include /lib/network
19 scan_interfaces
20
21 # Define servers and do a rapid series of time measurements
22 # to get up to date
23 (
24 echo password $CHRONY_KEY
25 for NTP_SERVER in $NTP_SERVERS; do
26 echo add server $NTP_SERVER
27 done
28 echo burst 5/5
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
34 (
35 echo password $CHRONY_KEY
36 echo makestep
37 for NETNAME in $CLIENT_NETWORKS; do
38 local INTERFACE
39 local IP
40 local NETMASK
41 local BROADCAST
42 local NETWORK
43 local PREFIX
44
45 config_get INTERFACE "$NETNAME" ifname
46 if [ -n "$INTERFACE" ] ; then
47 eval $(ifconfig $INTERFACE | grep inet | sed -e 's/.*addr:/IP=/' -e 's/ .*Mask:/; NETMASK=/')
48 eval $(ipcalc.sh $IP $NETMASK)
49 echo allow $NETWORK/$PREFIX
50 fi
51 done
52 ) | chronyc > /dev/null 2>&1
53 )
54 }
55
56 stop() {
57 [ -r /var/run/chronyd.pid ] && PID=$(cat /var/run/chronyd.pid)
58 [ -n "$PID" ] && kill $PID
59 }
60
61 restart() {
62 stop
63 while [ -r /var/run/chronyd.pid ] ; do sleep 1; done
64 start
65 }