4 COMMAND
=/etc
/init.d
/$NAME
6 LOGGER
="/usr/bin/logger -t $NAME-hotplug"
7 LOG_ERR
="$LOGGER -p user.err --"
8 LOG_NOTICE
="$LOGGER -p user.notice --"
10 [ "$ACTION" = ifup
] ||
exit 0
15 config_get interface hotplug interface
17 [ "$INTERFACE" = "$interface" ] ||
exit 0
19 pidof
$NAME &> /dev
/null
21 $LOG_NOTICE stopping
$NAME
22 $COMMAND stop
&> /dev
/null
25 config_get timeout hotplug timeout
60
27 [ "$timeout" -gt 0 ] 2> /dev
/null ||
unset timeout
28 timeout
="${timeout:-60}"
30 config_get mount_point hotplug mount_point
32 # Mount condition, idea lifted from OpenWrt Wiki
33 [ -n "$mount_point" ] && {
35 if ! [ -d "$mount_point" ]; then
36 $LOG_ERR "$mount_point" not a valid mount point
44 while [ -n "$notReady" -a $tmp_timeout -gt 0 ]; do
45 if [ "$notReady" != start
]; then
46 $LOG_NOTICE "$mnt" not yet mounted
, timeout
in $tmp_timeout s
48 tmp_timeout
=$
(($tmp_timeout-5))
53 result
=$
(cat /proc
/mounts |
awk '{print $2}' |
grep "^$mnt\$")
54 if [ -z "$result" ]; then
55 notReady
="$mnt not ready yet"
59 if [ -n "$notReady" ]; then
60 $LOG_ERR "$mnt" still not mounted
61 $LOG_ERR not starting
$NAME
64 $LOG_NOTICE "$mnt" mounted
69 config_get_bool ntpd hotplug ntpd
0
74 type ntpq
&> /dev
/null
76 $LOG_ERR ntpq utility not found
80 pidof ntpd
&> /dev
/null ||
{
81 $LOG_ERR ntpd not running
88 while [ -n "$notReady" -a $tmp_timeout -gt 0 ]; do
89 if [ "$notReady" != start
]; then
90 $LOG_NOTICE system
time not
in sync yet
, timeout
in $tmp_timeout s
92 tmp_timeout
=$
(($tmp_timeout-5))
97 result
=$
(ntpq
-c 'timeout 300' -c 'rv 0 stratum' 2> /dev
/null | \
98 awk -F '=' '{print $2}' |
grep -o -E '^[0-9]+')
99 if [ -z $result ]; then
100 $LOG_ERR failed to extract stratum from ntpd
101 notReady
="unable to extract stratum"
103 $LOG_NOTICE ntpd stratum
$result
104 if [ $result -lt 16 ] 2> /dev
/null
; then
105 result
=$
(ntpq
-c 'timeout 300' -c 'rv 0 offset' 2> /dev
/null \
106 |
awk -F '=' '{print $2}' |
grep -o -E '^-?[0-9]+')
107 if [ -z $result ]; then
108 $LOG_ERR failed to extract offset from ntpd
109 notReady
="unable to extract offset"
111 # "-0" looks stupid, so remove "-"
112 result
=$
(echo $result |
grep -o '[0-9]*')
113 $LOG_NOTICE ntpd to system
time offset \
+\
/\
- $result ms
114 # If offset < 100 ms consider system time in sync
115 [ $result -lt 100 ] || notReady
="system time not in sync yet"
118 notReady
="ntpd not in sync yet"
123 if [ -n "$notReady" ]; then
124 $LOG_ERR system
time still not
in sync
125 $LOG_ERR not starting
$NAME
128 $LOG_NOTICE system
time in sync
133 $COMMAND start
&> /dev
/null
135 pidof
$NAME &>/dev
/null
136 if [ $?
-eq 0 ]; then
137 $LOG_NOTICE started
$NAME due to
\"ifup
"$INTERFACE"\" event
139 $LOG_ERR start of
$NAME due to
\"ifup
"$INTERFACE"\" event failed