From ce9910b34b84233d92a7f97265bdf3b7d2e9fb6a Mon Sep 17 00:00:00 2001 From: cryobry <38270216+cryobry@users.noreply.github.com> Date: Thu, 24 May 2018 23:56:02 -0400 Subject: [PATCH] Initial commit --- wwan-iface-watchdog | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 wwan-iface-watchdog diff --git a/wwan-iface-watchdog b/wwan-iface-watchdog new file mode 100755 index 0000000..6b34ab9 --- /dev/null +++ b/wwan-iface-watchdog @@ -0,0 +1,51 @@ +#!/bin/sh /etc/rc.common + +# write wwan-iface-watchdog.sh script +function write_script() { + [ -d /root/scripts ] || mkdir -p /root/scripts + if [ ! -e /root/scripts/wwan-iface-watchdog.sh ]; then + echo '#!/bin/sh' > /root/scripts/wwan-iface-watchdog.sh + echo '' >> /root/scripts/wwan-iface-watchdog.sh + echo 'while true; do' >> /root/scripts/wwan-iface-watchdog.sh + echo ' tries=0' >> /root/scripts/wwan-iface-watchdog.sh + echo ' while [[ $tries -lt 5 ]]; do' >> /root/scripts/wwan-iface-watchdog.sh + echo ' /bin/ping -q -c 1 8.8.8.8 && sleep 5 && continue 2' >> /root/scripts/wwan-iface-watchdog.sh + echo ' tries=$((tries+1))' >> /root/scripts/wwan-iface-watchdog.sh + echo ' done' >> /root/scripts/wwan-iface-watchdog.sh + echo ' logger "Interface disconnected, restarting wwan..."' >> /root/scripts/wwan-iface-watchdog.sh + echo ' /sbin/ifup wwan' >> /root/scripts/wwan-iface-watchdog.sh + echo ' sleep 60' >> /root/scripts/wwan-iface-watchdog.sh + echo 'done' >> /root/scripts/wwan-iface-watchdog.sh + chmod +x /root/scripts/wwan-iface-watchdog.sh + fi +} + +START=99 +PIDDIR=/var/pids +PIDFILE=/var/pids/wwan-iface-watchdog + +# init functions +start() { + logger "Starting wwan iface watchdog" + write_script + [ -d $PIDDIR ] || mkdir -p $PIDDIR + [ -f $PIDFILE ] && exit 1 + /root/scripts/wwan-iface-watchdog.sh > /dev/null 2>&1 & + echo $! > $PIDFILE +} + +stop() { + logger "Stopping wwan iface watchdog" + kill `cat $PIDFILE` + rm $PIDFILE +} + +restart() { + logger "Restarting wwan iface watchdog" + kill `cat $PIDFILE` + rm $PIDFILE + write_script + /root/scripts/wwan-iface-watchdog.sh > /dev/null 2>&1 & + echo $! > $PIDFILE +} +