From 23240f04aaf89e92f9d247c7f79274e318b2d155 Mon Sep 17 00:00:00 2001 From: "Stephen Mahood (marxistvegan)" Date: Thu, 18 Jun 2015 16:50:11 -0400 Subject: [PATCH 1/1] added clock sync setup --- files/etc/cron.d/ntpdate/DEFAULT | 4 ++ files/usr/local/bin/clock-sync.sh/DEFAULT | 51 +++++++++++++++++++++++ scripts/DEFAULT/20_clock_setup | 5 +++ 3 files changed, 60 insertions(+) create mode 100644 files/etc/cron.d/ntpdate/DEFAULT create mode 100644 files/usr/local/bin/clock-sync.sh/DEFAULT create mode 100755 scripts/DEFAULT/20_clock_setup diff --git a/files/etc/cron.d/ntpdate/DEFAULT b/files/etc/cron.d/ntpdate/DEFAULT new file mode 100644 index 0000000..3ee63f1 --- /dev/null +++ b/files/etc/cron.d/ntpdate/DEFAULT @@ -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 index 0000000..448b394 --- /dev/null +++ b/files/usr/local/bin/clock-sync.sh/DEFAULT @@ -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 index 0000000..5d985a8 --- /dev/null +++ b/scripts/DEFAULT/20_clock_setup @@ -0,0 +1,5 @@ +#!/bin/bash + +fcopy -v /etc/cron.d/ntpdate + +fcopy -v /usr/local/bin/clock-sync.sh -- 2.25.1