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

%config
    youtrack_enable="$openpkg_rc_def"

%common
    youtrack_cli () {
        ( cd @l_prefix@/lib/youtrack || exit $?
          eval `JAVA_PLATFORM="sun-jdk" @l_prefix@/bin/java-toolkit -e`
          JIRA_HOME="$youtrack_datadir"; export JIRA_HOME
          ./bin/youtrack.sh "$@"
        ) || exit $?
    }

%status -u @l_rusr@ -o
    youtrack_usable="unknown"
    youtrack_active="no"
    if rcService youtrack enable; then
        if [ ".`youtrack_cli status | grep 'YouTrack is running'`" != . ]; then
            youtrack_active="yes"
        fi
    fi
    echo "youtrack_enable=\"$youtrack_enable\""
    echo "youtrack_usable=\"$youtrack_usable\""
    echo "youtrack_active=\"$youtrack_active\""

%start -u @l_rusr@
    rcService youtrack enable yes || exit 0
    rcService youtrack active yes && exit 0
    youtrack_cli start

%stop -u @l_rusr@
    rcService youtrack enable yes || exit 0
    rcService youtrack active no && exit 0
    youtrack_cli stop

%restart -u @l_rusr@
    rcService youtrack enable yes || exit 0
    rcService youtrack active no && exit 0
    youtrack_cli restart

