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

%config
    jira_enable="$openpkg_rc_def"
    jira_flags="-server -Xss2M -Xmn256M -Xms512M -Xmx1024M"
    jira_home="@l_prefix@/libexec/jira"
    jira_log_prolog="true"
    jira_log_epilog="true"
    jira_log_numfiles="10"
    jira_log_minsize="1M"
    jira_log_complevel="9"

%common
    jira_pidfile="@l_prefix@/var/jira/run/jira.pid"
    jira_logfile="@l_prefix@/var/jira/log/jira.log"
    jira_datadir="@l_prefix@/var/jira/data"
    jira_signal () {
        [ -f $jira_pidfile ] && kill -$1 `cat $jira_pidfile`
    }

%status -u @l_rusr@ -o
    jira_usable="unknown"
    jira_active="no"
    rcService jira enable yes && \
        jira_signal 0 && jira_active="yes"
    echo "jira_enable=\"$jira_enable\""
    echo "jira_usable=\"$jira_usable\""
    echo "jira_active=\"$jira_active\""

%start -u @l_rusr@
    rcService jira enable yes || exit 0
    rcService jira active yes && exit 0
    eval `JAVA_PLATFORM="sun-jdk" @l_prefix@/bin/java-toolkit -e`
    JIRA_HOME="$jira_datadir"; export JIRA_HOME
    CATALINA_HOME="$jira_home"; export CATALINA_HOME
    CATALINA_PID="$jira_pidfile"; export CATALINA_PID
    CATALINA_OUT="$jira_logfile"; export CATALINA_OUT
    CATALINA_OPTS="$jira_flags"; export CATALINA_OPTS
    (cd $CATALINA_HOME && $CATALINA_HOME/bin/catalina.sh start)

%stop -u @l_rusr@
    rcService jira enable yes || exit 0
    rcService jira active no && exit 0
    eval `JAVA_PLATFORM="sun-jdk" @l_prefix@/bin/java-toolkit -e`
    JIRA_HOME="$jira_datadir"; export JIRA_HOME
    CATALINA_HOME="$jira_home"; export CATALINA_HOME
    CATALINA_PID="$jira_pidfile"; export CATALINA_PID
    CATALINA_OUT="$jira_logfile"; export CATALINA_OUT
    CATALINA_OPTS="$jira_flags"; export CATALINA_OPTS
    (cd $CATALINA_HOME && $CATALINA_HOME/bin/catalina.sh stop 20 -force)
    rm -f $jira_pidfile 2>/dev/null || true

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

%daily -u @l_rusr@
    rcService jira enable yes || exit 0
    shtool rotate -f \
        -n ${jira_log_numfiles} -s ${jira_log_minsize} -d \
        -z ${jira_log_complevel} -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "${jira_log_prolog}" \
        -E "${jira_log_epilog}; rc jira restart" \
        @l_prefix@/var/jira/log/catalina.out

