busybox: fix validation in sysntpd init script
[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
9 validate_ntp_section() {
10         uci_validate_section system timeserver "${1}" \
11                 'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0'
12         return $?
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         for peer in $server; do
31                 procd_append_param command -p $peer
32         done
33         procd_set_param respawn
34         procd_close_instance
35 }
36
37 service_triggers()
38 {
39         procd_add_reload_trigger "system"
40         procd_add_validation validate_ntp_section
41 }