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

%config
    privoxy_enable="$openpkg_rc_def"
    privoxy_bind="127.0.0.1:110"
    privoxy_log_prolog="true"
    privoxy_log_epilog="true"
    privoxy_log_numfiles="10"
    privoxy_log_minsize="1M"
    privoxy_log_complevel="9"

%common
    privoxy_cfgfile="@l_prefix@/etc/privoxy/config"
    privoxy_pidfile="@l_prefix@/var/privoxy/run/privoxy.pid"
    privoxy_logfile="@l_prefix@/var/privoxy/log/privoxy.log"
    privoxy_signal () {
        [ -f $privoxy_pidfile ] && kill -$1 `cat $privoxy_pidfile`
    }

%status -u @l_susr@ -o
    privoxy_usable="unknown"
    privoxy_active="no"
    rcService privoxy enable yes && \
        privoxy_signal 0 && privoxy_active="yes"
    echo "privoxy_enable=\"$privoxy_enable\""
    echo "privoxy_usable=\"$privoxy_usable\""
    echo "privoxy_active=\"$privoxy_active\""

%start -u @l_susr@
    rcService privoxy enable yes || exit 0
    rcService privoxy active yes && exit 0
    @l_prefix@/sbin/privoxy \
        --user @l_rusr@.@l_rgrp@ \
        --pidfile $privoxy_pidfile \
        $privoxy_cfgfile

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

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

%daily -u @l_susr@
    rcService privoxy enable yes || exit 0
    shtool rotate -f \
        -n $privoxy_log_numfiles -s $privoxy_log_minsize -d \
        -z $privoxy_log_complevel -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "$privoxy_log_prolog" \
        -E "$privoxy_log_epilog; rc privoxy restart" \
        $privoxy_logfile

