#!/bin/bash # # $Id: rc.connectioncheck,v 1.4.2.22 2005/07/07 20:11:58 franck78 Exp $ # eval $(/usr/local/bin/readhash CONFIG_ROOT/ppp/settings) # MAXRETRIES is now a count before rc.red clear and if reconnection fail, eventually switching to a backup profil MAXCONFIGURE=160 if [ ! $HOLDOFF ]; then HOLDOFF=30 fi # Debugging. Comment it out to stop logging DEBUG="yes" msg() { if [ "z$DEBUG" != "z" ] ; then /usr/bin/logger -t red "Connectioncheck: $*" fi /bin/echo "$*" } if [ -s "CONFIG_ROOT/red/keepconnected" ]; then ATTEMPTS=$(/bin/cat CONFIG_ROOT/red/keepconnected) else echo "0" > CONFIG_ROOT/red/keepconnected fi case "$1" in start) # waiting pppd start or sync timout set at 90 s when available in driver #rc.eciadsl/eci-load2 timout after 60s and 5 eci-load2 maximum attempts are done in rc.eciadsl. #So just wait 5 s after 'rc.red start' end where pppd should have been started TIMETOSTART=0 while ( ! /bin/ps ax | /bin/grep -q [p]ppd ); do if [ ! -e "CONFIG_ROOT/red/keepconnected" ]; then # user pressed disconnect in gui exit 0 fi RCREDSTART=`/bin/ps ax | /bin/grep '[r]c.red start'` if [ "$TIMETOSTART" -eq 1 ]; then msg "fail before pppd start : no sync, trying again" /etc/rc.d/rc.red stop /etc/rc.d/rc.red clear /etc/rc.d/rc.red start exit fi # give 5 s more at pppd to be visible with ps ax after 'rc.red start' end if [ "$RCREDSTART" = '' ]; then TIMETOSTART=1 fi /bin/sleep 5 done #watching if an IP is received in $MAXCONFIGURE time to avoid some pppoa waiting forever even after LCP timeout COUNT=0 while [ "$COUNT" -le "$MAXCONFIGURE" ]; do if [ ! -e "CONFIG_ROOT/red/keepconnected" ]; then # user pressed disconnect in gui exit 0 fi if [ -e "CONFIG_ROOT/red/active" ]; then # connected in time so exit echo "0" > CONFIG_ROOT/red/keepconnected exit 0 fi if [ -e "CONFIG_ROOT/red/dial-on-demand" ]; then # Don't count time when dial-on-demand is not really connected if ( ! /sbin/ifconfig | /bin/grep -q addr:10.64.64.64 ); then (( COUNT += 5 )) fi else (( COUNT += 5 )) fi if ( ! /bin/ps ax | /bin/grep -q [p]ppd ); then #pppd exit, so don't need to wait MAXCONFIGURE break fi /bin/sleep 5 done msg "RED fail to connect" RCREDSTART=`/bin/ps ax | /bin/grep '[r]c.red start' | /usr/bin/cut -f1 -d ' '` if [ "$RCREDSTART" != '' ]; then /bin/kill "$RCREDSTART" fi # this attempt to connect fail, so retry #Don't erase keepconnected because it is used to watch user actions /bin/touch CONFIG_ROOT/red/redial /etc/rc.d/rc.red stop while ( /bin/ps ax | /bin/grep -q [p]ppd ); do msg "waiting pppd exit" /bin/sleep 2 done /bin/sleep $HOLDOFF if [ ! -e "CONFIG_ROOT/red/keepconnected" ]; then # user pressed disconnect in gui exit 0 fi (( ATTEMPTS += 1 )) msg "Restarting $ATTEMPTS/$MAXRETRIES" if [ "$ATTEMPTS" -ge "$MAXRETRIES" ]; then echo "0" > CONFIG_ROOT/red/keepconnected msg "Clearing RED interface" /etc/rc.d/rc.red clear if [ "$BACKUPPROFILE" != '' ]; then /bin/rm -f CONFIG_ROOT/ppp/settings /bin/cp "CONFIG_ROOT/ppp/settings-$BACKUPPROFILE" CONFIG_ROOT/ppp/settings fi else echo $ATTEMPTS > CONFIG_ROOT/red/keepconnected fi /etc/rc.d/rc.red start ;; reconnect) while ( /bin/ps ax | /bin/grep -q [p]ppd ); do /bin/sleep 2 done if [ "$PROTOCOL" = RFC1483 ]; then # remove bridged/routed user-space programs if [ "$TYPE" = eciadsl ]; then /etc/rc.d/rc.eciadsl stop fi if [ "$TYPE" = alcatelusb ]; then /etc/rc.d/rc.alcatelusb stop fi fi msg "will connect again" /etc/rc.d/rc.red start ;; *) /bin/echo "Usage: $0 {start|reconnect}" exit 1 ;; esac