#!@l_prefix@/bin/openpkg rc
##
##  rc.monit -- Run-Commands
##

%config
    monit_enable="$openpkg_rc_def"
    monit_log_prolog="true"
    monit_log_epilog="true"
    monit_log_numfiles="10"
    monit_log_minsize="1M"
    monit_log_complevel="9"

%common
    monit_pidfile="@l_prefix@/var/monit/monit.pid"
    monit_signal () {
        [ -f $monit_pidfile ] && kill -$1 `cat $monit_pidfile`
    }

%status -u @l_susr@ -o
    monit_usable="no"
    monit_active="no"
    rcService monit enable yes && \
        @l_prefix@/bin/monit -t && monit_usable="yes"
    rcService monit enable yes && \
        monit_signal 0 && monit_active="yes"
    echo "monit_enable=\"$monit_enable\""
    echo "monit_usable=\"$monit_usable\""
    echo "monit_active=\"$monit_active\""

%start -p 900 -u @l_susr@
    rcService monit enable yes || exit 0
    @l_prefix@/bin/monit >/dev/null

%stop -p 100 -u @l_susr@
    rcService monit enable yes || exit 0
    @l_prefix@/bin/monit quit

%restart -u @l_susr@
    rcService monit enable yes || exit 0
    @l_prefix@/bin/monit quit
    @l_prefix@/bin/monit >/dev/null

%reload -u @l_susr@
    rcService monit enable yes || exit 0
    @l_prefix@/bin/monit reload

%daily -u @l_susr@
    rcService monit enable yes || exit 0
    shtool rotate -f \
        -n ${monit_log_numfiles} -s ${monit_log_minsize} -d \
        -z ${monit_log_complevel} -o @l_musr@ -g @l_mgrp@ -m 600 \
        -P "${monit_log_prolog}" \
        -E "${monit_log_epilog} && rc monit reload" \
        @l_prefix@/var/monit/monit.log

