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

%config
    amd_enable="$openpkg_rc_def"
    amd_log_prolog="true"
    amd_log_epilog="true"
    amd_log_numfiles="10"
    amd_log_minsize="1M"
    amd_log_complevel="9"

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

%status -u @l_susr@ -o
    amd_usable="unknown"
    amd_active="no"
    rcService amd enable yes && \
        amd_signal 0 && amd_active="yes"
    echo "amd_enable=\"$amd_enable\""
    echo "amd_usable=\"$amd_usable\""
    echo "amd_active=\"$amd_active\""

%start -u @l_susr@
    rcService amd enable yes || exit 0
    rcService amd active yes && exit 0
    @l_prefix@/sbin/amd >/dev/null 2>&1

%stop -u @l_susr@
    rcService amd enable yes || exit 0
    rcService amd active no  && exit 0
    amd_signal TERM
    sleep 5
    rm -f $amd_pidfile 2>/dev/null || true

%restart -u @l_susr@
    rcService amd enable yes || exit 0
    rcService amd active no  && exit 0
    rc amd stop start

%reload -u @l_susr@
    rcService amd enable yes || exit 0
    rcService amd active no  && exit 0
    amd_signal HUP

%daily -u @l_susr@
    rcService amd enable yes || exit 0
    shtool rotate -f \
        -n ${amd_log_numfiles} -s ${amd_log_minsize} -d \
        -z ${amd_log_complevel} -o @l_musr@ -g @l_mgrp@ -m 644 \
        -P "$amd_log_prolog" \
        -E "$amd_log_epilog && rc amd restart" \
        @l_prefix@/var/amd/amd.log

