2 # Copyright (C) 2006 OpenWrt.org
10 unset INTERFACE_GLOBAL
12 NTPC=`which ntpclient`
18 [ -n "$SERVER" ] && return
19 config_get hostname $1 hostname
20 config_get port $1 port
21 config_get interface $1 interface
23 [ -z "$interface" ] && interface=$INTERFACE_GLOBAL
25 [ -n "$interface" ] && {
26 # $INTERFACE is passed from hotplug event
27 [ "$interface" = "$INTERFACE" ] || return
30 [ -z "$hostname" ] && return
31 $NTPC -c 1 -p ${port:-123} -i 2 -h $hostname > /dev/null && { SERVER=$hostname; PORT=${port:-123}; }
35 config_get freq $1 freq
36 [ -n "$freq" ] && adjtimex -f $freq >/dev/null
40 config_foreach set_drift ntpdrift
41 config_foreach check_server ntpserver
42 [ -z "$SERVER" ] && exit 0
43 logger starting ntpclient
44 $NTPC ${COUNT:+-c $COUNT} ${INTERVAL:+-i $INTERVAL} -s -l -D -p $PORT -h $SERVER 2> /dev/null
48 logger stopping ntpclient
57 config_get interval $1 interval
58 config_get count $1 count
59 config_get interface $1 interface
61 [ -n "$count" ] && COUNT=$count
62 [ -n "$interval" ] && INTERVAL=$interval
63 [ -n "$interface" ] && INTERFACE_GLOBAL=$interface
67 config_foreach load_settings ntpclient
69 NTP_RUNNING=`ps | grep $NTPC | grep -v grep`
71 case "${ACTION:-ifup}" in
73 [ -z "$NTP_RUNNING" ] && start_ntpclient
76 [ -n "$NTP_RUNNING" ] && stop_ntpclient