Fixed connectd to exit if dial on demand is used

This commit is contained in:
Maniacikarus
2008-08-26 20:43:51 +02:00
parent 4c1bf0c9a9
commit 32e19e9c9c
2 changed files with 104 additions and 99 deletions

View File

@@ -1,3 +1,4 @@
etc/squid etc/squid
etc/init.d/connectd
usr/lib/squid usr/lib/squid
usr/sbin/squid usr/sbin/squid

View File

@@ -1,99 +1,103 @@
#!/bin/bash #!/bin/bash
# #
. /etc/sysconfig/rc . /etc/sysconfig/rc
. ${rc_functions} . ${rc_functions}
# Stop if nothing is configured # Stop if nothing is configured
if [ ! -s "/var/ipfire/ppp/settings" ];then if [ ! -s "/var/ipfire/ppp/settings" ];then
exit 0 exit 0
fi fi
eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings) eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
MAX=160 MAX=160
ATTEMPTS=0 ATTEMPTS=0
COUNT=0 COUNT=0
if [ ! $HOLDOFF ]; then if [ ! $HOLDOFF ]; then
HOLDOFF=30 HOLDOFF=30
fi fi
msg_log () { if [ "$RECONNECTION" = "dialondemand" ]; then
logger -t $(basename $0)[$$] $* exit 0
} fi
msg_log "Connectd ($1) started with PID $$" msg_log () {
logger -t $(basename $0)[$$] $*
}
if [ -s "/var/ipfire/red/keepconnected" ]; then
ATTEMPTS=$(cat /var/ipfire/red/keepconnected) msg_log "Connectd ($1) started with PID $$"
else
echo "0" > /var/ipfire/red/keepconnected
fi if [ -s "/var/ipfire/red/keepconnected" ]; then
ATTEMPTS=$(cat /var/ipfire/red/keepconnected)
case "$1" in else
start) echo "0" > /var/ipfire/red/keepconnected
boot_mesg "Starting connection daemon..." fi
echo_ok
case "$1" in
while [ "$COUNT" -lt "$MAX" ]; do start)
if [ ! -e "/var/ipfire/red/keepconnected" ]; then boot_mesg "Starting connection daemon..."
# User pressed disconnect in gui echo_ok
msg_log "Stopping by user request. Exiting."
/etc/rc.d/init.d/network stop red while [ "$COUNT" -lt "$MAX" ]; do
exit 0 if [ ! -e "/var/ipfire/red/keepconnected" ]; then
fi # User pressed disconnect in gui
if [ -e "/var/ipfire/red/active" ]; then msg_log "Stopping by user request. Exiting."
# Successfully connected in time /etc/rc.d/init.d/network stop red
echo "0" > /var/ipfire/red/keepconnected exit 0
msg_log "System is online. Exiting."; exit 0 fi
fi if [ -e "/var/ipfire/red/active" ]; then
if ( ! ps ax | grep -q [p]ppd ); then # Successfully connected in time
msg_log "No pppd is running. Trying reconnect." echo "0" > /var/ipfire/red/keepconnected
break # because pppd died msg_log "System is online. Exiting."; exit 0
fi fi
sleep 5 if ( ! ps ax | grep -q [p]ppd ); then
(( COUNT+=1 )) msg_log "No pppd is running. Trying reconnect."
done break # because pppd died
fi
/etc/rc.d/init.d/network stop red sleep 5
(( COUNT+=1 ))
(( ATTEMPTS+=1 )) done
msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"
if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then /etc/rc.d/init.d/network stop red
echo "0" > /var/ipfire/red/keepconnected
if [ "$BACKUPPROFILE" != '' ]; then (( ATTEMPTS+=1 ))
rm -f /var/ipfire/ppp/settings msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"
cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then
msg_log "Switched to backup profile ${BACKUPPROFILE}" echo "0" > /var/ipfire/red/keepconnected
# to be shure the right secrets are used if [ "$BACKUPPROFILE" != '' ]; then
eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE}) rm -f /var/ipfire/ppp/settings
echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings
else msg_log "Switched to backup profile ${BACKUPPROFILE}"
msg_log "No backup profile given. Exiting." # to be shure the right secrets are used
exit 0 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE})
fi echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets
else else
echo $ATTEMPTS > /var/ipfire/red/keepconnected msg_log "No backup profile given. Exiting."
sleep ${HOLDOFF} exit 0
fi fi
else
/etc/rc.d/init.d/network start red >/dev/tty12 2>&1 </dev/tty12 & echo $ATTEMPTS > /var/ipfire/red/keepconnected
;; sleep ${HOLDOFF}
fi
reconnect)
while ( ps ax | grep -q [p]ppd ); do /etc/rc.d/init.d/network start red &
msg_log "There is a pppd still running. Waiting 2 seconds for exit." ;;
sleep 2
done reconnect)
while ( ps ax | grep -q [p]ppd ); do
/etc/rc.d/init.d/network restart red msg_log "There is a pppd still running. Waiting 2 seconds for exit."
;; sleep 2
done
*)
echo "Usage: $0 {start|reconnect}" /etc/rc.d/init.d/network restart red
exit 1 ;;
;;
esac *)
echo "Usage: $0 {start|reconnect}"
msg_log "Exiting gracefully connectd with PID $$." exit 1
;;
esac
msg_log "Exiting gracefully connectd with PID $$."