#!/bin/bash # # adsl This shell script takes care of starting and stopping # adsl. # It is useable for the mxStream variant. # Phons Bloemen (phons.bloemen@planet.nl) # # chkconfig: - 38 18 # description: adsl # probe: true # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x /usr/sbin/pptp ] || exit 0 [ -x /etc/adsl/adsllogin.pl ] || exit 0 RETVAL=0 # See how we were called. case "$1" in start) # Start daemons. echo -n "Starting adsl: " /usr/sbin/pptp 192.168.0.100 file /etc/ppp/options.adsl RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pptp cp -fp /etc/resolv.conf.correct /etc/resolv.conf echo `date ` "adsl startup command given" >>/var/log/adsl.log sync echo pptp # adsllogin.pl is run from /etc/ppp/addroute-adsl # /usr/bin/perl /etc/adsl/adsllogin.pl ;; stop) # Stop daemons. echo -n "Shutting down adsl: " if [ -f /var/run/ppp-adsl.pid ]; then echo -n pppd kill -HUP ` head -1 /var/run/ppp-adsl.pid ` killall pptp killall pppd killall pptp RETVAL=$? [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/pppd-adsl echo -n adsl sleep 5 fi killproc pptp echo `date ` "adsl stop command given" >>/var/log/adsl.log [ -f /var/run/pptp/192.168.0.100 ] echo `date ` "pipe not closed" >>/var/log/adsl.log rm -rf /var/run/pptp/192.168.0.100 echo ;; restart) $0 stop $0 start ;; status) RETVAL=0; if test -f /var/run/adsloff then echo `date ` "previous adsl status is hanging" >> /var/log/adsl.log rm -rf /var/run/adsloff RETVAL=1; else pid=`pidofproc /usr/sbin/pptp` [ "$pid" = "" ] && echo 'no pptp' >> /var/run/adsloff pid=`pidofproc /usr/sbin/pppd` [ "$pid" = "" ] && echo 'no pppd' >> /var/run/adsloff # Test is no good: it MAY run on ppp1.... # ifconfig ppp0 # [ $? -eq 0 ] && echo 'no ppp0' >> /var/run/adsloff # Test with ping no good: it sometimes hangs (-w does not work) # ping -n -c 3 -w 10 195.121.6.194 >> /dev/null # Use the mtr tool (if it pings, it is ok) ISOK=`/usr/local/sbin/mtr -r -n -c 3 195.121.6.194 | wc -l ` [ $ISOK -le "4" -o $ISOK -ge "7" ] && echo 'no ping (' $ISOK ')' >> /var/run/adsloff if test -f /var/run/adsloff then echo `date ` ` cat /var/run/adsloff ` >> /var/log/adsl.log RETVAL=1; fi fi ;; check) sh $0 status if test -f /var/run/adsloff then logger -p local1.info $0 "Adsl waker forced restart" echo `date ` "adsl waker forced restart" >>/var/log/adsl.log rm -rf /var/run/adsloff sh $0 stop sleep 3 sh $0 start fi ;; probe) exit 0 ;; *) echo "Usage: named {start|stop|status|check|restart}" exit 1 esac exit $RETVAL L