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

%config
    ircd_enable="$openpkg_rc_def"
    ircd_log_prolog="true"
    ircd_log_epilog="true"
    ircd_log_numfiles="10"
    ircd_log_minsize="1M"
    ircd_log_complevel="9"

%common
    ircd_pidfile="@l_prefix@/var/ircd/ircd.pid"
    ircd_signal () {
        [ -f $ircd_pidfile ] && kill -$1 `cat $ircd_pidfile`
    }

%status -u @l_rusr@ -o
    ircd_usable="unknown"
    ircd_active="no"
    rcService ircd enable yes && \
        ircd_signal 0 && ircd_active="yes"
    echo "ircd_enable=\"$ircd_enable\""
    echo "ircd_usable=\"$ircd_usable\""
    echo "ircd_active=\"$ircd_active\""

%start -u @l_rusr@
    rcService ircd enable yes || exit 0
    rcService ircd active yes && exit 0
    @l_prefix@/sbin/ircd -c

%stop -u @l_rusr@
    rcService ircd enable yes || exit 0
    rcService ircd active no  && exit 0
    ircd_signal TERM
    sleep 2
    rm -f $ircd_pidfile 2>/dev/null || true

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

%reload -u @l_rusr@
    rcService ircd enable yes || exit 0
    rcService ircd active no  && exit 0
    ircd_signal HUP

%daily -u @l_rusr@
    rcService ircd enable yes || exit 0
    shtool rotate -f \
        -n ${ircd_log_numfiles} -s ${ircd_log_minsize} -d \
        -z ${ircd_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${ircd_log_prolog}" \
        -E "${ircd_log_epilog}; rc ircd restart" \
        @l_prefix@/var/ircd/ircd.log

