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

%config
    hclnfsd_enable="$openpkg_rc_def"
    hclnfsd_flags=""
    hclnfsd_log_prolog="true"
    hclnfsd_log_epilog="true"
    hclnfsd_log_numfiles="10"
    hclnfsd_log_minsize="1M"
    hclnfsd_log_complevel="9"

%common
    hclnfsd_aclfile="@l_prefix@/etc/hclnfsd/hclnfsd.acl"
    hclnfsd_logfile="@l_prefix@/var/hclnfsd/hclnfsd.log"
    hclnfsd_pidfile="@l_prefix@/var/hclnfsd/hclnfsd.pid"
    hclnfsd_signal () {
        [ -f $hclnfsd_pidfile ] && kill -$1 `cat $hclnfsd_pidfile`
    }

%status -u @l_susr@ -o
    hclnfsd_usable="no"
    hclnfsd_active="no"
    rcService hclnfsd enable yes && \
        hclnfsd_signal 0 && hclnfsd_active="yes"
    echo "hclnfsd_enable=\"$hclnfsd_enable\""
    echo "hclnfsd_usable=\"$hclnfsd_usable\""
    echo "hclnfsd_active=\"$hclnfsd_active\""

%start -p 100 -u @l_susr@
    rcService hclnfsd enable yes || exit 0
    rcService hclnfsd active yes && exit 0
    @l_prefix@/sbin/hclnfsd \
        -A -X \
        -s ${hclnfsd_aclfile} \
        -l ${hclnfsd_logfile} \
        -P ${hclnfsd_pidfile} \
        ${hclnfsd_flags}

%stop -p 900 -u @l_susr@
    rcService hclnfsd enable yes || exit 0
    rcService hclnfsd active no  && exit 0
    hclnfsd_signal TERM
    sleep 2
    rm -f $hclnfsd_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService hclnfsd enable yes || exit 0
    shtool rotate -f \
        -n ${hclnfsd_log_numfiles} -s ${hclnfsd_log_minsize} -d \
        -z ${hclnfsd_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${hclnfsd_log_prolog}" \
        -E "${hclnfsd_log_epilog} && rc hclnfsd reload" \
        $hclnfsd_logfile

