#!/bin/sh
#
# multipathd	Multipath daemon.
#
# chkconfig: - 13 86
# description:	Manage device-mapper multipath devices
# processname: multipathd
# config: /etc/multipath.conf
# pidfile: /var/run/multipathd.pid

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

# Source function library.
. /etc/init.d/functions

PIDFILE=/run/multipathd.pid
LOCKFILE=/var/lock/subsys/multipathd
RETVAL=0

start()
{
	action "Loading kernel modules for multipath:" \
		modprobe -q -a scsi_dh_alua scsi_dh_emc scsi_dh_rdac dm-multipath 2>/dev/null
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- multipathd
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user root -- multipathd
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading multipathd
	stop_daemon --pidfile "$PIDFILE" --expect-user root -HUP -- multipathd
	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --pidfile "$PIDFILE" --expect-user root -- multipathd
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
