#!/sbin/openrc-run
# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License, v2 or later

name="monit"
description="Monit service supervisor"

: ${monit_config:=${CONF:-/etc/monit/monitrc}}

command="/usr/bin/monit"
command_args="-c ${monit_config}"
pidfile="/run/${RC_SVCNAME}.pid"

extra_commands="configtest"
extra_started_commands="reload"

depend() {
	use net
}

configtest() {
        /usr/bin/monit -t -c "${monit_config}" 1>/dev/null 2>&1
        ret=$?
        if [ $ret -ne 0 ]; then
                eerror "${RC_SVCNAME} has detected an error in your setup:"
                /usr/bin/monit -t "${monit_config}"
        fi
        return $ret
}

reload() {
	ebegin "Reloading monit"
	$command -c "${monit_config}" reload >/dev/null 2>&1
	eend $?
}
