]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/init.d/connectd
Nochmal 2 Fixes.
[people/pmueller/ipfire-2.x.git] / src / initscripts / init.d / connectd
1 #!/bin/bash
2 #
3
4 . /etc/sysconfig/rc
5 . ${rc_functions}
6
7 # Stop if nothing is configured
8 if [ ! -s "/var/ipfire/ppp/settings" ];then
9 exit 0
10 fi
11
12 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
13
14 MAX=160
15 ATTEMPTS=0
16 COUNT=0
17 if [ ! $HOLDOFF ]; then
18 HOLDOFF=30
19 fi
20
21 msg_log () {
22 logger -t $(basename $0)[$$] $*
23 }
24
25 msg_log "Connectd ($1) started with PID $$"
26
27
28 if [ -s "/var/ipfire/red/keepconnected" ]; then
29 ATTEMPTS=$(cat /var/ipfire/red/keepconnected)
30 else
31 echo "0" > /var/ipfire/red/keepconnected
32 fi
33
34 case "$1" in
35 start)
36 boot_mesg "Starting connection daemon..."
37 echo_ok
38
39 while [ "$COUNT" -lt "$MAX" ]; do
40 if [ ! -e "/var/ipfire/red/keepconnected" ]; then
41 # User pressed disconnect in gui
42 msg_log "Stopping by user request. Exiting."
43 /etc/rc.d/init.d/network stop red
44 exit 0
45 fi
46 if [ -e "/var/ipfire/red/active" ]; then
47 # Successfully connected in time
48 echo "0" > /var/ipfire/red/keepconnected
49 msg_log "System is online. Exiting."; exit 0
50 fi
51 if ( ! ps ax | grep -q [p]ppd ); then
52 msg_log "No pppd is running. Trying reconnect."
53 break # because pppd died
54 fi
55 sleep 5
56 (( COUNT+=1 ))
57 done
58
59 /etc/rc.d/init.d/network stop red
60
61 (( ATTEMPTS+=1 ))
62 msg_log "Reconnecting: Attempt ${ATTEMPTS} of ${MAXRETRIES}"
63 if [ "${ATTEMPTS}" -ge "${MAXRETRIES}" ]; then
64 echo "0" > /var/ipfire/red/keepconnected
65 if [ "$BACKUPPROFILE" != '' ]; then
66 rm -f /var/ipfire/ppp/settings
67 cp "/var/ipfire/ppp/settings-${BACKUPPROFILE}" /var/ipfire/ppp/settings
68 msg_log "Switched to backup profile ${BACKUPPROFILE}"
69 else
70 msg_log "No backup profile given. Exiting."
71 exit 0
72 fi
73 else
74 echo $ATTEMPTS > /var/ipfire/red/keepconnected
75 sleep ${HOLDOFF}
76 fi
77
78 /etc/rc.d/init.d/network start red &
79 ;;
80
81 reconnect)
82 while ( ps ax | grep -q [p]ppd ); do
83 sleep 2
84 done
85
86 /etc/rc.d/init.d/network restart red &
87 ;;
88
89 *)
90 echo "Usage: $0 {start|reconnect}"
91 exit 1
92 ;;
93 esac
94
95 msg_log "Exiting gracefully connectd with PID $$."