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

%config
    joomla_enable="$openpkg_rc_def"

%common
    joomla_cfgfile="@l_prefix@/etc/joomla/joomla-apache.conf"
    joomla_pidfile="@l_prefix@/var/joomla/run/apache.pid"
    joomla_signal () {
        [ -f $joomla_pidfile ] && kill -$1 `cat $joomla_pidfile`
    }

%status -u @l_susr@ -o
    joomla_usable="no"
    joomla_active="no"
    @l_prefix@/sbin/apache -t -f $joomla_cfgfile 2>/dev/null && \
        joomla_usable="yes"
    joomla_signal 0 && \
        joomla_active="yes"
    echo "joomla_enable=\"$joomla_enable\""
    echo "joomla_usable=\"$joomla_usable\""
    echo "joomla_active=\"$joomla_active\""

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

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

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

