]> git.pld-linux.org Git - packages/autossh.git/blob - autossh.init
- updated to 1.4g, drop -lnsl from linking
[packages/autossh.git] / autossh.init
1 #!/bin/sh
2 #
3 # autossh       ssh sessions manager
4 #
5 # chkconfig:    345 82 18
6 #
7 # description:  ssh sessions manager
8 #
9 # processname:  autossh
10 # config:       /etc/sysconfig/autossh
11 #
12 # $Id$
13
14 # Source function library
15 . /etc/rc.d/init.d/functions
16
17 # Get network config
18 . /etc/sysconfig/network
19
20 # Set defaults
21 AUTOSSH_PORT=0     # connection monitoring port. 0 turns the monitoring function off.
22 AUTOSSH_LOGLEVEL=7
23
24 # Get service config - may override defaults
25 [ -f /etc/sysconfig/autossh ] && . /etc/sysconfig/autossh
26
27 export AUTOSSH_LOGLEVEL
28
29 # Check that networking is up.
30 if is_yes "${NETWORKING}"; then
31         if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
32                 msg_network_down autossh
33                 exit 1
34         fi
35 else
36         exit 0
37 fi
38
39 start() {
40         # Check if the service is already running?
41         if [ -f /var/lock/subsys/autossh ]; then
42                 msg_already_running autossh
43                 return
44         fi
45
46         # Parse autossh.tab file
47         # /^[^#$]/ - removes comments, i.e. lines begining with '#' and empty lines.
48         local I
49         for I in $(awk -vFS=';' '/^[^#$]/ {print $1}' /etc/autossh.tab); do
50                 msg_starting "autossh $I"
51                 AUTOSSH_PIDFILE=/var/run/autossh/$I.pid $(awk -vFS=';' "-vport=$AUTOSSH_PORT" "/^$I;/ "'{printf("daemon autossh -M%s -fN %s\n", port, $2)}' /etc/autossh.tab)
52         done
53
54         # XXX How to detect errors?
55         touch /var/lock/subsys/autossh
56 }
57
58 stop() {
59         if [ ! -f /var/lock/subsys/autossh ]; then
60                 msg_not_running autossh
61                 return
62         fi
63
64         # Stop daemons.
65         for I in /var/run/autossh/*.pid; do
66           msg_stopping "autossh session $(basename $I)"
67           killproc --pidfile $I autossh -TERM
68         done
69         rm -f /var/lock/subsys/autossh
70 }
71
72 reload() {
73         if [ ! -f /var/lock/subsys/autossh ]; then
74                 msg_not_running autossh
75                 RETVAL=7
76                 return
77         fi
78
79         msg_reloading autossh
80         local I
81         for I in /var/run/autossh/*.pid; do
82           killproc --pidfile $I autossh -USR1
83         done
84         # XXX How to detect errors?
85         # RETVAL=$?
86         RETVAL=0
87 }
88
89 condrestart() {
90         if [ ! -f /var/lock/subsys/autossh ]; then
91                 msg_not_running autossh
92                 RETVAL=$1
93                 return
94         fi
95
96         stop
97         start
98 }
99
100 RETVAL=0
101 # See how we were called.
102 case "$1" in
103   start)
104         start
105         ;;
106   stop)
107         stop
108         ;;
109   restart)
110         stop
111         start
112         ;;
113   try-restart)
114         condrestart 0
115         ;;
116   reload|force-reload)
117         reload
118         ;;
119   status)
120         status autossh
121         RETVAL=$?
122         ;;
123   *)
124         msg_usage "$0 {start|stop|restart|try-restart|reload|force-reload|status}"
125         exit 3
126 esac
127
128 exit $RETVAL
This page took 0.093268 seconds and 3 git commands to generate.