packages/net/chrony/files/chronyd.init
Miroslav Lichvar 1dc8c501a6 chrony: rework loading of configuration
Instead of loading /etc/chrony/chrony.conf from the file generated from
the chrony UCI configuration, use the confdir directive in the main
config to load the generated file. This should make it obvious that
chrony is configured in UCI and it can also be easily disabled.

Signed-off-by: Miroslav Lichvar <mlichvar0@gmail.com>
2020-10-30 20:02:11 +01:00

75 lines
1.8 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2015 OpenWrt.org
START=15
USE_PROCD=1
PROG=/usr/sbin/chronyd
CONFIGFILE=/etc/chrony/chrony.conf
INCLUDEFILE=/var/etc/chrony.d/10-uci.conf
handle_source() {
local cfg=$1 sourcetype=$2 hostname minpoll maxpoll iburst
hostname=$NTP_SOURCE_HOSTNAME
[ -z "$hostname" ] && config_get hostname "$cfg" hostname
[ -z "$hostname" ] && return
config_get minpoll "$cfg" minpoll
config_get maxpoll "$cfg" maxpoll
config_get_bool iburst "$cfg" iburst 0
echo $(
echo $sourcetype $hostname
[ -n "$minpoll" ] && echo minpoll $minpoll
[ -n "$maxpoll" ] && echo maxpoll $maxpoll
[ "$iburst" = "1" ] && echo iburst
)
}
handle_allow() {
local cfg=$1 iface wan_iface wan6_iface subnet subnets subnets6
network_find_wan wan_iface true
network_find_wan6 wan6_iface true
config_get iface "$cfg" interface
if [ "$wan_iface" = "$iface" ]; then
echo allow 0/0
elif [ "$wan6_iface" = "$iface" ]; then
echo allow ::/0
else
network_get_subnets subnets $iface
network_get_subnets6 subnets6 $iface
for subnet in $subnets $subnets6; do
echo allow $subnet
done
fi
}
handle_makestep() {
local cfg=$1 threshold limit
config_get threshold "$cfg" threshold
config_get limit "$cfg" limit
[ -z "$threshold" -o -z "$limit" ] && return
echo makestep $threshold $limit
}
start_service() {
. /lib/functions/network.sh
procd_open_instance
procd_set_param command $PROG -n
procd_set_param file $CONFIGFILE
procd_set_param file $INCLUDEFILE
procd_close_instance
config_load chrony
mkdir -p $(dirname $INCLUDEFILE)
(
config_foreach handle_source server server
config_foreach handle_source pool pool
config_foreach handle_source peer peer
config_foreach handle_allow allow
config_foreach handle_makestep makestep
) > $INCLUDEFILE
}