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

%config
    wso2am_enable="$openpkg_rc_def"

%common
    wso2am_homedir="@l_prefix@/libexec/wso2am"
    wso2am_pidfile="@l_prefix@/libexec/wso2am/wso2carbon.pid"
    wso2am_signal () {
        [ -f $wso2am_pidfile ] && kill -$1 `cat $wso2am_pidfile`
    }
    wso2am_start () {
        eval `JAVA_PLATFORM="sun-jdk" @l_prefix@/bin/java-toolkit -e`
        export CARBON_HOME="$wso2am_homedir"
        (   nohup $wso2am_homedir/bin/wso2server.sh start \
            </dev/null >/dev/null 2>&1 &
        ) >/dev/null 2>&1
    }
    wso2am_stop () {
        eval `JAVA_PLATFORM="sun-jdk" @l_prefix@/bin/java-toolkit -e`
        export CARBON_HOME="$wso2am_homedir"
        $wso2am_homedir/bin/wso2server.sh stop
        sleep 2
        wso2am_signal TERM
        sleep 2
        rm -f $wso2am_pidfile >/dev/null 2>&1 || true
    }

%status -u @l_rusr@ -o
    wso2am_usable="unknown"
    wso2am_active="no"
    rcService wso2am enable yes && \
        wso2am_signal 0 && wso2am_active="yes"
    echo "wso2am_enable=\"$wso2am_enable\""
    echo "wso2am_usable=\"$wso2am_usable\""
    echo "wso2am_active=\"$wso2am_active\""

%start -u @l_rusr@
    rcService wso2am enable yes || exit 0
    rcService wso2am active yes && exit 0
    wso2am_start

%stop -u @l_rusr@
    rcService wso2am enable yes || exit 0
    rcService wso2am active no  && exit 0
    wso2am_stop

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

