#!/bin/sh
#
# multipathd shutdown

PREREQ=""

prereqs() { echo "$PREREQ"; }

case $1 in
prereqs)
	prereqs
	exit 0
	;;
esac

. /scripts/functions

verbose()
{
  case "$quiet" in y*|Y*|1|t*|T*)
    return 1;;
  *)
    return 0;;
  esac
}

maybe_break pre-multipath

if [ ! -e /sbin/multipathd ]; then
	exit 0
fi

# Stop multipathd
verbose && log_begin_msg "Stopping multipathd"

pid_pidof="$(pidof multipathd)"
pid_file="$(cat /var/run/multipathd.pid)"

if [ "${pid_pidof}" = "${pid_file}" ]; then
	kill ${pid_pidof}
	verbose && log_end_msg
else
	verbose && log_failure_msg "inconsistent PIDs (pidof: '${pid_pidof}', multipathd.pid: '${pid_file}')"
fi

maybe_break post-multipath

exit 0

