lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

chronyd.init (1854B)


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