blob: 8542181eb4bd7c62cefe3e2dc25cb11668b5d31e [file] [log] [blame]
Denys Vlasenko4fc82e02010-01-13 22:07:34 +01001#!/bin/sh
2
Denys Vlasenko24928ff2010-01-25 19:30:16 +01003# Note that there is no provision to prevent several copies of the script
4# to be run in quick succession. In fact, it happens rather often
5# if initial syncronization results in a step.
6# You will see "step" and then "stratum" script runs, sometimes
7# as close as only 0.002 seconds apart.
8#
9# Script should be ready to deal with this.
Denys Vlasenko4fc82e02010-01-13 22:07:34 +010010
11dt=`date '+%Y-%m-%d %H:%M:%S'`
12
Denys Vlasenko11868942015-03-31 22:00:55 +020013echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
14
15if test x"$1" = x"unsync" \
16; then
17 # No replies for our NTP requests were seen for some time.
18 #
19 # Among more mundate cases like network outages, this happens
20 # if we ran for a LONG time (days) and ntp server's IP has changed.
21 # ntpd has no code to re-resolve peers' addresses to IPs,
22 # we need to help it:
23 #
24 echo "$dt: $1"\
25 "syncronization lost, restarting ntpd"\
26 >>"$0.log.$$"
27 mv -- "$0.log.$$" "$0.log"
28 kill $PPID
29 exit
30fi
31
Denys Vlasenko4fc82e02010-01-13 22:07:34 +010032if test x"$stratum" != x"" \
33&& test x"$poll_interval" != x"" \
34&& test 4 -ge "$stratum" \
35&& test 128 -le "$poll_interval" \
36; then
37 echo "$dt: $1"\
38 "freq_drift_ppm=$freq_drift_ppm"\
39 "offset=$offset"\
40 "stratum=$stratum"\
41 "poll_interval=$poll_interval,"\
Denys Vlasenko24928ff2010-01-25 19:30:16 +010042 "setting hardware clock"\
43 >>"$0.log.$$"
44 mv -- "$0.log.$$" "$0.log"
Denys Vlasenko4fc82e02010-01-13 22:07:34 +010045 exec hwclock --systohc
46fi
47
48echo "$dt: $1"\
49 "freq_drift_ppm=$freq_drift_ppm"\
50 "offset=$offset"\
51 "stratum=$stratum"\
52 "poll_interval=$poll_interval"\
Denys Vlasenko24928ff2010-01-25 19:30:16 +010053 >>"$0.log.$$"
54mv -- "$0.log.$$" "$0.log"