From 9b6bf4695797f582ccf89d45d026161d566c6169 Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 18 Dec 2023 12:10:09 +0100 Subject: [PATCH] chrony: add ntp hotplug provider script When the service is started, wait for the clock to be synchronized for up to 5 minutes and provide the stratum action once for ntp hotplug scripts. Signed-off-by: Miroslav Lichvar --- net/chrony/Makefile | 1 + net/chrony/files/chrony.ntp-hotplug | 6 ++++++ net/chrony/files/chronyd.init | 5 +++++ 3 files changed, 12 insertions(+) create mode 100644 net/chrony/files/chrony.ntp-hotplug diff --git a/net/chrony/Makefile b/net/chrony/Makefile index 338493bd5..dc8fd678c 100644 --- a/net/chrony/Makefile +++ b/net/chrony/Makefile @@ -85,6 +85,7 @@ define Package/chrony/install $(INSTALL_DIR) $(1)/usr/sbin/ $(INSTALL_BIN) $(PKG_BUILD_DIR)/chronyd $(1)/usr/sbin $(INSTALL_BIN) $(PKG_BUILD_DIR)/chronyc $(1)/usr/bin + $(INSTALL_BIN) ./files/chrony.ntp-hotplug $(1)/usr/sbin/chrony-hotplug $(INSTALL_DIR) $(1)/etc/init.d $(INSTALL_DIR) $(1)/etc/config $(INSTALL_DIR) $(1)/etc/chrony diff --git a/net/chrony/files/chrony.ntp-hotplug b/net/chrony/files/chrony.ntp-hotplug new file mode 100644 index 000000000..1651b95fb --- /dev/null +++ b/net/chrony/files/chrony.ntp-hotplug @@ -0,0 +1,6 @@ +#!/bin/sh +# Wait for sync for up to 5 minutes and notify other services + +/usr/bin/chronyc waitsync 300 1 0.0 1 || exit 0 + +ubus call hotplug.ntp call '{ "env": [ "ACTION=stratum" ] }' diff --git a/net/chrony/files/chronyd.init b/net/chrony/files/chronyd.init index a734d431e..a043224ec 100644 --- a/net/chrony/files/chronyd.init +++ b/net/chrony/files/chronyd.init @@ -4,6 +4,7 @@ START=15 USE_PROCD=1 PROG=/usr/sbin/chronyd +HOTPLUG=/usr/sbin/chrony-hotplug CONFIGFILE=/etc/chrony/chrony.conf INCLUDEFILE=/var/etc/chrony.d/10-uci.conf RTCDEVICE=/dev/rtc0 @@ -79,6 +80,10 @@ start_service() { procd_set_param file $INCLUDEFILE procd_close_instance + procd_open_instance + procd_set_param command $HOTPLUG + procd_close_instance + config_load chrony mkdir -p $(dirname $INCLUDEFILE)