From f2d9af814740c81d9fc949c9a30e1c8315b60494 Mon Sep 17 00:00:00 2001 From: ms Date: Mon, 8 Jan 2007 15:02:21 +0000 Subject: [PATCH] DHCPCD wurde nicht gekillt :( Connectionscript umgearbeitet. git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@386 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8 --- config/rootfiles/common/initscripts | 4 +- src/initscripts/init.d/connectioncheck | 123 +++++++++++++++++++++++++ src/initscripts/init.d/red | 10 +- 3 files changed, 129 insertions(+), 8 deletions(-) create mode 100644 src/initscripts/init.d/connectioncheck diff --git a/config/rootfiles/common/initscripts b/config/rootfiles/common/initscripts index 38909a92fa..b9977399ca 100644 --- a/config/rootfiles/common/initscripts +++ b/config/rootfiles/common/initscripts @@ -7,6 +7,7 @@ etc/rc.d/helper/writeipac.pl etc/rc.d/init.d/apache etc/rc.d/init.d/checkfs etc/rc.d/init.d/cleanfs +etc/rc.d/init.d/connectioncheck etc/rc.d/init.d/console etc/rc.d/init.d/fcron etc/rc.d/init.d/firewall @@ -71,10 +72,7 @@ etc/rc.d/rcsysinit.d/S70console etc/rc.d/rcsysinit.d/S80localnet etc/rc.d/rcsysinit.d/S90sysctl #etc/sysconfig -etc/sysconfig/clock -etc/sysconfig/console etc/sysconfig/createfiles etc/sysconfig/firewall.local etc/sysconfig/modules -etc/sysconfig/network etc/sysconfig/rc diff --git a/src/initscripts/init.d/connectioncheck b/src/initscripts/init.d/connectioncheck new file mode 100644 index 0000000000..7e2cae53f1 --- /dev/null +++ b/src/initscripts/init.d/connectioncheck @@ -0,0 +1,123 @@ +#!/bin/bash +# + +eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) + +# MAXRETRIES is now a count before 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 "/var/ipfire/red/keepconnected" ]; then + ATTEMPTS=$(/bin/cat /var/ipfire/red/keepconnected) +else + echo "0" > /var/ipfire/red/keepconnected +fi + +case "$1" in + start) + # waiting pppd start or sync timout set at 90 s when available in driver + # So just wait 5 s after 'red start' end where pppd should have been started + TIMETOSTART=0 + while ( ! /bin/ps ax | /bin/grep -q [p]ppd ); do + if [ ! -e "/var/ipfire/red/keepconnected" ]; then + # user pressed disconnect in gui + exit 0 + fi + RCREDSTART=`/bin/ps ax | /bin/grep 'red start'` + if [ "$TIMETOSTART" -eq 1 ]; then + msg "fail before pppd start : no sync, trying again" + /etc/rc.d/init.d/red stop + /etc/rc.d/init.d/red clear + /etc/rc.d/init.d/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 "/var/ipfire/red/keepconnected" ]; then + # user pressed disconnect in gui + exit 0 + fi + if [ -e "/var/ipfire/red/active" ]; then + # connected in time so exit + echo "0" > /var/ipfire/red/keepconnected + exit 0 + fi + if [ -e "/var/ipfire/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 '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 /var/ipfire/red/redial + /etc/rc.d/init.d/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 "/var/ipfire/red/keepconnected" ]; then + # user pressed disconnect in gui + exit 0 + fi + (( ATTEMPTS += 1 )) + msg "Restarting $ATTEMPTS/$MAXRETRIES" + if [ "$ATTEMPTS" -ge "$MAXRETRIES" ]; then + echo "0" > /var/ipfire/red/keepconnected + msg "Clearing RED interface" + /etc/rc.d/init.d/red clear + if [ "$BACKUPPROFILE" != '' ]; then + /bin/rm -f /var/ipfire/ppp/settings + /bin/cp "/var/ipfire/ppp/settings-$BACKUPPROFILE" /var/ipfire/ppp/settings + fi + else + echo $ATTEMPTS > /var/ipfire/red/keepconnected + fi + /etc/rc.d/init.d/red start + ;; + reconnect) + while ( /bin/ps ax | /bin/grep -q [p]ppd ); do + /bin/sleep 2 + done + msg "will connect again" + /etc/rc.d/init.d/red start + ;; + *) + /bin/echo "Usage: $0 {start|reconnect}" + exit 1 + ;; +esac diff --git a/src/initscripts/init.d/red b/src/initscripts/init.d/red index 1b8390dca9..3be287aa9a 100644 --- a/src/initscripts/init.d/red +++ b/src/initscripts/init.d/red @@ -101,7 +101,7 @@ if ($ARGV[0] eq 'start') { if ( ( ( ($netsettings{'RED_TYPE'} =~ /^(PPPOE|PPTP)$/) && ($netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/) ) || ( ( ($pppsettings{'METHOD'} =~ /^(PPPOE|PPPOE_PLUGIN)$/) || ($pppsettings{'PROTOCOL'} eq 'RFC2364') ) && ($netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/) ) ) && ($pppsettings{'RECONNECTION'} ne 'manual') ) { - system ('/etc/rc.d/rc.connectioncheck start &'); + system ('/etc/rc.d/init.d/connectioncheck start &'); } ### @@ -240,7 +240,7 @@ elsif ($ARGV[0] eq 'stop') unlink "${General::swroot}/red/resolv.conf"; unlink "${General::swroot}/red/device"; - # stay with keepconnected during transitional rc.red stop ordered by rc.connectioncheck + # stay with keepconnected during transitional rc.red stop ordered by connectioncheck if ( ! -e "${General::swroot}/red/redial") { unlink "${General::swroot}/red/keepconnected"; } @@ -264,7 +264,7 @@ elsif ($ARGV[0] eq 'stop') } my $file; - while (($file = glob("${General::swroot}/dhcpc/dhcpcd-*.pid") )) { + while (($file = glob("/var/run/dhcpcd-*.pid") )) { if (open(FILE, $file)) { my $pid = ; close FILE; @@ -281,8 +281,8 @@ elsif ($ARGV[0] eq 'stop') system ('/sbin/ifconfig', 'atm0', 'down'); } - if ($pppsettings{'TYPE'} eq 'isdn') { system('/etc/rc.d/rc.isdn','stop'); } - if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','stop'); } + if ($pppsettings{'TYPE'} eq 'isdn') { system('/etc/rc.d/rc.isdn','stop'); } + if ($pppsettings{'TYPE'} eq 'fritzdsl') { system ('/etc/rc.d/rc.fritzdsl','stop'); } if ( ( $netsettings{'CONFIG_TYPE'} =~ /^(2|3|6|7)$/ && $netsettings{'RED_TYPE'} eq 'STATIC') || ( $netsettings{'CONFIG_TYPE'} =~ /^(0|1|4|5)$/ && $pppsettings{'PROTOCOL'} eq 'RFC1483' && -- 2.39.2