make multipathd disable queue_without_daemon by default
[multipath-tools/.git] / multipathd / multipathd.init.redhat
1 #!/bin/bash
2 #
3 # multipathd    Starts the multipath daemon
4 #
5 # chkconfig: - 06 87
6 # description: Manages device-mapper multipath devices
7
8 ### BEGIN INIT INFO
9 # Provides: multipathd
10 # Required-Start:
11 # Required-Stop:
12 # Default-Start:
13 # Default-Stop:
14 # Short-Description: Control multipathd
15 # Description: This service monitors and manages
16 #              device-mapper multipath devices
17 ### END INIT INFO
18
19 DAEMON=/sbin/multipathd
20 prog=`basename $DAEMON`
21 initdir=/etc/rc.d/init.d
22 lockdir=/var/lock/subsys
23 sysconfig=/etc/sysconfig
24 syspath=/sys/block
25
26  
27 . $initdir/functions
28  
29 test -r $sysconfig/$prog && . $sysconfig/$prog
30
31 RETVAL=0
32
33 teardown_slaves()
34 {
35 pushd $1 > /dev/null
36 if [ -d "slaves" ]; then
37 for slave in slaves/*;
38 do
39         if [ "$slave" = "slaves/*" ]; then
40                 read dev <  $1/dev
41                 tablename=`dmsetup table --target multipath | sed -n "s/\(.*\): .* $dev .*/\1/p"`
42                 if ! [ -z $tablename ]; then
43                         echo "Root is on a multipathed device, multipathd can not be stopped"
44                         exit 1
45                 fi
46         else
47                 local_slave=`readlink -f $slave`;
48                 teardown_slaves $local_slave;
49         fi
50         done
51
52 else
53                 read dev <  $1/dev
54                 tablename=`dmsetup table --target multipath | sed -n "s/\(.*\): .* $dev .*/\1/p"`
55                 if ! [ -z $tablename ]; then
56                         echo "Root is on a multipathed device, multipathd can not be stopped"
57                         exit 1
58                 fi
59 fi
60 popd > /dev/null
61 }
62
63 #
64 # See how we were called.
65 #
66
67 start() {
68         test -x $DAEMON || exit 5
69         echo -n $"Starting $prog daemon: "
70         daemon $DAEMON
71         RETVAL=$?
72         [ $RETVAL -eq 0 ] && touch $lockdir/$prog
73         echo
74 }
75
76 force_stop() {
77         echo -n $"Stopping $prog daemon: "
78         killproc $DAEMON
79         RETVAL=$?
80         [ $RETVAL -eq 0 ] && rm -f $lockdir/$prog
81         echo
82 }
83
84 check_root() {
85         root_dev=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/mtab)
86         dm_num=`dmsetup info -c --noheadings -o minor $root_dev 2> /dev/null`
87         if [ $? -eq 0 ]; then
88                 root_dm_device="dm-$dm_num"
89                 [ -d $syspath/$root_dm_device ] && teardown_slaves $syspath/$root_dm_device
90         fi
91 }
92
93 force_queue_without_daemon() {
94         $DAEMON forcequeueing daemon
95 }
96
97 restart() {
98         force_queue_without_daemon
99         check_root
100         force_stop
101         start
102 }
103
104 force_restart() {
105         force_queue_without_daemon
106         force_stop
107         start
108 }
109
110 reload() {
111         echo -n "Reloading $prog: "
112         trap "" SIGHUP
113         killproc $DAEMON -HUP
114         RETVAL=$?
115         echo
116 }       
117
118 case "$1" in
119 start)
120         start
121         ;;
122 stop)
123         check_root
124         force_stop
125         ;;
126 force-stop)
127         force_stop
128         ;;
129 force-reload|reload)
130         reload
131         ;;
132 restart)
133         restart
134         ;;
135 force-restart)
136         force_restart
137         ;;
138 condrestart|try-restart)
139         if [ -f $lockdir/$prog ]; then
140             restart
141         fi
142         ;;
143 status)
144         status $prog
145         RETVAL=$?
146         ;;
147 *)
148         echo $"Usage: $0 {start|stop|force-stop|status|restart|force-restart|condrestart|reload}"
149         RETVAL=2
150 esac
151
152 exit $RETVAL