Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # This script is meant to run continuously, instead of being constantly called by cron. It is best
- # called from a screen session or just call it and dump stdout to /dev/null.
- # If the gateway of the mesh goes away, we turn off our typical user serving APs and turn on a
- # 'help me' AP. Mainly useful for mesh nodes that might have their LTE hotspot (gateway) wander off.
- # [ config vars ]
- ping_ip=192.168.1.1
- # [ global vars ]
- # These are the vars for how many pings we can miss before we reset the wwan0 connection
- pingtries=0
- maxtries=5
- failedstate=0
- watchdog_name=gateway-watchdog
- logger -t $watchdog_name "Starting wan-watchdog of" $modem_iface
- echo $watchdog_name
- # Instead of waiting until we get pings we're just going to sleep for 10 before going on
- sleep 10
- # We need to make sure our customer APs are 'on' or something for the startup.
- # If the mesh node gets shutdown in it's 'help me' state, it needs to be sure
- # to enable the right APs if it was left in that state.
- # If we just grab the status of the 'help me' AP, that would let us set our failed state flag.
- echo Failed state start
- failcheck=$(uci -q get wireless.@wifi-iface[4].disabled)
- echo Output from uci:
- echo $failcheck
- #if [ failcheck -eq 0 ]
- if [[ "$failcheck" == *"0"* ]]
- then
- echo "Caught failed if check"
- failedstate=1
- fi
- echo Setting failstate to:
- echo $failedstate
- echo end failstate shit
- logger -t $watchdog_name "Starting connection monitoring loop..."
- while [[ 1 ]]
- do
- pingtries=0
- while [[ $pingtries -lt $maxtries ]]
- do
- echo "Pinging..."
- if /bin/ping -c 1 $ping_ip >/dev/null
- then
- echo "Ping success, sleeping"
- if [ $failedstate -eq 1 ]
- then
- logger -t $watchdog_name "Enabling user APs, disable help me APs"
- echo "Enabling user APs, disable help me APs"
- failedstate=0
- uci -q set wireless.@wifi-iface[4].disabled=1
- uci -q set wireless.radio0.disabled=0
- uci -q set wireless.radio1.disabled=0
- uci -q set wireless.@wifi-iface[0].disabled=0
- uci -q set wireless.@wifi-iface[1].disabled=0
- uci commit wireless
- wifi down && wifi up
- sleep 15
- fi
- break
- fi
- pingtries=$((pingtries+1))
- echo "Ping failure"
- logger -t $watchdog_name "Ping failure"
- sleep 2
- done
- if [ $pingtries -eq $maxtries ]
- then
- if [ $failedstate -eq 0 ]
- then
- logger -t $watchdog_name "Disabling user APs, enabling help me APs"
- echo "Disabling user APs, enabling help me APs"
- failedstate=1
- uci -q set wireless.@wifi-iface[4].disabled=0
- uci -q set wireless.@wifi-iface[0].disabled=1
- uci -q set wireless.@wifi-iface[1].disabled=1
- uci commit wireless
- wifi down && wifi up
- sleep 15
- fi
- else
- sleep 5
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement