d1319b1a03be0a95571914972dc207cd642f95a4
[multipath-tools/.git] / multipathd / multipathd.init.suse
1 #! /bin/sh
2 # Copyright (c) 1995-2001 SuSE GmbH Nuernberg, Germany.
3 #
4 # Author: Hannes Reinecke <feedback@suse.de>
5 #
6 # init.d/multipathd
7 #
8 ### BEGIN INIT INFO
9 # Provides:          multipathd
10 # Required-Start:    $syslog
11 # Required-Stop:     $syslog
12 # Default-Start:     3 5
13 # Default-Stop:      0 1 2 4 6
14 # Short-Description: Starts multipath daemon
15 # Description:       Starts the multipath daemon
16 ### END INIT INFO
17
18 PATH=/bin:/usr/bin:/sbin:/usr/sbin
19 DAEMON=/sbin/multipathd
20 PIDFILE=/var/run/multipathd.pid
21 MPATH_INIT_TIMEOUT=10
22 ARGS=""
23
24 # Set the maximum number of open files
25 MAX_OPEN_FDS=4096
26
27 # Set to enable asynchronous daemon startup
28 DAEMON_ASYNC_STARTUP=
29
30 test -x $DAEMON || exit 5
31
32 . /etc/rc.status
33
34 # First reset status of this service
35 rc_reset
36
37 case "$1" in
38     start)
39         echo -n "Starting multipathd"
40         ulimit -c unlimited
41         if $DAEMON -k"reconfigure" > /dev/null 2>&1 ; then
42             echo -n " (multipathd running)"
43             rc_status -v
44             rc_exit
45         fi
46
47         modprobe dm-multipath
48
49         # Set the maximum number of open files
50         if [ -n "$MAX_OPEN_FDS" ] ; then
51             ulimit -n $MAX_OPEN_FDS
52         fi
53
54         $DAEMON $ARGS
55
56         if [ -n "$DAEMON_ASYNC_STARTUP" ] ; then
57             rc_status -v
58             rc_exit
59         fi
60         # Wait for the daemon to start up
61         status=$($DAEMON -k'show daemon' 2> /dev/null)
62         timeout=$MPATH_INIT_TIMEOUT
63         while [ $timeout -gt 0 ] ; do
64             if [ -n "$status" ] ; then
65                 PID=${status##pid }
66                 STATUS=${PID##* }
67                 # Configuration might be taking some time,
68                 # so don't increase the timeout here
69                 [ "$STATUS" != "configure" ] && timeout=$(( $timeout - 1 ))
70
71                 [ "$STATUS" == "running" ] && break
72             else
73                 timeout=$(( $timeout - 1 ))
74             fi
75             sleep 1
76             status=$($DAEMON -k'show daemon' 2> /dev/null)
77         done
78         if [ -z "$status" ] ; then
79             rc_failed 7
80         fi
81         if [ $timeout -le 0 ] ; then
82             rc_failed 1
83         fi
84         # Remember status and be verbose
85         rc_status -v
86         ;;
87     stop)
88         echo -n "Shutting down multipathd"
89         STATUS="unknown"
90         # Try to get PID from daemon
91         status=$($DAEMON -k'show daemon' 2> /dev/null)
92         if [ -n "$status" ] ; then
93             PID=${status##pid }
94             STATUS=${PID##* }
95             PID=${PID%% *}
96         fi
97         # Fallback to PID file for older versions
98         if [ -z "$PID" ] || [ "$PID" == "multipath-tools" ] ; then
99             if [ -f $PIDFILE ]; then
100                 PID="$(cat $PIDFILE)"
101                 STATUS="running"
102             else
103                 rc_failed 7
104                 rc_status -v
105                 rc_exit
106             fi
107         fi
108         # Shutdown the daemon via CLI
109         if [ "$STATUS" = "running" ] ; then
110             status=$($DAEMON -k'shutdown' 2> /dev/null)
111             if [ "$status" = "ok" ] ; then
112                 timeout=$MPATH_INIT_TIMEOUT
113                 while [ $timeout -gt 0 ] ; do
114                     PROCNAME="$(ps -p $PID -o comm=)"
115                     if [ "$PROCNAME" != "multipathd" ] &&
116                         [ "$PROCNAME" != "multipathd <defunct>" ] ; then
117                         STATUS="shutdown"
118                         break
119                     fi
120                     sleep 1
121                     timeout=$(( $timeout - 1 ))
122                 done
123             fi
124         fi
125         # Kill the daemon if the above failed
126         if [ -n "$PID" -a "$STATUS" != "shutdown" ] ; then
127             kill -TERM $PID
128             timeout=$MPATH_INIT_TIMEOUT
129             while [ $timeout -gt 0 ] ; do
130                 PROCNAME="$(ps -p $PID -o comm=)"
131                 if [ "$PROCNAME" != "multipathd" ] &&
132                     [ "$PROCNAME" != "multipathd <defunct>" ] ; then
133                     STATUS="shutdown"
134                     break
135                 fi
136                 sleep 1
137                 timeout=$(( $timeout - 1 ))
138             done
139         fi
140         if [ $STATUS != "shutdown" ] ; then
141             echo -n " (still running)"
142             rc_failed 1
143         fi
144
145         # Remember status and be verbose
146         rc_status -v
147         ;;
148     try-restart)
149         ## Stop the service and if this succeeds (i.e. the 
150         ## service was running before), start it again.
151         $0 status >/dev/null &&  $0 restart
152
153         # Remember status and be quiet
154         rc_status
155         ;;
156     restart|force-reload)
157         ## Stop the service and regardless of whether it was
158         ## running or not, start it again.
159         $0 stop
160         $0 start
161
162         # Remember status and be quiet
163         rc_status
164         ;;
165     reload)
166         ## Like force-reload, but if daemon does not support
167         ## signalling, do nothing (!)
168
169         $DAEMON -k"reconfigure" > /dev/null 2>&1
170
171         # Remember status and be quiet
172         rc_status
173         ;;
174     status)
175         echo -n "Checking for multipathd: "
176
177         # Status has a slightly different for the status command:
178         # 0 - service running
179         # 1 - service dead, but /var/run/  pid  file exists
180         # 2 - service dead, but /var/lock/ lock file exists
181         # 3 - service not running
182
183         status=$($DAEMON -k'show daemon' 2> /dev/null)
184         if [ -n "$status" ]; then
185                 (exit 0)
186         else
187                 (exit 3)
188         fi
189         rc_status -v
190         ;;
191     probe)
192         ## Optional: Probe for the necessity of a reload,
193         ## give out the argument which is required for a reload.
194         ;;
195     *)
196         echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
197         exit 1
198         ;;
199 esac
200 rc_exit