#!/sbin/openrc-run

name="UPS Monitor"
# `upsmon` refuses to start if `/run/upsmon.pid` points to the supervisor process.
pidfile=/run/upsmon${supervisor:+-${supervisor}}.pid
command=/usr/sbin/upsmon
command_args_foreground="-F"
required_files="/etc/nut/nut.conf /etc/nut/upsmon.conf"
extra_started_commands="reload"

depend() {
	. /etc/nut/nut.conf
	case $MODE in
	standalone|netserver)
		need nut-upsd
		;;
	esac
	use net dns
}

start_pre() {
	. /etc/nut/nut.conf
	case $MODE in
	none)
		eerror "$name disabled, please adjust the configuration to your needs"
		eerror "Then set MODE to a suitable value in /etc/nut/nut.conf to enable it"
		return 1
		;;
	esac
}

stop_post() {
	ebegin "Stopping unprivileged $name child process"
	${command} -c stop > /dev/null
	eend $?
}

reload() {
	ebegin "Reloading $name"
	${command} -c reload > /dev/null
	eend $?
}
