2009-11-06 08:34:19 +05:30
|
|
|
#!/bin/sh
|
|
|
|
|
2015-10-15 05:40:11 +05:30
|
|
|
# How often to test, seconds
|
|
|
|
ping_time=67
|
|
|
|
# "One ping, must have reply in 1 sec"
|
|
|
|
ping_opts="-c1 -W1 -w1"
|
|
|
|
# If ping failed, how soon to retry
|
|
|
|
retry_time=5
|
|
|
|
# Reinit after this many consecutive ping error
|
|
|
|
max_fail=5
|
|
|
|
# Interface whose DHCP data to use
|
2009-11-06 08:34:19 +05:30
|
|
|
if=${PWD##*/dhcp_}
|
|
|
|
if=${if%%_pinger}
|
|
|
|
|
2015-10-15 05:40:11 +05:30
|
|
|
msg() {
|
|
|
|
echo "`date '+%Y-%m-%d %H:%M:%S'` $*" >>"$0.log"
|
|
|
|
}
|
|
|
|
|
2009-11-06 08:34:19 +05:30
|
|
|
if test -f "$0.log"; then
|
|
|
|
tail -999 "$0.log" >"$0.log.new"
|
|
|
|
mv "$0.log.new" "$0.log"
|
|
|
|
fi
|
|
|
|
|
2015-10-15 05:40:11 +05:30
|
|
|
test -f "/var/service/dhcp_$if/dhcp_$if.out" || exec env - sleep "$ping_time"
|
2009-11-06 08:34:19 +05:30
|
|
|
|
2015-10-15 05:40:11 +05:30
|
|
|
. "/var/service/dhcp_$if/dhcp_$if.out"
|
|
|
|
test x"$router" != x"" || exec env - sleep "$ping_time"
|
2009-11-06 08:34:19 +05:30
|
|
|
|
2015-10-15 05:40:11 +05:30
|
|
|
#msg "Pinging $router"
|
|
|
|
failcnt=0
|
|
|
|
while true; do
|
|
|
|
ping $ping_opts "$router" && exec env - sleep "$ping_time"
|
|
|
|
: $((failcnt++))
|
|
|
|
msg "Failed to ping $router, fail count:$failcnt"
|
|
|
|
test $failcnt -ge $max_fail && break
|
|
|
|
env - sleep "$retry_time"
|
|
|
|
done
|
2009-11-06 08:34:19 +05:30
|
|
|
|
2015-10-15 05:40:11 +05:30
|
|
|
test -d "/var/service/dhcp_$if" && {
|
|
|
|
msg "Restarting /var/service/dhcp_$if"
|
|
|
|
sv t "/var/service/dhcp_$if"
|
|
|
|
}
|
|
|
|
test -d "/var/service/supplicant_$if" && {
|
|
|
|
msg "Restarting /var/service/supplicant_$if"
|
|
|
|
sv t "/var/service/supplicant_$if"
|
|
|
|
}
|
|
|
|
exec env - sleep "$ping_time"
|