sysntpd 885 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2011 OpenWrt.org
  3. START=98
  4. USE_PROCD=1
  5. PROG=/usr/sbin/ntpd
  6. HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug
  7. validate_ntp_section() {
  8. uci_validate_section system timeserver "${1}" \
  9. 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0'
  10. }
  11. start_service() {
  12. local server enabled enable_server peer
  13. validate_ntp_section ntp || {
  14. echo "validation failed"
  15. return 1
  16. }
  17. [ $enabled = 0 ] && return
  18. [ -z "$server" ] && return
  19. procd_open_instance
  20. procd_set_param command "$PROG" -n
  21. [ "$enable_server" = "1" ] && procd_append_param command -l
  22. [ -x "$HOTPLUG_SCRIPT" ] && procd_append_param command -S "$HOTPLUG_SCRIPT"
  23. for peer in $server; do
  24. procd_append_param command -p $peer
  25. done
  26. procd_set_param respawn
  27. procd_close_instance
  28. }
  29. service_triggers()
  30. {
  31. procd_add_reload_trigger "system"
  32. procd_add_validation validate_ntp_section
  33. }