mirror of
https://github.com/novatiq/packages.git
synced 2026-04-30 07:28:39 +01:00
chrony: improve hotplug and init scripts
- fix the init script to read the right config - rework the init script to allow reusing its code in the hotplug script - find wan interfaces in the hotplug script instead of using hardcoded name and set the online/offline status separately for IPv4/IPv6 - allow NTP access on interfaces that are configured after chronyd start - add NTP servers obtained from DHCP, options are specified in a new dhcp_ntp_server config section - start chronyd before the network service, include a patch to always have IP_FREEBIND defined, which seems to be missing with uclibc Signed-off-by: Miroslav Lichvar <mlichvar0@gmail.com>
This commit is contained in:
@@ -1,6 +1,44 @@
|
||||
COMMAND=/usr/bin/chronyc
|
||||
#!/bin/sh
|
||||
# Set chronyd online/offline status, allow NTP access and add servers from DHCP
|
||||
|
||||
[ -x $COMMAND ] || exit 0
|
||||
[ "$ACTION" = ifup -o "$ACTION" = ifdown ] || exit 0
|
||||
|
||||
[ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && $COMMAND online
|
||||
[ "$ACTION" = "ifdown" -a "$INTERFACE" = "wan" ] && $COMMAND offline
|
||||
run_command() {
|
||||
/usr/bin/chronyc -n "$*" > /dev/null 2>&1
|
||||
}
|
||||
|
||||
run_command tracking || exit 0
|
||||
|
||||
. /lib/functions/network.sh
|
||||
|
||||
network_find_wan iface4
|
||||
network_find_wan6 iface6
|
||||
run_command $([ -n "$iface4" ] && echo online || echo offline) 0.0.0.0/0.0.0.0
|
||||
run_command $([ -n "$iface6" ] && echo online || echo offline) ::/0
|
||||
|
||||
[ "$ACTION" = ifup ] || exit 0
|
||||
|
||||
. /lib/functions.sh
|
||||
. /etc/init.d/chronyd
|
||||
|
||||
config_load chrony
|
||||
|
||||
config_foreach handle_allow allow | while read command; do
|
||||
run_command "$command"
|
||||
done
|
||||
|
||||
# Add servers from DHCP only if the config has a dhcp_ntp_server section
|
||||
[ -z "$(config_foreach echo dhcp_ntp_server)" ] && exit 0
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
for iface in $iface4 $iface6; do
|
||||
json_load "$(ifstatus $iface)"
|
||||
json_select data
|
||||
json_get_var dhcp_ntp_servers ntpserver
|
||||
|
||||
for server in $dhcp_ntp_servers; do
|
||||
run_command add $(NTP_SOURCE_HOSTNAME=$server config_foreach \
|
||||
handle_source dhcp_ntp_server server)
|
||||
done
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user