]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/initscripts/init.d/connectd
fix collectd initskript load sensormodules from commentlines
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / connectd
CommitLineData
905fbf3e
MT
1#!/bin/bash
2#
3
4. /etc/sysconfig/rc
5. ${rc_functions}
6
3ca6c05a
MT
7# Stop if nothing is configured
8if [ ! -s "/var/ipfire/ppp/settings" ];then
9 exit 0
10fi
11
905fbf3e
MT
12eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings)
13
14MAX=160
15ATTEMPTS=0
16COUNT=0
17if [ ! $HOLDOFF ]; then
18 HOLDOFF=30
19fi
20
21msg_log () {
22 logger -t $(basename $0)[$$] $*
23}
24
25msg_log "Connectd ($1) started with PID $$"
26
27
28if [ -s "/var/ipfire/red/keepconnected" ]; then
29 ATTEMPTS=$(cat /var/ipfire/red/keepconnected)
30else
31 echo "0" > /var/ipfire/red/keepconnected
32fi
33
34case "$1" in
35 start)
36 boot_mesg "Starting connection daemon..."
37 echo_ok
38
3ca6c05a
MT
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
905fbf3e
MT
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}"
cdfc1e52
CS
69 # to be shure the right secrets are used
70 eval $(/usr/local/bin/readhash /var/ipfire/ppp/settings-${BACKUPPROFILE})
71 echo "'$USERNAME' * '$PASSWORD'" > /var/ipfire/ppp/secrets
905fbf3e
MT
72 else
73 msg_log "No backup profile given. Exiting."
74 exit 0
75 fi
76 else
77 echo $ATTEMPTS > /var/ipfire/red/keepconnected
78 sleep ${HOLDOFF}
79 fi
80
81 /etc/rc.d/init.d/network start red &
82 ;;
83
84 reconnect)
85 while ( ps ax | grep -q [p]ppd ); do
352e626f 86 msg_log "There is a pppd still running. Waiting 2 seconds for exit."
905fbf3e
MT
87 sleep 2
88 done
89
352e626f 90 /etc/rc.d/init.d/network restart red
905fbf3e
MT
91 ;;
92
93 *)
94 echo "Usage: $0 {start|reconnect}"
95 exit 1
96 ;;
97esac
98
99msg_log "Exiting gracefully connectd with PID $$."