From 5905589f476b41154c6ca04d6ea58284c980ab75 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 25 Jan 2017 11:31:38 +0100 Subject: [PATCH] restart ntp hourly if not in sync --- .../templates/dsa-puppet-stuff.cron.erb | 2 ++ modules/ntp/files/ntp-restart-if-required | 23 +++++++++++++++++++ modules/ntp/manifests/client.pp | 4 ++++ 3 files changed, 29 insertions(+) create mode 100755 modules/ntp/files/ntp-restart-if-required diff --git a/modules/debian-org/templates/dsa-puppet-stuff.cron.erb b/modules/debian-org/templates/dsa-puppet-stuff.cron.erb index 3aa7328f1..48fab729d 100644 --- a/modules/debian-org/templates/dsa-puppet-stuff.cron.erb +++ b/modules/debian-org/templates/dsa-puppet-stuff.cron.erb @@ -16,3 +16,5 @@ SHELL=/bin/bash @daily munin-async [ -d /var/lib/munin-async ] && find /var/lib/munin-async -maxdepth 1 -type f -mtime +30 -delete @daily root [ -d /var/lib/puppet/clientbucket ] && find /var/lib/puppet/clientbucket -type f -mtime +60 -delete && find /var/lib/puppet/clientbucket -type d -empty -delete + +@hourly root ! [ -x /usr/local/sbin/ntp-restart-if-required ] || /usr/local/sbin/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 index 000000000..6252b827a --- /dev/null +++ b/modules/ntp/files/ntp-restart-if-required @@ -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 diff --git a/modules/ntp/manifests/client.pp b/modules/ntp/manifests/client.pp index 9fd935652..d36b5d49a 100644 --- a/modules/ntp/manifests/client.pp +++ b/modules/ntp/manifests/client.pp @@ -34,4 +34,8 @@ class ntp::client { file { '/etc/ntp.keys.d/ntpkey_iff_busoni': ensure => absent, } + file { '/usr/local/sbin/ntp-restart-if-required': + source => 'puppet:///modules/ntp/ntp-restart-if-required', + mode => '0555', + } } -- 2.20.1