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

%config
    ziproxy_enable="$openpkg_rc_def"
    ziproxy_log_prolog="true"
    ziproxy_log_epilog="true"
    ziproxy_log_numfiles="10"
    ziproxy_log_minsize="1M"
    ziproxy_log_complevel="9"

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

%status -u @l_nusr@ -o
    ziproxy_usable="unknown"
    ziproxy_active="no"
    rcService ziproxy enable yes && \
        ziproxy_signal 0 && ziproxy_active="yes"
    echo "ziproxy_enable=\"$ziproxy_enable\""
    echo "ziproxy_usable=\"$ziproxy_usable\""
    echo "ziproxy_active=\"$ziproxy_active\""

%start -u @l_nusr@
    rcService ziproxy enable yes || exit 0
    rcService ziproxy active yes && exit 0
    @l_prefix@/bin/ziproxy -d >$ziproxy_pidfile

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

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

%daily -u @l_nusr@
    rcService ziproxy enable yes || exit 0
    shtool rotate -f \
        -n ${ziproxy_log_numfiles} -s ${ziproxy_log_minsize} -d \
        -z ${ziproxy_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${ziproxy_log_prolog}" \
        -E "${ziproxy_log_epilog}; rc ziproxy restart" \
        @l_prefix@/var/ziproxy/ziproxy.log

