You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.2 KiB
Bash

#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2011 OpenWrt.org
START=65
STOP=65
USE_PROCD=1
PROG=/sbin/ntpd
HOTPLUG_HELPER=/usr/sbin/ntpd.hotplug-helper
CONFIG_FILE=/var/run/ntpd.conf
validate_ntp_section() {
uci_validate_section system timeserver "${1}" \
'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0'
}
start_service() {
mkdir -p /var/lib/ntp
local server enabled enable_server peer restrict
validate_ntp_section ntp || {
echo "validation failed"
return 1
}
[ $enabled = 0 ] && return
[ -z "$server" ] && return
if [ $enable_server = 0 ]; then
restrict="ignore"
else
restrict="nomodify noquery notrap"
fi
cat >$CONFIG_FILE <<EOF
driftfile /var/lib/ntp/ntp.drift
restrict default $restrict
restrict source nomodify noquery notrap
restrict 127.0.0.1
restrict ::1
EOF
for peer in $server; do
echo "pool $peer iburst" >>$CONFIG_FILE
done
procd_open_instance
procd_set_param command $PROG -g -p /var/run/ntpd.pid -c $CONFIG_FILE -n
procd_set_param respawn
procd_set_param file $CONFIG_FILE
procd_close_instance
procd_open_instance
procd_set_param command $HOTPLUG_HELPER
procd_close_instance
}
service_triggers()
{
procd_add_reload_trigger "system"
procd_add_validation validate_ntp_section
}