restart ntp hourly if not in sync
[mirror/dsa-puppet.git] / modules / ntp / files / ntp-restart-if-required
diff --git a/modules/ntp/files/ntp-restart-if-required b/modules/ntp/files/ntp-restart-if-required
new file mode 100755 (executable)
index 0000000..6252b82
--- /dev/null
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+[ -e /usr/lib/nagios/plugins/dsa-check-timedatectl ] || exit
+
+/usr/lib/nagios/plugins/dsa-check-timedatectl -s 2>/dev/null
+rc=$?
+
+case "$rc" in
+  1|2)
+    pid=$(pgrep -u ntp ntp)
+    if [ -z "$pid" ]; then
+      service ntp restart
+      exit
+    fi
+
+    age=$(ps -ho etimes "$pid")
+    if [ "$age" -gt 3600 ]; then
+      service ntp restart
+    fi
+    ;;
+  *)
+    ;;
+esac