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

%config
    openfire_enable="$openpkg_rc_def"
    openfire_flags=""
    openfire_flags_jvm="-Xms512m -Xmx1024m"
    openfire_log_rotsteps="10"
    openfire_log_rotminsize="10M"
    openfire_log_rotcomplevel="9"
    openfire_log_rotprolog="true"
    openfire_log_rotepilog="true"

%common
    openfire_cfgfile="@l_prefix@/etc/openfire/openfire.xml"
    openfire_pidfile="@l_prefix@/var/openfire/run/openfire.pid"
    openfire_logfile="@l_prefix@/var/openfire/log/openfire.log"
    openfire_signal () {
        [ -f $openfire_pidfile ] && kill -$1 `cat $openfire_pidfile`
    }

%status -u @l_rusr@ -o
    openfire_usable="unknown"
    openfire_active="no"
    rcService openfire enable yes && \
        openfire_signal 0 && openfire_active="yes"
    echo "openfire_enable=\"$openfire_enable\""
    echo "openfire_usable=\"$openfire_usable\""
    echo "openfire_active=\"$openfire_active\""

%start -u @l_rusr@
    rcService openfire enable yes || exit 0
    rcService openfire active yes && exit 0
    OPENFIRE_HOME="@l_prefix@/lib/openfire"
    export OPENFIRE_HOME
    cmd="@l_prefix@/bin/java"
    cmd="$cmd $openfire_flags_jvm"
    cmd="$cmd -server"
    cmd="$cmd -DopenfireHome=$OPENFIRE_HOME"
    cmd="$cmd -Dopenfire.lib.dir=$OPENFIRE_HOME/lib"
    cp=""
    for jar in $OPENFIRE_HOME/lib/*.jar; do
        if [ ".$cp" != . ]; then cp="$cp:"; fi
        cp="$cp$jar"
    done
    cmd="$cmd -cp $cp"
    cmd="$cmd -jar $OPENFIRE_HOME/lib/startup.jar"
    cmd="$cmd $openfire_flags"
    ( eval `JAVA_PLATFORM="sun-jdk" @l_prefix@/bin/java-toolkit -e`
      cd @l_prefix@/var/openfire/run
      nohup $cmd </dev/null >>$openfire_logfile 2>&1 &
      echo $! >$openfire_pidfile
    ) >/dev/null 2>&1

%stop -u @l_rusr@
    rcService openfire enable yes || exit 0
    rcService openfire active no  && exit 0
    openfire_signal TERM
    sleep 2
    rm -f $openfire_pidfile >/dev/null 2>&1 || true

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

