diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-15 02:10:11 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2015-10-15 02:10:11 +0200 |
commit | 5251135bc184bdcb8cbcb964e8c44c6c301bffdc (patch) | |
tree | 01d8d066d38668731bc95bdc54e24180a3d1d327 | |
parent | 4ad702c0a70628ce7574609087e50b0ce40455d6 (diff) | |
download | busybox-w32-5251135bc184bdcb8cbcb964e8c44c6c301bffdc.tar.gz busybox-w32-5251135bc184bdcb8cbcb964e8c44c6c301bffdc.tar.bz2 busybox-w32-5251135bc184bdcb8cbcb964e8c44c6c301bffdc.zip |
better pinger service example
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rwxr-xr-x | examples/var_service/dhcp_if_pinger/run | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/examples/var_service/dhcp_if_pinger/run b/examples/var_service/dhcp_if_pinger/run index 20b2fc516..1868510d1 100755 --- a/examples/var_service/dhcp_if_pinger/run +++ b/examples/var_service/dhcp_if_pinger/run | |||
@@ -1,23 +1,47 @@ | |||
1 | #!/bin/sh | 1 | #!/bin/sh |
2 | 2 | ||
3 | delay=67 | 3 | # How often to test, seconds |
4 | 4 | ping_time=67 | |
5 | # "One ping, must have reply in 1 sec" | ||
6 | ping_opts="-c1 -W1 -w1" | ||
7 | # If ping failed, how soon to retry | ||
8 | retry_time=5 | ||
9 | # Reinit after this many consecutive ping error | ||
10 | max_fail=5 | ||
11 | # Interface whose DHCP data to use | ||
5 | if=${PWD##*/dhcp_} | 12 | if=${PWD##*/dhcp_} |
6 | if=${if%%_pinger} | 13 | if=${if%%_pinger} |
7 | 14 | ||
15 | msg() { | ||
16 | echo "`date '+%Y-%m-%d %H:%M:%S'` $*" >>"$0.log" | ||
17 | } | ||
18 | |||
8 | if test -f "$0.log"; then | 19 | if test -f "$0.log"; then |
9 | tail -999 "$0.log" >"$0.log.new" | 20 | tail -999 "$0.log" >"$0.log.new" |
10 | mv "$0.log.new" "$0.log" | 21 | mv "$0.log.new" "$0.log" |
11 | fi | 22 | fi |
12 | 23 | ||
13 | test -f "/var/service/dhcp_$if/dhcp_$if.out" || exec env - sleep "$delay" | 24 | test -f "/var/service/dhcp_$if/dhcp_$if.out" || exec env - sleep "$ping_time" |
14 | . "/var/service/dhcp_$if/dhcp_$if.out" | ||
15 | test x"$router" != x"" || exec env - sleep "$delay" | ||
16 | 25 | ||
17 | #echo "`date '+%Y-%m-%d %H:%M:%S'` Testing ping -c3 $router" >>"$0.log" | 26 | . "/var/service/dhcp_$if/dhcp_$if.out" |
18 | ping -c3 "$router" && exec env - sleep "$delay" | 27 | test x"$router" != x"" || exec env - sleep "$ping_time" |
19 | 28 | ||
20 | echo "`date '+%Y-%m-%d %H:%M:%S'` Restarting /var/service/dhcp_$if" >>"$0.log" | 29 | #msg "Pinging $router" |
21 | sv t "/var/service/dhcp_$if" | 30 | failcnt=0 |
31 | while true; do | ||
32 | ping $ping_opts "$router" && exec env - sleep "$ping_time" | ||
33 | : $((failcnt++)) | ||
34 | msg "Failed to ping $router, fail count:$failcnt" | ||
35 | test $failcnt -ge $max_fail && break | ||
36 | env - sleep "$retry_time" | ||
37 | done | ||
22 | 38 | ||
23 | exec env - sleep "$delay" | 39 | test -d "/var/service/dhcp_$if" && { |
40 | msg "Restarting /var/service/dhcp_$if" | ||
41 | sv t "/var/service/dhcp_$if" | ||
42 | } | ||
43 | test -d "/var/service/supplicant_$if" && { | ||
44 | msg "Restarting /var/service/supplicant_$if" | ||
45 | sv t "/var/service/supplicant_$if" | ||
46 | } | ||
47 | exec env - sleep "$ping_time" | ||