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

%config
    tor_enable="$openpkg_rc_def"
    tor_log_prolog="true"
    tor_log_epilog="true"
    tor_log_numfiles="10"
    tor_log_minsize="1M"
    tor_log_complevel="9"

%common
    tor_logfile="@l_prefix@/var/tor/tor.log"
    tor_pidfile="@l_prefix@/var/tor/tor.pid"
    tor_signal () {
        [ -f $tor_pidfile ] && kill -$1 `cat $tor_pidfile`
    }

%status -u @l_rusr@ -o
    tor_usable="unknown"
    tor_active="no"
    rcService tor enable yes && \
        tor_signal 0 && tor_active="yes"
    echo "tor_enable=\"$tor_enable\""
    echo "tor_usable=\"$tor_usable\""
    echo "tor_active=\"$tor_active\""

%start -u @l_rusr@
    rcService tor enable yes || exit 0
    rcService tor active yes && exit 0
    @l_prefix@/bin/tor

%stop -u @l_rusr@
    rcService tor enable yes || exit 0
    rcService tor active no  && exit 0
    tor_signal TERM
    sleep 2
    rm -f $tor_pidfile >/dev/null 2>&1 || true

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

%reload -u @l_rusr@
    rcService tor enable yes || exit 0
    rcService tor active no  && exit 0
    tor_signal HUP

%daily -u @l_susr@
    rcService tor enable yes || exit 0
    shtool rotate -f \
        -n ${tor_log_numfiles} -s ${tor_log_minsize} -d \
        -z ${tor_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${tor_log_prolog}" \
        -E "${tor_log_epilog}; rc tor restart" \
        ${tor_logfile}

