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

%config
    teapop_enable="$openpkg_rc_def"
    teapop_log_prolog="true"
    teapop_log_epilog="true"
    teapop_log_numfiles="10"
    teapop_log_minsize="1M"
    teapop_log_complevel="9"
    POP_type="teapop"
    POP_logfile="@l_prefix@/var/teapop/teapop.log"

%start -u @l_susr@
    rcService teapop enable yes || exit 0
    @l_prefix@/sbin/teapop -s

%stop -u @l_susr@
    rcService teapop enable yes || exit 0
    if [ -f @l_prefix@/var/teapop/teapop.pid ]; then
        kill -TERM `cat @l_prefix@/var/teapop/teapop.pid`
        rm -f @l_prefix@/var/teapop/teapop.pid >/dev/null 2>&1 || true
    fi

%restart -u @l_susr@
    rcService teapop enable yes || exit 0
    if [ -f @l_prefix@/var/teapop/teapop.pid ]; then
        kill -TERM `cat @l_prefix@/var/teapop/teapop.pid`
        rm -f @l_prefix@/var/teapop/teapop.pid >/dev/null 2>&1 || true
        sleep 2
    fi
    @l_prefix@/sbin/teapop -s

%daily -u @l_rusr@
    rcService teapop enable yes || exit 0
    prolog="$teapop_log_prolog"
    epilog="$teapop_log_epilog && @l_prefix@/etc/openpkg rc teapop restart || true"
    shtool rotate -f \
        -n ${teapop_log_numfiles} -s ${teapop_log_minsize} -d \
        -z ${teapop_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${prolog}" \
        -E "${epilog}" \
        @l_prefix@/var/teapop/teapop.log

