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

%config
    sysmon_enable="$openpkg_rc_def"
    sysmon_log_prolog="true"
    sysmon_log_epilog="true"
    sysmon_log_numfiles="10"
    sysmon_log_minsize="1M"
    sysmon_log_complevel="9"
    sysmon_stop_timeout="60"

%common
    sysmon_pidfile="@l_prefix@/var/sysmon/sysmond.pid"
    sysmon_signal () {
        [ -f $sysmon_pidfile ] && kill -$1 `cat $sysmon_pidfile`
    }

%status -u @l_susr@ -o
    sysmon_usable="unknown"
    sysmon_active="no"
    rcService sysmon enable yes && \
        sysmon_signal 0 && sysmon_active="yes"
    echo "sysmon_enable=\"$sysmon_enable\""
    echo "sysmon_usable=\"$sysmon_usable\""
    echo "sysmon_active=\"$sysmon_active\""

%start -u @l_susr@
    rcService sysmon enable yes || exit 0
    @l_prefix@/sbin/sysmond -q -f @l_prefix@/etc/sysmon/sysmon.conf >/dev/null 2>&1

%stop -u @l_susr@
    rcService sysmon enable yes || exit 0
    sysmon_signal TERM

%restart -u @l_susr@
    rcService sysmon enable yes || exit 0
    rc sysmon stop
    sleep 2
    rc sysmon start

%reload -u @l_susr@
    rcService sysmon enable yes || exit 0
    sysmon_signal HUP

%daily -u @l_susr@
    rcService sysmon enable yes || exit 0
    shtool rotate -f \
        -n ${sysmon_log_numfiles} -s ${sysmon_log_minsize} -d \
        -z ${sysmon_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${sysmon_log_prolog}" \
        -E "${sysmon_log_epilog}" \
        @l_prefix@/var/sysmon/sysmon.log

