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

%config
    unfsd_enable="$openpkg_rc_def"
    unfsd_bind="127.0.0.1"
    unfsd_flags=""
    unfsd_log_prolog="true"
    unfsd_log_epilog="true"
    unfsd_log_numfiles="10"
    unfsd_log_minsize="1M"
    unfsd_log_complevel="9"

%common
    unfsd_pidfile="@l_prefix@/var/unfsd/unfsd.pid"
    unfsd_logfile="@l_prefix@/var/unfsd/unfsd.log"
    unfsd_signal () {
        [ -f $unfsd_pidfile ] && kill -$1 `cat $unfsd_pidfile`
    }

%status -u @l_susr@ -o
    unfsd_usable="unknown"
    unfsd_active="no"
    rcService unfsd enable yes && \
        unfsd_signal 0 && unfsd_active="yes"
    echo "unfsd_enable=\"$unfsd_enable\""
    echo "unfsd_usable=\"$unfsd_usable\""
    echo "unfsd_active=\"$unfsd_active\""

%start -u @l_susr@
    rcService unfsd enable yes || exit 0
    rcService unfsd active yes && exit 0
    ( nohup @l_prefix@/sbin/unfsd \
        -d -l ${unfsd_bind} \
        -e @l_prefix@/etc/unfsd/unfsd.exports \
        ${unfsd_flags} \
        </dev/null >/dev/null 2>&1 &
        echo $! >$unfsd_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_susr@
    rcService unfsd enable yes || exit 0
    shtool rotate -f \
        -n ${unfsd_log_numfiles} -s ${unfsd_log_minsize} -d \
        -z ${unfsd_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${unfsd_log_prolog}" \
        -E "${unfsd_log_epilog}; rc unfsd restart" \
        $unfsd_logfile

