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

%config
    punbb_enable="$openpkg_rc_def"

%common
    punbb_cfgfile="@l_prefix@/etc/punbb/punbb-apache.conf"
    punbb_pidfile="@l_prefix@/var/punbb/run/apache.pid"
    punbb_signal () {
        [ -f $punbb_pidfile ] && kill -$1 `cat $punbb_pidfile`
    }

%status -u @l_susr@ -o
    punbb_usable="no"
    punbb_active="no"
    @l_prefix@/sbin/apache -t -f $punbb_cfgfile 2>/dev/null && \
        punbb_usable="yes"
    punbb_signal 0 && \
        punbb_active="yes"
    echo "punbb_enable=\"$punbb_enable\""
    echo "punbb_usable=\"$punbb_usable\""
    echo "punbb_active=\"$punbb_active\""

%start -u @l_susr@
    rcService punbb enable yes || exit 0
    rcService punbb active yes && exit 0
    ( export PATH="@l_path@"
      @l_prefix@/sbin/apache -f $punbb_cfgfile
    ) || exit $?

%stop -u @l_susr@
    rcService punbb enable yes || exit 0
    rcService punbb active no  && exit 0
    punbb_signal TERM
    sleep 2
    rm -f $punbb_pidfile >/dev/null 2>&1 || true

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

