[2725] | 1 | #!/bin/sh
|
---|
| 2 |
|
---|
| 3 | # 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.
|
---|
| 10 |
|
---|
| 11 | dt=`date '+%Y-%m-%d %H:%M:%S'`
|
---|
| 12 |
|
---|
[3621] | 13 | echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
|
---|
| 14 |
|
---|
| 15 | if 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
|
---|
| 30 | fi
|
---|
| 31 |
|
---|
[2725] | 32 | if 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,"\
|
---|
| 42 | "setting hardware clock"\
|
---|
| 43 | >>"$0.log.$$"
|
---|
| 44 | mv -- "$0.log.$$" "$0.log"
|
---|
| 45 | exec hwclock --systohc
|
---|
| 46 | fi
|
---|
| 47 |
|
---|
| 48 | echo "$dt: $1"\
|
---|
| 49 | "freq_drift_ppm=$freq_drift_ppm"\
|
---|
| 50 | "offset=$offset"\
|
---|
| 51 | "stratum=$stratum"\
|
---|
| 52 | "poll_interval=$poll_interval"\
|
---|
| 53 | >>"$0.log.$$"
|
---|
| 54 | mv -- "$0.log.$$" "$0.log"
|
---|