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

%config
    opensearch_enable="$openpkg_rc_def"
    opensearch_flags="-server"
    opensearch_minmem="512m"
    opensearch_maxmem="512m"
    opensearch_log_prolog="true"
    opensearch_log_epilog="true"
    opensearch_log_numfiles="10"
    opensearch_log_minsize="1M"
    opensearch_log_complevel="9"

%common
    opensearch_pidfile="@l_prefix@/var/opensearch/run/opensearch.pid"
    opensearch_signal () {
        [ -f $opensearch_pidfile ] && kill -$1 `cat $opensearch_pidfile`
    }

%status -u @l_rusr@ -o
    opensearch_usable="unknown"
    opensearch_active="no"
    rcService opensearch enable yes && \
        opensearch_signal 0 && opensearch_active="yes"
    echo "opensearch_enable=\"$opensearch_enable\""
    echo "opensearch_usable=\"$opensearch_usable\""
    echo "opensearch_active=\"$opensearch_active\""

%start -u @l_rusr@
    rcService opensearch enable yes || exit 0
    rcService opensearch active yes && exit 0
    export ES_JAVA_OPTS="-Xms$opensearch_minmem -Xmx$opensearch_maxmem $opensearch_flags"
    @l_prefix@/bin/opensearch --daemonize -p $opensearch_pidfile

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

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

