#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.proftpd -- Run-Commands
##

%config
    proftpd_enable="$openpkg_rc_def"
    proftpd_acc_file="@l_prefix@/var/proftpd/proftpd.access.log"
    proftpd_acc_prolog="true"
    proftpd_acc_epilog="true"
    proftpd_acc_numfiles="10"
    proftpd_acc_minsize="1M"
    proftpd_acc_complevel="9"
    proftpd_auth_file="@l_prefix@/var/proftpd/proftpd.auth.log"
    proftpd_auth_prolog="true"
    proftpd_auth_epilog="true"
    proftpd_auth_numfiles="10"
    proftpd_auth_minsize="1M"
    proftpd_auth_complevel="9"
    proftpd_sys_file="@l_prefix@/var/proftpd/proftpd.system.log"
    proftpd_sys_prolog="true"
    proftpd_sys_epilog="true"
    proftpd_sys_numfiles="10"
    proftpd_sys_minsize="1M"
    proftpd_sys_complevel="9"
    proftpd_xfer_file="@l_prefix@/var/proftpd/proftpd.xfer.log"
    proftpd_xfer_prolog="true"
    proftpd_xfer_epilog="true"
    proftpd_xfer_numfiles="10"
    proftpd_xfer_minsize="1M"
    proftpd_xfer_complevel="9"

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

%status -u @l_susr@ -o
    proftpd_usable="unknown"
    proftpd_active="no"
    rcService proftpd enable yes && \
        proftpd_signal 0 && proftpd_active="yes"
    echo "proftpd_enable=\"$proftpd_enable\""
    echo "proftpd_usable=\"$proftpd_usable\""
    echo "proftpd_active=\"$proftpd_active\""

%start -u @l_susr@
    rcService proftpd enable yes || exit 0
    rcService proftpd active yes && exit 0
    @l_prefix@/sbin/proftpd

%stop -u @l_susr@
    rcService proftpd enable yes || exit 0
    rcService proftpd active no  && exit 0
    proftpd_signal TERM
    sleep 2

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

%reload -u @l_susr@
    rcService proftpd enable yes || exit 0
    proftpd_signal HUP

%daily -u @l_susr@
    rcService proftpd enable yes || exit 0
    rcTmp -i
    hintfile=`rcTmp -f -n hint`
    shtool rotate -f \
        -n ${proftpd_acc_numfiles} -s ${proftpd_acc_minsize} -d \
        -z ${proftpd_acc_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${proftpd_acc_prolog}" \
        -E "${proftpd_acc_epilog}; echo 1 >$hintfile" \
        ${proftpd_acc_file}
    shtool rotate -f \
        -n ${proftpd_auth_numfiles} -s ${proftpd_auth_minsize} -d \
        -z ${proftpd_auth_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${proftpd_auth_prolog}" \
        -E "${proftpd_auth_epilog}; echo 1 >$hintfile" \
        ${proftpd_auth_file}
    shtool rotate -f \
        -n ${proftpd_sys_numfiles} -s ${proftpd_sys_minsize} -d \
        -z ${proftpd_sys_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${proftpd_sys_prolog}" \
        -E "${proftpd_sys_epilog}; echo 1 >$hintfile" \
        ${proftpd_sys_file}
    shtool rotate -f \
        -n ${proftpd_xfer_numfiles} -s ${proftpd_xfer_minsize} -d \
        -z ${proftpd_xfer_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${proftpd_xfer_prolog}" \
        -E "${proftpd_xfer_epilog}; echo 1 >$hintfile" \
        ${proftpd_xfer_file}
    if [ -s $hintfile ]; then
        rc proftpd restart
    fi
    rcTmp -k

