Advertisement
Guest User

Untitled

a guest
Apr 28th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.99 KB | None | 0 0
  1. #!/bin/sh
  2.  
  3. # This script is meant to run continuously, instead of being constantly called by cron. It is best
  4. # called from a screen session or just call it and dump stdout to /dev/null.
  5.  
  6. # If the gateway of the mesh goes away, we turn off our typical user serving APs and turn on a
  7. # 'help me' AP. Mainly useful for mesh nodes that might have their LTE hotspot (gateway) wander off.
  8.  
  9. # [ config vars ]
  10. ping_ip=192.168.1.1
  11.  
  12. # [ global vars ]
  13. # These are the vars for how many pings we can miss before we reset the wwan0 connection
  14. pingtries=0
  15. maxtries=5
  16. failedstate=0
  17.  
  18. watchdog_name=gateway-watchdog
  19.  
  20. logger -t $watchdog_name "Starting wan-watchdog of" $modem_iface
  21. echo $watchdog_name
  22.  
  23. # Instead of waiting until we get pings we're just going to sleep for 10 before going on
  24. sleep 10
  25.  
  26. # We need to make sure our customer APs are 'on' or something for the startup.
  27. # If the mesh node gets shutdown in it's 'help me' state, it needs to be sure
  28. # to enable the right APs if it was left in that state.
  29. # If we just grab the status of the 'help me' AP, that would let us set our failed state flag.
  30. echo Failed state start
  31. failcheck=$(uci -q get wireless.@wifi-iface[4].disabled)
  32. echo Output from uci:
  33. echo $failcheck
  34. #if [ failcheck -eq 0 ]
  35. if [[ "$failcheck" == *"0"* ]]
  36. then
  37.     echo "Caught failed if check"
  38.     failedstate=1
  39. fi
  40. echo Setting failstate to:
  41. echo $failedstate
  42. echo end failstate shit
  43.  
  44. logger -t $watchdog_name "Starting connection monitoring loop..."
  45.  
  46. while [[ 1 ]]
  47. do
  48.     pingtries=0
  49.     while [[ $pingtries -lt $maxtries ]]
  50.     do
  51.         echo "Pinging..."
  52.         if /bin/ping -c 1 $ping_ip >/dev/null
  53.         then
  54.             echo "Ping success, sleeping"
  55.             if [ $failedstate -eq 1 ]
  56.             then
  57.                 logger -t $watchdog_name "Enabling user APs, disable help me APs"
  58.         echo  "Enabling user APs, disable help me APs"
  59.         failedstate=0
  60.                 uci -q set wireless.@wifi-iface[4].disabled=1
  61.                 uci -q set wireless.radio0.disabled=0
  62.                 uci -q set wireless.radio1.disabled=0
  63.                 uci -q set wireless.@wifi-iface[0].disabled=0
  64.                 uci -q set wireless.@wifi-iface[1].disabled=0
  65.                 uci commit wireless
  66.                 wifi down && wifi up
  67.                 sleep 15
  68.             fi
  69.             break
  70.         fi
  71.         pingtries=$((pingtries+1))
  72.         echo "Ping failure"
  73.     logger -t $watchdog_name "Ping failure"
  74.     sleep 2
  75.     done
  76.  
  77.     if [ $pingtries -eq $maxtries ]
  78.     then
  79.     if [ $failedstate -eq 0 ]
  80.     then
  81.             logger -t $watchdog_name "Disabling user APs, enabling help me APs"
  82.         echo "Disabling user APs, enabling help me APs"
  83.         failedstate=1
  84.             uci -q set wireless.@wifi-iface[4].disabled=0
  85.             uci -q set wireless.@wifi-iface[0].disabled=1
  86.             uci -q set wireless.@wifi-iface[1].disabled=1
  87.             uci commit wireless
  88.             wifi down && wifi up
  89.             sleep 15
  90.     fi
  91.     else
  92.        sleep 5
  93.     fi
  94.  
  95. done
  96.  
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement