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

%config
    ngircd_enable="$openpkg_rc_def"
    ngircd_log_prolog="true"
    ngircd_log_epilog="true"
    ngircd_log_numfiles="10"
    ngircd_log_minsize="1M"
    ngircd_log_complevel="9"

%common
    ngircd_pidfile="@l_prefix@/var/ngircd/run/ngircd.pid"
    ngircd_signal () {
        [ -f $ngircd_pidfile ] && kill -$1 `cat $ngircd_pidfile`
    }

%status -u @l_susr@ -o
    ngircd_usable="no"
    ngircd_active="no"
    @l_prefix@/sbin/ngircd -t >/dev/null 2>&1 && ngircd_usable="yes"
    rcService ngircd enable yes && \
        ngircd_signal 0 && ngircd_active="yes"
    echo "ngircd_enable=\"$ngircd_enable\""
    echo "ngircd_usable=\"$ngircd_usable\""
    echo "ngircd_active=\"$ngircd_active\""

%start -u @l_susr@
    rcService ngircd enable yes || exit 0
    @l_prefix@/sbin/ngircd --pidfile $ngircd_pidfile
    exit 0

%stop -u @l_susr@
    rcService ngircd enable yes || exit 0
    kill -TERM `cat $ngircd_pidfile`
    rm -f $ngircd_pidfile 2>/dev/null || true
    exit 0

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

%daily -u @l_susr@
    rcService ngircd enable yes || exit 0
    shtool rotate -f \
        -n ${ngircd_log_numfiles} -s ${ngircd_log_minsize} -d \
        -z ${ngircd_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${ngircd_log_prolog}" \
        -E "${ngircd_log_epilog}" \
        @l_prefix@/var/ngircd/log/ngircd.log

