#!/usr/sbin/openrc-run

description="Execute the halt command"

depend()
{
	# Called manually from /etc/init.d/rc after openrc finishes.
	# No ordering edges: "after umountroot" inverts stop deps in deptree.
	:
}

NETDOWN=yes

[ -f /etc/default/halt ] && . /etc/default/halt

stop()
{
	if [ "$INIT_HALT" = "" ]
	then
		case "$HALT" in
		  [Pp]*)
			INIT_HALT=POWEROFF
			;;
		  [Hh]*)
			INIT_HALT=HALT
			;;
		  *)
			INIT_HALT=POWEROFF
			;;
		esac
	fi

	if [ "$INIT_HALT" = "POWEROFF" ] && [ -x /etc/init.d/ups-monitor ]
	then
		/etc/init.d/ups-monitor poweroff
	fi

	hddown="-h"
	if grep -qs '^md.*active' /proc/mdstat
	then
		hddown=""
	fi

	poweroff="-p"
	if [ "$INIT_HALT" = "HALT" ]
	then
		poweroff=""
	fi

	netdown="-i"
	if [ "$NETDOWN" = "no" ]; then
		netdown=""
	fi

	einfo "Will now halt"
	halt -d -f $netdown $poweroff $hddown
}

start()
{
	:
}
