blob: 3bdf875e3cd480a871f95f1ebabea62aaa45de43 [file] [log] [blame]
Patrick Williamsb48b7b42016-08-17 15:04:38 -05001#!/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
19DAEMON=/sbin/multipathd
20prog=`basename $DAEMON`
21initdir=/etc/init.d
22lockdir=/var/lock/subsys
23sysconfig=/etc/sysconfig
24syspath=/sys/block
25
26RETVAL=0
27
28teardown_slaves()
29{
30pushd $1 > /dev/null
31if [ -d "slaves" ]; then
32for slave in slaves/*;
33do
34 if [ "$slave" = "slaves/*" ]; then
35 read dev < $1/dev
36 tablename=`dmsetup table --target multipath | sed -n "s/\(.*\): .* $dev .*/\1/p"`
37 if ! [ -z $tablename ]; then
38 echo "Root is on a multipathed device, multipathd can not be stopped"
39 exit 1
40 fi
41 else
42 local_slave=`readlink -f $slave`;
43 teardown_slaves $local_slave;
44 fi
45 done
46
47else
48 read dev < $1/dev
49 tablename=`dmsetup table --target multipath | sed -n "s/\(.*\): .* $dev .*/\1/p"`
50 if ! [ -z $tablename ]; then
51 echo "Root is on a multipathed device, multipathd can not be stopped"
52 exit 1
53 fi
54fi
55popd > /dev/null
56}
57
58#
59# See how we were called.
60#
61
62start() {
63 test -x $DAEMON || exit 5
64 echo -n $"Starting $prog daemon: "
65 start-stop-daemon --start --quiet --exec $DAEMON
66 RETVAL=$?
67 [ $RETVAL -eq 0 ] && touch $lockdir/$prog
68 echo
69}
70
71force_stop() {
72 echo -n $"Stopping $prog daemon: "
73 killall $DAEMON
74 RETVAL=$?
75 [ $RETVAL -eq 0 ] && rm -f $lockdir/$prog
76 echo
77}
78
79stop() {
80 root_dev=$(awk '{ if ($1 !~ /^[ \t]*#/ && $2 == "/") { print $1; }}' /etc/mtab)
81 dm_num=`dmsetup info -c --noheadings -o minor $root_dev 2> /dev/null`
82 if [ $? -eq 0 ]; then
83 root_dm_device="dm-$dm_num"
84 [ -d $syspath/$root_dm_device ] && teardown_slaves $syspath/$root_dm_device
85 fi
86
87 force_stop
88}
89
90restart() {
91 stop
92 start
93}
94
95force_restart() {
96 force_stop
97 start
98}
99
100reload() {
101 echo -n "Reloading $prog: "
102 trap "" SIGHUP
103 killall $DAEMON -s SIGHUP -v
104 RETVAL=$?
105 echo
106}
107
108case "$1" in
109start)
110 start
111 ;;
112stop)
113 stop
114 ;;
115force-stop)
116 force_stop
117 ;;
118force-reload|reload)
119 reload
120 ;;
121restart)
122 restart
123 ;;
124force-restart)
125 force_restart
126 ;;
127condrestart|try-restart)
128 if [ -f $lockdir/$prog ]; then
129 restart
130 fi
131 ;;
132status)
133 if pidof -o %PPID $DAEMON > /dev/null; then
134 echo "Running"
135 RETVAL=0
136 else
137 echo "Not running"
138 RETVAL=1
139 fi
140 ;;
141*)
142 echo $"Usage: $0 {start|stop|force-stop|status|restart|force-restart|condrestart|reload}"
143 RETVAL=2
144esac
145
146exit $RETVAL