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

%config
    statsite_enable="$openpkg_rc_def"
    statsite_flags=""
    statsite_log_prolog="true"
    statsite_log_epilog="true"
    statsite_log_numfiles="10"
    statsite_log_minsize="1M"
    statsite_log_complevel="9"

%common
    statsite_cfgfile="@l_prefix@/etc/statsite/statsite.ini"
    statsite_pidfile="@l_prefix@/var/statsite/run/statsite.pid"
    statsite_logfile="@l_prefix@/var/statsite/log/statsite.log"
    statsite_signal () {
        [ -f $statsite_pidfile ] && kill -$1 `cat $statsite_pidfile`
    }

%status -u @l_nusr@ -o
    statsite_usable="unknown"
    statsite_active="no"
    rcService statsite enable yes && \
        statsite_signal 0 && statsite_active="yes"
    echo "statsite_enable=\"$statsite_enable\""
    echo "statsite_usable=\"$statsite_usable\""
    echo "statsite_active=\"$statsite_active\""

%start -u @l_nusr@
    rcService statsite enable yes || exit 0
    rcService statsite active yes && exit 0
    @l_prefix@/bin/statsite \
        -f "$statsite_cfgfile" \
        $statsite_flags \
        </dev/null >>$statsite_logfile 2>&1

%stop -u @l_nusr@
    rcService statsite enable yes || exit 0
    rcService statsite active no  && exit 0
    statsite_signal TERM
    sleep 2
    rm -f $statsite_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_nusr@
    rcService statsite enable yes || exit 0
    shtool rotate -f \
        -n ${statsite_log_numfiles} -s ${statsite_log_minsize} -d \
        -z ${statsite_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${statsite_log_prolog}" \
        -E "${statsite_log_epilog}; rc statsite restart" \
        $statsite_logfile

