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

%config
    nexus_enable="$openpkg_rc_def"
    nexus_log_prolog="true"
    nexus_log_epilog="true"
    nexus_log_numfiles="10"
    nexus_log_minsize="1M"
    nexus_log_complevel="9"

%common
    nexus_pidfile="@l_prefix@/var/nexus/run/nexus.pid"
    nexus_logfile="@l_prefix@/var/nexus/log/nexus.log"
    nexus_signal () {
        [ -f $nexus_pidfile ] && kill -$1 `cat $nexus_pidfile`
    }

%status -u @l_rusr@ -o
    nexus_usable="unknown"
    nexus_active="no"
    rcService nexus enable yes && \
        nexus_signal 0 && nexus_active="yes"
    echo "nexus_enable=\"$nexus_enable\""
    echo "nexus_usable=\"$nexus_usable\""
    echo "nexus_active=\"$nexus_active\""

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

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

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

%daily -u @l_susr@
    rcService nexus enable yes || exit 0
    shtool rotate -f \
        -n ${nexus_log_numfiles} -s ${nexus_log_minsize} -d \
        -z ${nexus_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${nexus_log_prolog}" \
        -E "${nexus_log_epilog}; rc nexus restart" \
        $nexus_logfile

