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

%config
    neo4j_enable="$openpkg_rc_def"
    neo4j_flags=""
    neo4j_log_prolog="true"
    neo4j_log_epilog="true"
    neo4j_log_numfiles="10"
    neo4j_log_minsize="1M"
    neo4j_log_complevel="9"

%common
    neo4j_pidfile="@l_prefix@/var/neo4j/run/neo4j.pid"
    neo4j_logfile="@l_prefix@/var/neo4j/log/neo4j.log"
    neo4j_signal () {
        [ -f $neo4j_pidfile ] && kill -$1 `cat $neo4j_pidfile`
    }

%status -u @l_rusr@ -o
    neo4j_usable="unknown"
    neo4j_active="no"
    rcService neo4j enable yes && \
        neo4j_signal 0 && neo4j_active="yes"
    echo "neo4j_enable=\"$neo4j_enable\""
    echo "neo4j_usable=\"$neo4j_usable\""
    echo "neo4j_active=\"$neo4j_active\""

%start -u @l_rusr@
    rcService neo4j enable yes || exit 0
    rcService neo4j active yes && exit 0
    ( nohup @l_prefix@/bin/neo4j-server $neo4j_flags </dev/null >$neo4j_logfile 2>&1 &
      echo $! >$neo4j_pidfile
    ) >/dev/null 2>&1

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

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

%daily -u @l_rusr@
    rcService neo4j enable yes || exit 0
    shtool rotate -f \
        -n $neo4j_log_numfiles -s $neo4j_log_minsize -d \
        -z $neo4j_log_complevel -o @l_rusr@ -g @l_rgrp@ -m 644 \
        -P "$neo4j_log_prolog" \
        -E "$neo4j_log_epilog; rc neo4j restart" \
        $neo4j_logfile

