ntpd: add hotplug script that signals when ntp reaches the stratum level like the...
authorPeter Wagner <tripolar@gmx.at>
Mon, 16 Jan 2017 21:28:01 +0000 (22:28 +0100)
committerJo-Philipp Wich <jo@mein.io>
Sun, 5 Feb 2017 18:38:14 +0000 (19:38 +0100)
use ntpq to check the status of the ntp server as all other status scripts included in the ntp tarball are
based on perl which would dramatically increase the footprint of ntpd

Signed-off-by: Peter Wagner <tripolar@gmx.at>
net/ntpd/Makefile
net/ntpd/files/ntpd.hotplug-helper [new file with mode: 0644]
net/ntpd/files/ntpd.init

index 2e97575542d5a0cc620b90c1d87a51f76cb0d2c4..e16669611c9e1d723de93229169b1fe55b9464fe 100644 (file)
@@ -13,7 +13,7 @@ PKG_RELEASE:=1
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
 PKG_SOURCE_URL:=http://www.eecis.udel.edu/~ntp/ntp_spool/ntp4/ntp-4.2/
-PKG_MD5SUM:=857452b05f5f2e033786f77ade1974ed
+PKG_HASH:=b724287778e1bac625b447327c9851eedef020517a3545625e9f652a90f30b72
 
 PKG_LICENSE:=Unique
 PKG_LICENSE_FILES:=COPYRIGHT html/copyright.html
@@ -115,6 +115,9 @@ CONFIGURE_ARGS += \
 define Package/ntpd/install
        $(INSTALL_DIR) $(1)/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpd/ntpd $(1)/sbin/
+       $(INSTALL_DIR) $(1)/usr/sbin
+       $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpq/ntpq $(1)/usr/sbin/
+       $(INSTALL_BIN) ./files/ntpd.hotplug-helper $(1)/usr/sbin/ntpd.hotplug-helper
        $(INSTALL_DIR) $(1)/etc
        $(INSTALL_CONF) ./files/ntp.conf $(1)/etc/
        $(INSTALL_DIR) $(1)/etc/init.d
@@ -145,7 +148,6 @@ endef
 define Package/ntp-utils/install
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpdc/ntpdc $(1)/usr/sbin/
-       $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpq/ntpq $(1)/usr/sbin/
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/util/ntptime $(1)/usr/sbin/
 endef
 
diff --git a/net/ntpd/files/ntpd.hotplug-helper b/net/ntpd/files/ntpd.hotplug-helper
new file mode 100644 (file)
index 0000000..39d3df0
--- /dev/null
@@ -0,0 +1,15 @@
+#!/bin/sh
+
+HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug
+
+while true
+do
+       STATUS="$(ntpq -c 'rv 0 stratum'|awk -F '=' '{ print $2 }')"
+
+       if [ -n "$STATUS" ] && [ "$STATUS" -lt "16" ]
+       then
+               ACTION="stratum" /sbin/hotplug-call ntp
+               exit 0
+       fi
+       sleep 10
+done
index e626e248ff2099fd6fec27cd1567fca80d688a04..55dd3e84f1eeb132ddd03a9c42c69c0941a5f5d2 100644 (file)
@@ -5,14 +5,18 @@ START=65
 STOP=65
 
 USE_PROCD=1
+PROG=/sbin/ntpd
+HOTPLUG_HELPER=/usr/sbin/ntpd.hotplug-helper
 
 start_service() {
-#      ln -sf /dev/ttyS0 /dev/gps0
-#      /usr/sbin/setgarmin -d /dev/gps -c /etc/setgarmin.conf
        mkdir -p /var/lib/ntp
        chown -R ntp:ntp /var/lib/ntp
 
        procd_open_instance
-       procd_set_param command /sbin/ntpd -g -u ntp:ntp -p /var/run/ntpd.pid -n
+       procd_set_param command $PROG -g -u ntp:ntp -p /var/run/ntpd.pid -n
+       procd_close_instance
+
+       procd_open_instance
+       procd_set_param command $HOTPLUG_HELPER
        procd_close_instance
 }