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

%config
    radius_enable="$openpkg_rc_def"
    radius_debug_file="@l_prefix@/var/radius/log/radius.debug"
    radius_debug_prolog="true"
    radius_debug_epilog="true"
    radius_debug_numfiles="10"
    radius_debug_minsize="1M"
    radius_debug_complevel="9"
    radius_info_file="@l_prefix@/var/radius/log/radius.info"
    radius_info_prolog="true"
    radius_info_epilog="true"
    radius_info_numfiles="10"
    radius_info_minsize="1M"
    radius_info_complevel="9"
    radius_main_file="@l_prefix@/var/radius/log/radius.log"
    radius_main_prolog="true"
    radius_main_epilog="true"
    radius_main_numfiles="10"
    radius_main_minsize="1M"
    radius_main_complevel="9"
    radius_stat_file="@l_prefix@/var/radius/log/radius.stat"
    radius_stat_prolog="true"
    radius_stat_epilog="true"
    radius_stat_numfiles="10"
    radius_stat_minsize="1M"
    radius_stat_complevel="9"
    radius_stderr_file="@l_prefix@/var/radius/log/radius.stderr"
    radius_stderr_prolog="true"
    radius_stderr_epilog="true"
    radius_stderr_numfiles="10"
    radius_stderr_minsize="1M"
    radius_stderr_complevel="9"

%common
    radius_pidfile="@l_prefix@/var/radius/run/radiusd.pid"
    radius_signal () {
        [ -f $radius_pidfile ] && kill -$1 `cat $radius_pidfile`
    }

%status -u @l_susr@ -o
    radius_usable="unknown"
    radius_active="no"
    rcService radius enable yes && \
        radius_signal 0 && radius_active="yes"
    echo "radius_enable=\"$radius_enable\""
    echo "radius_usable=\"$radius_usable\""
    echo "radius_active=\"$radius_active\""

%start -u @l_susr@
    rcService radius enable yes || exit 0
    rcService radius active yes && exit 0
    @l_prefix@/sbin/radctl start

%stop -u @l_susr@
    rcService radius enable yes || exit 0
    rcService radius active no && exit 0
    @l_prefix@/sbin/radctl stop

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

%reload -u @l_susr@
    rcService radius enable yes || exit 0
    rcService radius active no  && exit 0
    @l_prefix@/sbin/radctl reload

%daily -u @l_susr@
    rcService radius enable yes || exit 0

    #   rotate logfiles
    rcTmp -i
    hintfile=`rcTmp -f -n hint`
    shtool rotate -f \
        -n ${radius_debug_numfiles} -s ${radius_debug_minsize} -d \
        -z ${radius_debug_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${radius_debug_prolog}" \
        -E "${radius_debug_epilog}; echo 1 >$hintfile" \
        ${radius_debug_file}
    shtool rotate -f \
        -n ${radius_info_numfiles} -s ${radius_info_minsize} -d \
        -z ${radius_info_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${radius_info_prolog}" \
        -E "${radius_info_epilog}; echo 1 >$hintfile" \
        ${radius_info_file}
    shtool rotate -f \
        -n ${radius_main_numfiles} -s ${radius_main_minsize} -d \
        -z ${radius_main_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${radius_main_prolog}" \
        -E "${radius_main_epilog}; echo 1 >$hintfile" \
        ${radius_main_file}
    shtool rotate -f \
        -n ${radius_stat_numfiles} -s ${radius_stat_minsize} -d \
        -z ${radius_stat_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${radius_stat_prolog}" \
        -E "${radius_stat_epilog}; echo 1 >$hintfile" \
        ${radius_stat_file}
    shtool rotate -f \
        -n ${radius_stderr_numfiles} -s ${radius_stderr_minsize} -d \
        -z ${radius_stderr_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${radius_stderr_prolog}" \
        -E "${radius_stderr_epilog}; echo 1 >$hintfile" \
        ${radius_stderr_file}
    if [ -s $hintfile ]; then
        rc radius restart
    fi
    rcTmp -k

