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

%config
    gerrit_enable="$openpkg_rc_def"
    gerrit_log_prolog="true"
    gerrit_log_epilog="true"
    gerrit_log_numfiles="10"
    gerrit_log_minsize="1M"
    gerrit_log_complevel="9"

%common
    gerrit_pidfile="@l_prefix@/var/gerrit/site/review/logs/gerrit.pid"
    gerrit_signal () {
        [ -f $gerrit_pidfile ] && kill -$1 `cat $gerrit_pidfile`
    }

%status -u @l_rusr@ -o
    gerrit_usable="unknown"
    gerrit_active="no"
    rcService gerrit enable yes && \
        gerrit_signal 0 && gerrit_active="yes"
    echo "gerrit_enable=\"$gerrit_enable\""
    echo "gerrit_usable=\"$gerrit_usable\""
    echo "gerrit_active=\"$gerrit_active\""

%start -u @l_rusr@
    rcService gerrit enable yes || exit 0
    rcService gerrit active yes && exit
    export START_STOP_DAEMON=0
    @l_prefix@/var/gerrit/site/review/bin/gerrit.sh start

%stop -u @l_rusr@
    rcService gerrit enable yes || exit 0
    rcService gerrit active no  && exit 0
    export START_STOP_DAEMON=0
    @l_prefix@/var/gerrit/site/review/bin/gerrit.sh stop
    gerrit_signal TERM
    sleep 2
    rm -f $gerrit_pidfile >/dev/null 2>&1 || true

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

