source: hybrid/branches/releng-9/nanobsd/files/tools/check-inet-alive@ 12900

Last change on this file since 12900 was 10829, checked in by rick, 13 years ago

Control the right daemons with the right function.

  • Property svn:executable set to *
File size: 2.2 KB
Line 
1#!/bin/sh
2#
3# Internet Connection Wrapper From Cron
4#
5# a) Disable lvrouted if the internet is down.
6# b) Re-enable lvrouted if the internet is back up.
7#
8# XXX: Do we need build an fail-save for flapping states?
9# XXX: Do we need to manage state, like DHCP here?
10# XXX: Check if page output is actually the output expected and not some weird captive portal somewhere.
11# XXX: For effiently reasons this should be combined with the nagios check_inet check
12#
13# Rick van der Zwet <rick@wirelessleiden.nl>
14#
15
16TAG=`basename $0`
17logit() {
18 logger -t "$TAG" $*
19}
20
21# Check if we need to check inet at all
22. /etc/rc.subr
23
24load_rc_config "lvrouted"
25load_rc_config "tinyproxy"
26
27: ${lvouted_enable="NO"}
28: ${tinyproxy_enable="NO"}
29: ${service_ileiden="NO"}
30: ${service_proxy="NO"}
31
32control_lvrouted=false
33control_tinyproxy=false
34checkyesno service_proxy_ileiden && checkyesno lvouted_enable control_lvrouted=true
35checkyesno service_proxy_normal && checkyesno tinyproxy_enable || control_tinyproxy=false
36
37
38# Get current state of the daemons
39lvouted_status="stopped"
40tinyproxy_status="stopped"
41service lvrouted onestatus > /dev/null && lvouted_status="running"
42service tinyproxy onestatus > /dev/null && tinyproxy_status="running"
43
44check_http() {
45 fetch -o /dev/null -q $* 2>/dev/null
46}
47
48# Get connection stats for internet direct and via proxy
49inet_status=up
50proxy_status=up
51check_http http://proxy-test.wirelessleiden.nl || check_http http://ams-ix.net || inet_status=down
52export HTTP_PROXY=${HTTP_PROXY-:http://proxy.wleiden.net:3128}
53check_http http://tinyproxy.stats || check_http http://ams-ix.net || proxy_status=down
54
55# Log Network Status
56cat <<EOF > /tmp/network.status
57internet=$inet_status
58proxy=$proxy_status
59EOF
60
61# Control connections
62if $control_lvrouted; then
63 if [ $lvrouted_status = "stopped" ] && [ $inet_status = "up" ]; then
64 service lvrouted start | logit
65 elif [ $lvrouted_status = "running" ] && [ $inet_status = "down" ]; then
66 service lvrouted stop | logit
67 fi
68fi
69
70if $control_tinyproxy; then
71 if [ $tinyproxy_status = "stopped" ] && [ $inet_status = "up" ]; then
72 service tinyproxy start | logit
73 elif [ $tinyproxy_status = "running" ] && [ $inet_status = "down" ]; then
74 service tinyproxy stop | logit
75 fi
76fi
Note: See TracBrowser for help on using the repository browser.