source: hybrid/branches/releng-9.0/nanobsd/files/tools/check-inet-alive@ 10827

Last change on this file since 10827 was 10720, checked in by rick, 13 years ago

Plaats de handige tools in de ... tools directory :-)

  • Property svn:executable set to *
File size: 2.3 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 <info@rickvanderzwet.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
23load_rc_config "lvrouted"
24load_rc_config "tinyproxy"
25: ${lvouted_enable="NO"}
26: ${tinyproxy_enable="NO"}
27: ${service_ileiden="NO"}
28: ${service_proxy="NO"}
29
30control_lvrouted="yes"
31control_tinyproxy="yes"
32(( checkyesno service_ileiden || checkyesno service_proxy ) && checkyesno lvouted_enable ) || control_lvrouted="no"
33(( checkyesno service_ileiden || checkyesno service_proxy ) && checkyesno tinyproxy_enable ) || control_tinyproxy="no"
34
35
36service lvrouted onestatus > /dev/null && LVROUTED_STATUS="running" || LVROUTED_STATUS="stopped"
37service tinyproxy onestatus > /dev/null && TINYPROXY_STATUS="running" || TINYPROXY_STATUS="stopped"
38
39check_http() {
40 fetch -o /dev/null -q $* 2>/dev/null
41}
42
43# Get connection stats for internet
44INET_STATUS=up && check_http http://proxy-test.wirelessleiden.nl || check_http http://ams-ix.net || INET_STATUS=down
45# Connections statistics for proxy
46export HTTP_PROXY=${HTTP_PROXY-:http://proxy.wleiden.net:3128}
47PROXY_STATUS=up && check_http http://tinyproxy.stats || check_http http://ams-ix.net || PROXY_STATUS=down
48
49# Log Network Status
50cat <<EOF > /tmp/network.status
51internet=$INET_STATUS
52proxy=$PROXY_STATUS
53EOF
54
55# Control connections
56if checkyesno control_lvrouted; then
57 if [ $LVROUTED_STATUS = "stopped" ] && [ $INET_STATUS = "up" ]; then
58 service lvrouted start | logit
59 elif [ $LVROUTED_STATUS = "running" ] && [ $INET_STATUS = "down" ]; then
60 service lvrouted stop | logit
61 fi
62fi
63
64if checkyesno control_tinyproxy; then
65 if [ $TINYPROXY_STATUS_STATUS = "stopped" ] && [ $INET_STATUS = "up" ]; then
66 service tinyproxy start | logit
67 elif [ $TINYPROXY_STATUS = "running" ] && [ $INET_STATUS = "down" ]; then
68 service tinyproxy stop | logit
69 fi
70fi
Note: See TracBrowser for help on using the repository browser.