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