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

%config
    trafficserver_enable="$openpkg_rc_def"
    trafficserver_log_prolog="true"
    trafficserver_log_epilog="true"
    trafficserver_log_numfiles="10"
    trafficserver_log_minsize="1M"
    trafficserver_log_complevel="9"

%common
    trafficserver_pidfile="@l_prefix@/var/trafficserver/trafficserver.pid"
    trafficserver_logfile="@l_prefix@/var/trafficserver/trafficserver.log"
    trafficserver_signal () {
        [ -f $trafficserver_pidfile ] && kill -$1 `cat $trafficserver_pidfile`
    }

%status -u @l_susr@ -o
    trafficserver_usable="unknown"
    trafficserver_active="no"
    rcService trafficserver enable yes && \
        trafficserver_signal 0 && trafficserver_active="yes"
    echo "trafficserver_enable=\"$trafficserver_enable\""
    echo "trafficserver_usable=\"$trafficserver_usable\""
    echo "trafficserver_active=\"$trafficserver_active\""

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

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

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

%daily -u @l_susr@
    rcService trafficserver enable yes || exit 0
    shtool rotate -f \
        -n ${trafficserver_log_numfiles} -s ${trafficserver_log_minsize} -d \
        -z ${trafficserver_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${trafficserver_log_prolog}" \
        -E "${trafficserver_log_epilog}; rc trafficserver restart" \
        $trafficserver_logfile

