Patrick Williams | b48b7b4 | 2016-08-17 15:04:38 -0500 | [diff] [blame] | 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/init.d |
| 22 | lockdir=/var/lock/subsys |
| 23 | sysconfig=/etc/sysconfig |
| 24 | syspath=/sys/block |
| 25 | |
| 26 | RETVAL=0 |
| 27 | |
| 28 | teardown_slaves() |
| 29 | { |
| 30 | pushd $1 > /dev/null |
| 31 | if [ -d "slaves" ]; then |
| 32 | for slave in slaves/*; |
| 33 | do |
| 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 | |
| 47 | else |
| 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 |
| 54 | fi |
| 55 | popd > /dev/null |
| 56 | } |
| 57 | |
| 58 | # |
| 59 | # See how we were called. |
| 60 | # |
| 61 | |
| 62 | start() { |
| 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 | |
| 71 | force_stop() { |
| 72 | echo -n $"Stopping $prog daemon: " |
| 73 | killall $DAEMON |
| 74 | RETVAL=$? |
| 75 | [ $RETVAL -eq 0 ] && rm -f $lockdir/$prog |
| 76 | echo |
| 77 | } |
| 78 | |
| 79 | stop() { |
| 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 | |
| 90 | restart() { |
| 91 | stop |
| 92 | start |
| 93 | } |
| 94 | |
| 95 | force_restart() { |
| 96 | force_stop |
| 97 | start |
| 98 | } |
| 99 | |
| 100 | reload() { |
| 101 | echo -n "Reloading $prog: " |
| 102 | trap "" SIGHUP |
| 103 | killall $DAEMON -s SIGHUP -v |
| 104 | RETVAL=$? |
| 105 | echo |
| 106 | } |
| 107 | |
| 108 | case "$1" in |
| 109 | start) |
| 110 | start |
| 111 | ;; |
| 112 | stop) |
| 113 | stop |
| 114 | ;; |
| 115 | force-stop) |
| 116 | force_stop |
| 117 | ;; |
| 118 | force-reload|reload) |
| 119 | reload |
| 120 | ;; |
| 121 | restart) |
| 122 | restart |
| 123 | ;; |
| 124 | force-restart) |
| 125 | force_restart |
| 126 | ;; |
| 127 | condrestart|try-restart) |
| 128 | if [ -f $lockdir/$prog ]; then |
| 129 | restart |
| 130 | fi |
| 131 | ;; |
| 132 | status) |
| 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 |
| 144 | esac |
| 145 | |
| 146 | exit $RETVAL |