S48sntp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/sh
  2. DAEMON="sntp"
  3. # sntp uses all the IPs resolved for the hostname (i.e. pool.ntp.org has 4).
  4. # It will try each until they either all timeout or time has been set. Thus
  5. # default to only providing one NTP pool host.
  6. SNTP_SERVERS="pool.ntp.org"
  7. # Step if time delta is greater then 128ms, otherwise slew
  8. SNTP_ARGS="-Ss -M 128"
  9. SNTP_KEY_CACHE="/tmp/kod"
  10. # shellcheck source=/dev/null
  11. [ -r "/etc/default/$DAEMON" ] && . "/etc/default/$DAEMON"
  12. start() {
  13. printf 'Starting %s: ' "$DAEMON"
  14. # Create key cache file to prevents warning that file is missing
  15. touch $SNTP_KEY_CACHE
  16. # shellcheck disable=SC2086 # we need the word splitting
  17. /usr/bin/$DAEMON $SNTP_ARGS -K $SNTP_KEY_CACHE $SNTP_SERVERS
  18. # sntp behavior
  19. # - Does not background
  20. # - Does not infinitely block
  21. # - Time-out w/o network = ~2 sec
  22. # - Time-out w/ network = ~5sec * # of servers
  23. status=$?
  24. if [ "$status" -eq 0 ]; then
  25. echo "OK"
  26. else
  27. echo "FAIL"
  28. fi
  29. return "$status"
  30. }
  31. stop() {
  32. echo "Nothing to do, $DAEMON is not a daemon."
  33. }
  34. restart() {
  35. stop
  36. sleep 1
  37. start
  38. }
  39. reload() {
  40. echo "Nothing to do, $DAEMON does not support reload."
  41. }
  42. case "$1" in
  43. start|stop|restart|reload)
  44. "$1";;
  45. *)
  46. echo "Usage: $0 {start|stop|restart|reload}"
  47. exit 1
  48. esac