#!/bin/sh
#
# multipathd	Starts multipath daemon
#
# chkconfig:	345 10 90
#
# description:	The multipathd daemon is in charge of checking for failed paths.
#
# $Id: multipathd.init,v 1.6 2009/06/11 21:25:58 glen Exp $

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

[ -f /etc/sysconfig/multipathd ] && . /etc/sysconfig/multipathd

start() {
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/multipathd ]; then
		msg_starting "multipath daemon"
		modprobe dm-multipath
		daemon /sbin/multipathd
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/multipathd
	else
		msg_already_running "multipath daemon"
	fi
}

stop() {
	if [ -f /var/lock/subsys/multipathd ]; then
		# Stop daemons.
		msg_stopping "multipath daemon"
		killproc --pidfile multipathd.pid multipathd -TERM
		rm -f /var/lock/subsys/multipathd
	else
		msg_not_running "multipath daemon"
	fi
}

condrestart() {
	if [ ! -f /var/lock/subsys/multipathd ]; then
		msg_not_running "multipath daemon"
		RETVAL=$1
		return
	fi

	stop
	start
}


RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status multipathd
	RETVAL=$?
	;;
  *)
	msg_usage "$0 {start|stop|status|restart|try-restart|force-reload}"
	exit 3
	;;
esac

exit $RETVAL
