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

%config
    freeradius_enable="$openpkg_rc_def"
    freeradius_flags=""
    freeradius_log_prolog="true"
    freeradius_log_epilog="true"
    freeradius_log_numfiles="10"
    freeradius_log_minsize="1M"
    freeradius_log_complevel="9"

%common
    freeradius_logfile="@l_prefix@/var/freeradius/radius.log"
    freeradius_pidfile="@l_prefix@/var/freeradius/radiusd.pid"
    freeradius_signal () {
        [ -f $freeradius_pidfile ] && kill -$1 `cat $freeradius_pidfile`
    }

%status -u @l_susr@ -o
    freeradius_usable="no"
    freeradius_active="no"
    rcService freeradius enable yes && \
        freeradius_signal 0 && freeradius_active="yes"
    echo "freeradius_enable=\"$freeradius_enable\""
    echo "freeradius_usable=\"$freeradius_usable\""
    echo "freeradius_active=\"$freeradius_active\""

%start -u @l_susr@
    rcService freeradius enable yes || exit 0
    rcService freeradius active yes && exit 0
    @l_prefix@/sbin/radiusd ${freeradius_flags}

%stop -u @l_susr@
    rcService freeradius enable yes || exit 0
    rcService freeradius active no  && exit 0
    freeradius_signal TERM
    sleep 2
    rm -f ${freeradius_pidfile} >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService freeradius enable yes || exit 0
    shtool rotate -f \
        -n ${freeradius_log_numfiles} -s ${freeradius_log_minsize} -d \
        -z ${freeradius_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${freeradius_log_prolog}" \
        -E "${freeradius_log_epilog} && rc freeradius reload" \
        ${freeradius_logfile}

