source: hybrid/branches/releng-10/nanobsd/files/tools/check-inet-alive@ 12926

Last change on this file since 12926 was 12894, checked in by huub, 10 years ago

internet check niet naar ams-ix.net ivm certificaat

  • Property svn:executable set to *
File size: 2.2 KB
RevLine 
[10136]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.
[10481]11# XXX: For effiently reasons this should be combined with the nagios check_inet check
[10136]12#
[10829]13# Rick van der Zwet <rick@wirelessleiden.nl>
[10136]14#
15
16TAG=`basename $0`
[10483]17logit() {
18 logger -t "$TAG" $*
19}
20
21# Check if we need to check inet at all
22. /etc/rc.subr
[10829]23
[10483]24load_rc_config "lvrouted"
25load_rc_config "tinyproxy"
[10829]26
[10483]27: ${lvouted_enable="NO"}
28: ${tinyproxy_enable="NO"}
29: ${service_ileiden="NO"}
30: ${service_proxy="NO"}
31
[10829]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
[10483]36
37
[10829]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"
[10136]43
[10481]44check_http() {
45 fetch -o /dev/null -q $* 2>/dev/null
46}
47
[10829]48# Get connection stats for internet direct and via proxy
49inet_status=up
50proxy_status=up
[12894]51check_http http://www.nu.nl || check_http http://ams-ix.net || inet_status=down
[10483]52export HTTP_PROXY=${HTTP_PROXY-:http://proxy.wleiden.net:3128}
[12894]53check_http http://tinyproxy.stats || check_http http://www.nu.net || proxy_status=down
[10136]54
[10483]55# Log Network Status
56cat <<EOF > /tmp/network.status
[10829]57internet=$inet_status
58proxy=$proxy_status
[10483]59EOF
[10136]60
[10483]61# Control connections
[10829]62if $control_lvrouted; then
63 if [ $lvrouted_status = "stopped" ] && [ $inet_status = "up" ]; then
[10483]64 service lvrouted start | logit
[10829]65 elif [ $lvrouted_status = "running" ] && [ $inet_status = "down" ]; then
[10483]66 service lvrouted stop | logit
67 fi
[10136]68fi
[10481]69
[10829]70if $control_tinyproxy; then
71 if [ $tinyproxy_status = "stopped" ] && [ $inet_status = "up" ]; then
[10483]72 service tinyproxy start | logit
[10829]73 elif [ $tinyproxy_status = "running" ] && [ $inet_status = "down" ]; then
[10483]74 service tinyproxy stop | logit
75 fi
[10481]76fi
Note: See TracBrowser for help on using the repository browser.