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

%config
    tacacs_enable="$openpkg_rc_def"
    tacacs_log_prolog="true"
    tacacs_log_epilog="true"
    tacacs_log_numfiles="10"
    tacacs_log_minsize="1M"
    tacacs_log_complevel="9"

%common
    tacacs_cfgfile="@l_prefix@/etc/tacacs/tac_plus.cfg"
    tacacs_pidfile="@l_prefix@/var/tacacs/tac_plus.pid"
    tacacsr_signal () {
        [ -f $tacacs_pidfile ] && kill -$1 `cat $tacacs_pidfile`
    }

%status -u @l_susr@ -o
    tacacs_usable="unknown"
    tacacs_active="no"
    rcService tacacs enable yes && \
        tacacs_signal 0 && tacacs_active="yes"
    echo "tacacs_enable=\"$tacacs_enable\""
    echo "tacacs_usable=\"$tacacs_usable\""
    echo "tacacs_active=\"$tacacs_active\""

%start -p 300 -u @l_susr@
    rcService tacacs enable yes || exit 0
    rcService tacacs active yes && exit 0
    @l_prefix@/sbin/tac_plus -C $tacacs_cfgfile

%stop -p 700 -u @l_susr@
    rcService tacacs enable yes || exit 0
    rcService tacacs active no  && exit 0
    tacacs_signal TERM
    sleep 2
    rm -f $tacacs_pidfile >/dev/null 2>&1 || true

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

%daily
    rcService tacacs enable yes || exit 0
    shtool rotate -f \
        -n ${tacacs_log_numfiles} -s ${tacacs_log_minsize} -d \
        -z ${tacacs_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${tacacs_log_prolog}" \
        -E "${tacacs_log_epilog}; rc tacacs restart" \
        @l_prefix@/var/tacacs/tacacs.log

