2010-01-14 02:37:34 +05:30
|
|
|
#!/bin/sh
|
|
|
|
|
2010-01-26 00:00:16 +05:30
|
|
|
# Note that there is no provision to prevent several copies of the script
|
|
|
|
# to be run in quick succession. In fact, it happens rather often
|
|
|
|
# if initial syncronization results in a step.
|
|
|
|
# You will see "step" and then "stratum" script runs, sometimes
|
|
|
|
# as close as only 0.002 seconds apart.
|
|
|
|
#
|
|
|
|
# Script should be ready to deal with this.
|
2010-01-14 02:37:34 +05:30
|
|
|
|
|
|
|
dt=`date '+%Y-%m-%d %H:%M:%S'`
|
|
|
|
|
2015-04-01 01:30:55 +05:30
|
|
|
echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
|
|
|
|
|
|
|
|
if test x"$1" = x"unsync" \
|
|
|
|
; then
|
|
|
|
# No replies for our NTP requests were seen for some time.
|
|
|
|
#
|
|
|
|
# Among more mundate cases like network outages, this happens
|
|
|
|
# if we ran for a LONG time (days) and ntp server's IP has changed.
|
|
|
|
# ntpd has no code to re-resolve peers' addresses to IPs,
|
|
|
|
# we need to help it:
|
|
|
|
#
|
|
|
|
echo "$dt: $1"\
|
|
|
|
"syncronization lost, restarting ntpd"\
|
|
|
|
>>"$0.log.$$"
|
|
|
|
mv -- "$0.log.$$" "$0.log"
|
|
|
|
kill $PPID
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2010-01-14 02:37:34 +05:30
|
|
|
if test x"$stratum" != x"" \
|
|
|
|
&& test x"$poll_interval" != x"" \
|
|
|
|
&& test 4 -ge "$stratum" \
|
|
|
|
&& test 128 -le "$poll_interval" \
|
|
|
|
; then
|
|
|
|
echo "$dt: $1"\
|
|
|
|
"freq_drift_ppm=$freq_drift_ppm"\
|
|
|
|
"offset=$offset"\
|
|
|
|
"stratum=$stratum"\
|
|
|
|
"poll_interval=$poll_interval,"\
|
2010-01-26 00:00:16 +05:30
|
|
|
"setting hardware clock"\
|
|
|
|
>>"$0.log.$$"
|
|
|
|
mv -- "$0.log.$$" "$0.log"
|
2010-01-14 02:37:34 +05:30
|
|
|
exec hwclock --systohc
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "$dt: $1"\
|
|
|
|
"freq_drift_ppm=$freq_drift_ppm"\
|
|
|
|
"offset=$offset"\
|
|
|
|
"stratum=$stratum"\
|
|
|
|
"poll_interval=$poll_interval"\
|
2010-01-26 00:00:16 +05:30
|
|
|
>>"$0.log.$$"
|
|
|
|
mv -- "$0.log.$$" "$0.log"
|