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

%config
    sasl_enable="$openpkg_rc_def"
    sasl_flags=""
    sasl_authmech="@l_authmech@"
    sasl_threads="4"
    sasl_log_prolog="true"
    sasl_log_epilog="true"
    sasl_log_numfiles="10"
    sasl_log_minsize="1M"
    sasl_log_complevel="9"

%common
    sasl_pidfile="@l_prefix@/var/sasl/run/saslauthd/saslauthd.pid"
    sasl_signal () {
        [ -f $sasl_pidfile ] && kill -$1 `cat $sasl_pidfile`
    }

%status -u @l_susr@ -o
    sasl_usable="unknown"
    sasl_active="no"
    rcService sasl enable yes && \
        sasl_signal 0 && sasl_active="yes"
    echo "sasl_enable=\"$sasl_enable\""
    echo "sasl_usable=\"$sasl_usable\""
    echo "sasl_active=\"$sasl_active\""

%start -p 400 -u @l_susr@
    rcService sasl enable yes || exit 0
    rcService sasl active yes && exit 0
    @l_prefix@/sbin/saslauthd \
        -a "${sasl_authmech}" \
        -n "${sasl_threads}" \
        ${sasl_flags}

%stop -p 600 -u @l_susr@
    rcService sasl enable yes || exit 0
    rcService sasl active no && exit 0
    sasl_signal TERM

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

%daily -u @l_susr@
    rcService sasl enable yes || exit 0
    shtool rotate -f \
        -n ${sasl_log_numfiles} -s ${sasl_log_minsize} -d \
        -z ${sasl_log_complevel} -o @l_susr@ -g @l_sgrp@ -m 600 \
        -P "${sasl_log_prolog}" \
        -E "${sasl_log_epilog}; rc sasl restart" \
        @l_prefix@/var/sasl/log/saslauthd.log

