chrony: import from oldpackages
[feed/packages.git] / net / chrony / files / chronyd.init
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3
4 START=60
5 USE_PROCD=1
6 PROG=/usr/sbin/chronyd
7 CONFIGFILE=/var/etc/chrony.conf
8
9 handle_source() {
10 local cfg=$1 sourcetype=$2 hostname minpoll maxpoll iburst
11
12 config_get hostname "$cfg" hostname
13 [ -z "$hostname" ] && return
14 config_get minpoll "$cfg" minpoll
15 config_get maxpoll "$cfg" maxpoll
16 config_get_bool iburst "$cfg" iburst 0
17 echo $(
18 echo $sourcetype $hostname
19 [ -n "$minpoll" ] && echo minpoll $minpoll
20 [ -n "$maxpoll" ] && echo maxpoll $maxpoll
21 [ "$iburst" = "1" ] && echo iburst
22 ) >> $CONFIGFILE
23 }
24
25 handle_allow() {
26 local cfg=$1 iface wan_iface wan6_iface subnet subnets subnets6
27
28 network_find_wan wan_iface true
29 network_find_wan6 wan6_iface true
30 config_get iface "$cfg" interface
31
32 if [ "$wan_iface" = "$iface" ]; then
33 echo allow >> $CONFIGFILE
34 else
35 network_get_subnets subnets $iface || \
36 network_get_subnets subnets6 $iface || continue
37 for subnet in $subnets $subnets6; do
38 echo allow $subnet >> $CONFIGFILE
39 done
40 fi
41 }
42
43 handle_makestep() {
44 local cfg=$1 threshold limit
45
46 config_get threshold "$cfg" threshold
47 config_get limit "$cfg" limit
48 [ -z "$threshold" -o -z "$limit" ] && return
49 echo makestep $threshold $limit >> $CONFIGFILE
50 }
51
52 start_service() {
53 . /lib/functions/network.sh
54
55 procd_open_instance
56 procd_set_param command $PROG -n -f $CONFIGFILE
57 procd_set_param file $CONFIGFILE
58 procd_set_param file /etc/chrony/chrony.conf
59 procd_close_instance
60
61 echo include /etc/chrony/chrony.conf > $CONFIGFILE
62
63 config_load ntpd
64 config_foreach handle_source server server
65 config_foreach handle_source pool pool
66 config_foreach handle_source peer peer
67 config_foreach handle_allow allow
68 config_foreach handle_makestep makestep
69 }