Initial commit
This commit is contained in:
51
wwan-iface-watchdog
Executable file
51
wwan-iface-watchdog
Executable file
@@ -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
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user