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

%config
    phpbb_enable="$openpkg_rc_def"

%common
    phpbb_cfgfile="@l_prefix@/etc/phpbb/phpbb-apache.conf"
    phpbb_pidfile="@l_prefix@/var/phpbb/run/apache.pid"
    phpbb_signal () {
        [ -f $phpbb_pidfile ] && kill -$1 `cat $phpbb_pidfile`
    }

%status -u @l_susr@ -o
    phpbb_usable="no"
    phpbb_active="no"
    @l_prefix@/sbin/apache -t -f $phpbb_cfgfile 2>/dev/null && \
        phpbb_usable="yes"
    phpbb_signal 0 && \
        phpbb_active="yes"
    echo "phpbb_enable=\"$phpbb_enable\""
    echo "phpbb_usable=\"$phpbb_usable\""
    echo "phpbb_active=\"$phpbb_active\""

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

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

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

