Ignore:
Timestamp:
Apr 13, 2012, 7:18:42 PM (13 years ago)
Author:
rick
Message:

Control both tinyproxy and lvrouted

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/releng-9.0/nanobsd/files/usr/local/sbin/check-inet-alive

    r10481 r10483  
    1515
    1616TAG=`basename $0`
    17 INET_STATUS=down
     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
    1836service lvrouted onestatus > /dev/null && LVROUTED_STATUS="running" || LVROUTED_STATUS="stopped"
     37service tinyproxy onestatus > /dev/null && TINYPROXY_STATUS="running" || TINYPROXY_STATUS="stopped"
    1938
    2039check_http() {
     
    2241}
    2342
    24 # Main I-net check
    25 check_http http://proxy-test.wirelessleiden.nl && INET_STATUS=up
     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
    2648
    27 if [ $INET_STATUS = "down" ]; then
    28   # Failback internet check
    29   check_http http://ams-ix.net && INET_STATUS=up
     49# Log Network Status
     50cat <<EOF > /tmp/network.status
     51internet=$INET_STATUS
     52echo proxy=$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
    3062fi
    3163
    32 if [ $LVROUTED_STATUS = "stopped" ] && [ $INET_STATUS = "up" ]; then
    33   service lvrouted start | logger -t "$TAG"
    34 elif [ $LVROUTED_STATUS = "running" ] && [ $INET_STATUS = "down" ]; then
    35   service lvrouted stop | logger -t "$TAG"
     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
    3670fi
    37 
    38 # Retrieve proxy status
    39 export HTTP_PROXY=${HTTP_PROXY-:http://proxy.wleiden.net:3128}
    40 PROXY_STATUS=down
    41 check_http http://proxy-test.wirelessleiden.nl && PROXY_STATUS=down
    42 
    43 if [ $INET_STATUS = "down" ]; then
    44   # Failback internet check
    45   check_http http://ams-ix.net && PROXY_STATUS=up
    46 fi
    47 
    48 echo -e "internet=$INET_STATUS\nproxy=$PROXY_STATUS" > /tmp/network.status
Note: See TracChangeset for help on using the changeset viewer.