added clock sync setup
authorStephen Mahood (marxistvegan) <mv@fsf.org>
Thu, 18 Jun 2015 20:50:11 +0000 (16:50 -0400)
committerStephen Mahood (marxistvegan) <mv@fsf.org>
Thu, 18 Jun 2015 20:50:11 +0000 (16:50 -0400)
files/etc/cron.d/ntpdate/DEFAULT [new file with mode: 0644]
files/usr/local/bin/clock-sync.sh/DEFAULT [new file with mode: 0644]
scripts/DEFAULT/20_clock_setup [new file with mode: 0755]

diff --git a/files/etc/cron.d/ntpdate/DEFAULT b/files/etc/cron.d/ntpdate/DEFAULT
new file mode 100644 (file)
index 0000000..3ee63f1
--- /dev/null
@@ -0,0 +1,4 @@
+# Make sure that our clock stays more or less within sync
+# The clock-sync script automatically adjusts if it is run on a Xen domU
+
+0 * * * * root /usr/local/bin/clock-sync.sh
diff --git a/files/usr/local/bin/clock-sync.sh/DEFAULT b/files/usr/local/bin/clock-sync.sh/DEFAULT
new file mode 100644 (file)
index 0000000..448b394
--- /dev/null
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+# 2014/04/10 Lisa
+# Modified this script to use the usn pool from pool.ntp.org. More
+# Info on this can be found at the project page: http://www.pool.ntp.org/zone/us
+
+if [ -d /proc/sys/xen ]; then
+   echo 1 > /proc/sys/xen/independent_wallclock;
+fi
+
+servers='0.us.pool.ntp.org 1.us.pool.ntp.org 2.us.pool.ntp.org 3.us.pool.ntp.org'
+
+
+/usr/sbin/ntpdate $servers >/dev/null 2>&1
+rc="$?"
+
+if [ $rc -ne 0 ] ; then
+   /usr/sbin/ntpdate $servers 2>&1 \
+   | grep -q ': the NTP socket is in use, exiting$'
+if [ $? -eq 0 ] ; then
+   exit 0          # machine is running NTP daemon
+fi
+       for backoff in 15 30 60 300 ; do
+       sleep $backoff
+       /usr/sbin/ntpdate $servers >/dev/null 2>&1
+       rc="$?"
+       [ $rc -eq 0 ] && break
+       done
+fi
+
+if [ $rc -ne 0 ] ; then
+   echo "ntpdate failed, trying again"
+   # try again, and be verbose
+   date
+   ping -c 3 $servers
+   /usr/sbin/ntpdate $servers 2>&1
+   if [ $? -ne 0 ] ; then
+   # DNS failure?
+   sleep 300
+   date
+   ping -c 3 $servers
+   /usr/sbin/ntpdate $server 2>&1
+if [ $? -ne 0 ] ; then
+   exit
+   fi
+   fi
+   fi
+
+if [ -e /dev/rtc ]; then
+   /sbin/hwclock -w
+fi
diff --git a/scripts/DEFAULT/20_clock_setup b/scripts/DEFAULT/20_clock_setup
new file mode 100755 (executable)
index 0000000..5d985a8
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+
+fcopy -v /etc/cron.d/ntpdate
+
+fcopy -v /usr/local/bin/clock-sync.sh