ntp.script 1.4 KB

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