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

%config
    drac_enable="$openpkg_rc_def"
    drac_flags=""
    drac_log_prolog="true"
    drac_log_epilog="true"
    drac_log_numfiles="10"
    drac_log_minsize="1M"
    drac_log_complevel="9"

%common
    drac_pidfile="@l_prefix@/var/drac/dracd.pid"
    drac_signal () {
        [ -f $drac_pidfile ] && kill -$1 `cat $drac_pidfile`
    }

%status -u @l_susr@ -o
    drac_usable="no"
    drac_active="no"
    rcService drac enable yes && \
        drac_signal 0 && drac_active="yes"
    echo "drac_enable=\"$drac_enable\""
    echo "drac_usable=\"$drac_usable\""
    echo "drac_active=\"$drac_active\""

%start -u @l_susr@
    rcService drac enable yes || exit 0
    rcService drac active yes && exit 0
    ( nohup @l_prefix@/sbin/dracd $drac_flags </dev/null >/dev/null 2>&1 &
      echo $! >$drac_pidfile
    ) >/dev/null 2>&1

%stop -u @l_susr@
    rcService drac enable yes || exit 0
    rcService drac active no  && exit 0
    drac_signal TERM
    sleep 2
    rm -f $drac_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService drac enable yes || exit 0
    shtool rotate -f \
        -n ${drac_log_numfiles} -s ${drac_log_minsize} -d \
        -z ${drac_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${drac_log_prolog}" \
        -E "${drac_log_epilog}; rc drac restart" \
        @l_prefix@/var/drac/drac.log

