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

%config
    arangodb_enable="$openpkg_rc_def"
    arangodb_flags=""
    arangodb_log_prolog="true"
    arangodb_log_epilog="true"
    arangodb_log_numfiles="10"
    arangodb_log_minsize="1M"
    arangodb_log_complevel="9"

%common
    arangodb_cfgfile="@l_prefix@/etc/arangodb/arangodb.conf"
    arangodb_pidfile="@l_prefix@/var/arangodb/run/arangodb.pid"
    arangodb_logfile="@l_prefix@/var/arangodb/log/arangodb.log"
    arangodb_signal () {
        [ -f $arangodb_pidfile ] && kill -$1 `cat $arangodb_pidfile`
    }

%status -u @l_rusr@ -o
    arangodb_usable="unknown"
    arangodb_active="no"
    rcService arangodb enable yes && \
        arangodb_signal 0 && arangodb_active="yes"
    echo "arangodb_enable=\"$arangodb_enable\""
    echo "arangodb_usable=\"$arangodb_usable\""
    echo "arangodb_active=\"$arangodb_active\""

%start -u @l_rusr@
    rcService arangodb enable yes || exit 0
    rcService arangodb active yes && exit 0
    @l_prefix@/sbin/arangod ${arangodb_flags}

%stop -u @l_rusr@
    rcService arangodb enable yes || exit 0
    rcService arangodb active no  && exit 0
    arangodb_signal INT
    sleep 2
    arangodb_signal TERM
    sleep 1
    rm -f $arangodb_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_rusr@
    rcService arangodb enable yes || exit 0
    shtool rotate -f \
        -n ${arangodb_log_numfiles} -s ${arangodb_log_minsize} -d \
        -z ${arangodb_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${arangodb_log_prolog}" \
        -E "${arangodb_log_epilog}; rc arangodb restart" \
        $arangodb_logfile

