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.
openwrt/package/utils/busybox/files/sysntpd

91 lines
2.1 KiB
Plaintext

#!/bin/sh /etc/rc.common
# Copyright (C) 2011 OpenWrt.org
START=98
USE_PROCD=1
PROG=/usr/sbin/ntpd
HOTPLUG_SCRIPT=/usr/sbin/ntpd-hotplug
get_dhcp_ntp_servers() {
local interfaces="$1"
local filter="*"
local interface ntpservers ntpserver
for interface in $interfaces; do
[ "$filter" = "*" ] && filter="@.interface='$interface'" || filter="$filter,@.interface='$interface'"
done
ntpservers=$(ubus call network.interface dump | jsonfilter -e "@.interface[$filter]['data']['ntpserver']")
for ntpserver in $ntpservers; do
local duplicate=0
local entry
for entry in $server; do
[ "$ntpserver" = "$entry" ] && duplicate=1
done
[ "$duplicate" = 0 ] && server="$server $ntpserver"
done
}
validate_ntp_section() {
uci_load_validate system timeserver "$1" "$2" \
'server:list(host)' 'enabled:bool:1' 'enable_server:bool:0' 'use_dhcp:bool:1' 'dhcp_interface:list(string)'
}
start_ntpd_instance() {
local peer
[ "$2" = 0 ] || {
echo "validation failed"
return 1
}
enable ntpd server for busybox hi Another version, in this one the enable_server option is in the timeserver ntp part of the "system" config file You can patch trunk and bacfire (tested both) You can put busybox ntpd in client mode (if you put server), in client & server (by putting enable_server to 1, ntpd listen to udp 123), and also in server mode only (if you didn't put any servers in the config and still put enable_server 1, ntpd will answer with the time of the router) I've replaced "config_foreach getpeers timeserver" with "config_get peers ntp server" because we want ntp timeserver, not random ones (to pre-answer if someone want to say that it's intrusive ...) Signed-off-by: Etienne CHAMPETIER <etienne.champetier@free.fr> Le 27/03/2012 20:41, Etienne Champetier a écrit : > I've now tested my trunk patch and it works fine > But I still can't find were $PROG is defined (is this a mistake, or some sort of built in variable???) > (I've made some grep and nothing) > > Le 23/03/2012 02:19, Philip Prindeville a écrit : >> Maybe: >> >> [ -n "$PROG" -a -x "$PROG" ] || return 1 >> >> instead? >> >> >> On 3/22/12 4:34 PM, Etienne Champetier wrote: >>> Hi >>> >>> The 2 attached patchs (trunk & bacfire) add busybox ntpd enable_server option, as busybox ntpd server is compiled by default. >>> We only need 1 client/server daemon (olipro patch was launching 2 daemons) >>> I've fully tested the bacfire patch, and as i don't have a running openwrt trunk i'm not sure for the trunk patch (i'm sure about my modifications, but i'm not sure about "[ -x $PROG ] || return 1", as "$PROG" isn't defined ?!) >>> >>> Signed-off-by: Etienne CHAMPETIER <etienne.champetier@free.fr> >>> >>> >>> Le 16/01/2012 01:57, Philip Prindeville a écrit : >>>> On 1/14/12 11:37 AM, Olipro wrote: >>>>> On Saturday 14 Jan 2012 02:45:59 Philip Prindeville wrote: >>>>>> Don't we already have a 'disabled' option? Now we're adding an >>>>>> 'enable_server' option? >>>>>> >>>>>> That seems confusing for no useful reason. >>>>>> >>>>> have you bothered to read what I originally wrote? your response would make >>>>> me inclined to believe that you didn't. >>>>> >>>>> currently the ntpd initscript only runs it as a CLIENT - this patch enables >>>>> you to have one instance running as a client and another as a SERVER that >>>>> other hosts can synchronise with. >>>>> >>>>> Or perhaps I'm misunderstanding, what would you propose for allowing the >>>>> built-in busybox ntpd to be utilised as a server? a separate init script >>>>> entirely perhaps? >>>> Or separate config sections... instead of 'config ntp' have 'config ntp-server' and 'config ntp-client'. >>>> >>>> -Philip >>>> >>>> >>>> _______________________________________________ >>>> openwrt-devel mailing list >>>> openwrt-devel@lists.openwrt.org >>>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel >> _______________________________________________ >> openwrt-devel mailing list >> openwrt-devel@lists.openwrt.org >> https://lists.openwrt.org/mailman/listinfo/openwrt-devel > _______________________________________________ > openwrt-devel mailing list > openwrt-devel@lists.openwrt.org > https://lists.openwrt.org/mailman/listinfo/openwrt-devel SVN-Revision: 31374
12 years ago
[ $enabled = 0 ] && return
[ $use_dhcp = 1 ] && get_dhcp_ntp_servers "$dhcp_interface"
[ -z "$server" -a "$enable_server" = "0" ] && return
procd_open_instance
procd_set_param command "$PROG" -n -N
[ "$enable_server" = "1" ] && procd_append_param command -l
[ -x "$HOTPLUG_SCRIPT" ] && procd_append_param command -S "$HOTPLUG_SCRIPT"
for peer in $server; do
procd_append_param command -p $peer
done
procd_set_param respawn
procd_close_instance
}
start_service() {
validate_ntp_section ntp start_ntpd_instance
}
service_triggers() {
local script name use_dhcp
script=$(readlink -f "$initscript")
name=$(basename ${script:-$initscript})
procd_add_config_trigger "config.change" "system" /etc/init.d/$name reload
config_load system
config_get use_dhcp ntp use_dhcp 1
[ $use_dhcp = 1 ] && {
local dhcp_interface
config_get dhcp_interface ntp dhcp_interface
if [ -n "$dhcp_interface" ]; then
for n in $dhcp_interface; do
procd_add_interface_trigger "interface.*" $n /etc/init.d/$name reload
done
else
procd_add_raw_trigger "interface.*" 1000 /etc/init.d/$name reload
fi
}
procd_add_validation validate_ntp_section
}