restart ntp hourly if not in sync
[mirror/dsa-puppet.git] / modules / ntp / files / ntp-restart-if-required
1 #!/bin/bash
2
3 [ -e /usr/lib/nagios/plugins/dsa-check-timedatectl ] || exit
4
5 /usr/lib/nagios/plugins/dsa-check-timedatectl -s 2>/dev/null
6 rc=$?
7
8 case "$rc" in
9   1|2)
10     pid=$(pgrep -u ntp ntp)
11     if [ -z "$pid" ]; then
12       service ntp restart
13       exit
14     fi
15
16     age=$(ps -ho etimes "$pid")
17     if [ "$age" -gt 3600 ]; then
18       service ntp restart
19     fi
20     ;;
21   *)
22     ;;
23 esac