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

%config
    spamassassin_enable="$openpkg_rc_def"
    spamassassin_bind="127.0.0.1"
    spamassassin_port="783"
    spamassassin_flags="-A 127. --local"
    spamassassin_stop_delay="2"
    spamassassin_log_prolog="true"
    spamassassin_log_epilog="true"
    spamassassin_log_numfiles="10"
    spamassassin_log_minsize="1M"
    spamassassin_log_complevel="9"

%common
    spamassassin_etcdir="@l_prefix@/etc/spamassassin"
    spamassassin_pidfile="@l_prefix@/var/spamassassin/spamassassin.pid"
    spamassassin_logfile="@l_prefix@/var/spamassassin/spamassassin.log"
    spamassassin_signal () {
        [ -f $spamassassin_pidfile ] && kill -$1 `cat $spamassassin_pidfile`
    }

%status -u @l_susr@ -o
    spamassassin_usable="unknown"
    spamassassin_active="no"
    rcService spamassassin enable yes && \
        spamassassin_signal 0 && spamassassin_active="yes"
    echo "spamassassin_enable=\"$spamassassin_enable\""
    echo "spamassassin_usable=\"$spamassassin_usable\""
    echo "spamassassin_active=\"$spamassassin_active\""

%start -p 400 -u @l_susr@
    rcService spamassassin enable yes || exit 0
    rcService spamassassin active yes && exit 0
    @l_prefix@/bin/spamd \
        --daemonize \
        --siteconfigpath="${spamassassin_etcdir}" \
        --pidfile="${spamassassin_pidfile}" \
        --syslog="${spamassassin_logfile}" \
        --listen-ip="${spamassassin_bind}" \
        --port="${spamassassin_port}" \
        ${spamassassin_flags}

%stop -p 400 -u @l_susr@
    rcService spamassassin enable yes || exit 0
    rcService spamassassin active no && exit 0
    spamassassin_signal TERM
    sleep "$spamassassin_stop_delay"

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

%daily -u @l_susr@
    rcService spamassassin enable yes || exit 0
    su - @l_rusr@ -c "@l_prefix@/bin/sa-update"
    shtool rotate -f \
        -n ${spamassassin_log_numfiles} -s ${spamassassin_log_minsize} -d \
        -z ${spamassassin_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${spamassassin_log_prolog}" \
        -E "${spamassassin_log_epilog}" \
        $spamassassin_logfile
    rc spamassassin restart

