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

%config
    tinyproxy_enable="$openpkg_rc_def"
    tinyproxy_log_prolog="true"
    tinyproxy_log_epilog="true"
    tinyproxy_log_numfiles="10"
    tinyproxy_log_minsize="1M"
    tinyproxy_log_complevel="9"

%common
    tinyproxy_pidfile="@l_prefix@/var/tinyproxy/tinyproxy.pid"
    tinyproxy_logfile="@l_prefix@/var/tinyproxy/tinyproxy.log"
    tinyproxy_signal () {
        [ -f $tinyproxy_pidfile ] && kill -$1 `cat $tinyproxy_pidfile`
    }

%status -u @l_susr@ -o
    tinyproxy_usable="unknown"
    tinyproxy_active="no"
    rcService tinyproxy enable yes && \
        tinyproxy_signal 0 && tinyproxy_active="yes"
    echo "tinyproxy_enable=\"$tinyproxy_enable\""
    echo "tinyproxy_usable=\"$tinyproxy_usable\""
    echo "tinyproxy_active=\"$tinyproxy_active\""

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

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

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

%daily -u @l_susr@
    rcService tinyproxy enable yes || exit 0
    shtool rotate -f \
        -n ${tinyproxy_log_numfiles} -s ${tinyproxy_log_minsize} -d \
        -z ${tinyproxy_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${tinyproxy_log_prolog}" \
        -E "${tinyproxy_log_epilog}; rc tinyproxy restart" \
        $tinyproxy_logfile

