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