3
0

ntp.script 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. # For other parts of the system which prefer to run only on the stable clock
  10. echo "$1" >rundir/sync_status
  11. dt=`date '+%Y-%m-%d %H:%M:%S'`
  12. echo "`tail -n 199 -- "$0.log" 2>/dev/null`" >"$0.log.$$"
  13. if test x"$1" = x"unsync" \
  14. ; then
  15. # No replies for our NTP requests were seen for some time.
  16. #
  17. # Among more mundate cases like network outages, this happens
  18. # if we ran for a LONG time (days) and ntp server's IP has changed.
  19. # ntpd has no code to re-resolve peers' addresses to IPs,
  20. # we need to help it:
  21. #
  22. echo "$dt: $1"\
  23. "syncronization lost, restarting ntpd"\
  24. >>"$0.log.$$"
  25. mv -- "$0.log.$$" "$0.log"
  26. kill $PPID
  27. exit
  28. fi
  29. if test x"$stratum" != x"" \
  30. && test x"$poll_interval" != x"" \
  31. && test 4 -ge "$stratum" \
  32. && test 128 -le "$poll_interval" \
  33. ; then
  34. echo "$dt: $1"\
  35. "freq_drift_ppm=$freq_drift_ppm"\
  36. "offset=$offset"\
  37. "stratum=$stratum"\
  38. "poll_interval=$poll_interval,"\
  39. "setting hardware clock"\
  40. >>"$0.log.$$"
  41. mv -- "$0.log.$$" "$0.log"
  42. exec hwclock --systohc
  43. fi
  44. echo "$dt: $1"\
  45. "freq_drift_ppm=$freq_drift_ppm"\
  46. "offset=$offset"\
  47. "stratum=$stratum"\
  48. "poll_interval=$poll_interval"\
  49. >>"$0.log.$$"
  50. mv -- "$0.log.$$" "$0.log"