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

%config
    orientdb_enable="$openpkg_rc_def"
    orientdb_log_prolog="true"
    orientdb_log_epilog="true"
    orientdb_log_numfiles="10"
    orientdb_log_minsize="1M"
    orientdb_log_complevel="9"

%common
    orientdb_pidfile="@l_prefix@/var/orientdb/run/orientdb.pid"
    orientdb_logfile="@l_prefix@/var/orientdb/log/orientdb.log"
    orientdb_signal () {
        [ -f $orientdb_pidfile ] && kill -$1 `cat $orientdb_pidfile`
    }

%status -u @l_rusr@ -o
    orientdb_usable="unknown"
    orientdb_active="no"
    rcService orientdb enable yes && \
        orientdb_signal 0 && orientdb_active="yes"
    echo "orientdb_enable=\"$orientdb_enable\""
    echo "orientdb_usable=\"$orientdb_usable\""
    echo "orientdb_active=\"$orientdb_active\""

%start -u @l_rusr@
    rcService orientdb enable yes || exit 0
    rcService orientdb active yes && exit 0
    ( eval "nohup @l_prefix@/bin/orientdb-server </dev/null >/dev/null 2>&1 &"
      echo $! >$orientdb_pidfile
    ) >/dev/null 2>&1

%stop -u @l_rusr@
    rcService orientdb enable yes || exit 0
    rcService orientdb active no && exit 0
    orientdb_signal TERM
    sleep 2
    rm -f $orientdb_pidfile 2>/dev/null || true

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

%daily -u @l_rusr@
    rcService orientdb enable yes || exit 0
    shtool rotate -f \
        -n $orientdb_log_numfiles -s $orientdb_log_minsize -d \
        -z $orientdb_log_complevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$orientdb_log_prolog" \
        -E "$orientdb_log_epilog; rc orientdb restart" \
        $orientdb_logfile

