wwan-iface-watchdog 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh /etc/rc.common
  2. # write wwan-iface-watchdog.sh script
  3. function write_script() {
  4. [ -d /root/scripts ] || mkdir -p /root/scripts
  5. if [ ! -e /root/scripts/wwan-iface-watchdog.sh ]; then
  6. echo '#!/bin/sh' > /root/scripts/wwan-iface-watchdog.sh
  7. echo '' >> /root/scripts/wwan-iface-watchdog.sh
  8. echo 'while true; do' >> /root/scripts/wwan-iface-watchdog.sh
  9. echo ' tries=0' >> /root/scripts/wwan-iface-watchdog.sh
  10. echo ' while [[ $tries -lt 5 ]]; do' >> /root/scripts/wwan-iface-watchdog.sh
  11. echo ' /bin/ping -q -c 1 8.8.8.8 && sleep 5 && continue 2' >> /root/scripts/wwan-iface-watchdog.sh
  12. echo ' tries=$((tries+1))' >> /root/scripts/wwan-iface-watchdog.sh
  13. echo ' done' >> /root/scripts/wwan-iface-watchdog.sh
  14. echo ' logger "Interface disconnected, restarting wwan..."' >> /root/scripts/wwan-iface-watchdog.sh
  15. echo ' /sbin/ifup wwan' >> /root/scripts/wwan-iface-watchdog.sh
  16. echo ' sleep 60' >> /root/scripts/wwan-iface-watchdog.sh
  17. echo 'done' >> /root/scripts/wwan-iface-watchdog.sh
  18. chmod +x /root/scripts/wwan-iface-watchdog.sh
  19. fi
  20. }
  21. START=99
  22. PIDDIR=/var/pids
  23. PIDFILE=/var/pids/wwan-iface-watchdog
  24. # init functions
  25. start() {
  26. logger "Starting wwan iface watchdog"
  27. write_script
  28. [ -d $PIDDIR ] || mkdir -p $PIDDIR
  29. [ -f $PIDFILE ] && exit 1
  30. /root/scripts/wwan-iface-watchdog.sh > /dev/null 2>&1 &
  31. echo $! > $PIDFILE
  32. }
  33. stop() {
  34. logger "Stopping wwan iface watchdog"
  35. kill `cat $PIDFILE`
  36. rm $PIDFILE
  37. }
  38. restart() {
  39. logger "Restarting wwan iface watchdog"
  40. kill `cat $PIDFILE`
  41. rm $PIDFILE
  42. write_script
  43. /root/scripts/wwan-iface-watchdog.sh > /dev/null 2>&1 &
  44. echo $! > $PIDFILE
  45. }