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

%config
    skyapi_enable="$openpkg_rc_def"
    skyapi_flags=""
    skyapi_log_prolog="true"
    skyapi_log_epilog="true"
    skyapi_log_numfiles="10"
    skyapi_log_minsize="1M"
    skyapi_log_complevel="9"

%common
    skyapi_cfgfile="@l_prefix@/etc/skyapi/skyapi.cfg"
    skyapi_pidfile="@l_prefix@/var/skyapi/run/skyapi.pid"
    skyapi_logfile="@l_prefix@/var/skyapi/log/skyapi.log"
    skyapi_signal () {
        [ -f $skyapi_pidfile ] && kill -$1 `cat $skyapi_pidfile`
    }

%status -u @l_nusr@ -o
    skyapi_usable="unknown"
    skyapi_active="no"
    rcService skyapi enable yes && \
        skyapi_signal 0 && skyapi_active="yes"
    echo "skyapi_enable=\"$skyapi_enable\""
    echo "skyapi_usable=\"$skyapi_usable\""
    echo "skyapi_active=\"$skyapi_active\""

%start -u @l_nusr@
    rcService skyapi enable yes || exit 0
    rcService skyapi active yes && exit 0
    (   nohup @l_prefix@/sbin/skyapi \
           --config="$skyapi_cfgfile" \
           $skyapi_flags \
        </dev/null >>$skyapi_logfile 2>&1 &
        echo $! >$skyapi_pidfile
    ) >/dev/null 2>&1

%stop -u @l_nusr@
    rcService skyapi enable yes || exit 0
    rcService skyapi active no  && exit 0
    skyapi_signal TERM
    sleep 2
    rm -f $skyapi_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService skyapi enable yes || exit 0
    shtool rotate -f \
        -n ${skyapi_log_numfiles} -s ${skyapi_log_minsize} -d \
        -z ${skyapi_log_complevel} -m 664 -o @l_nusr@ -g @l_ngrp@ \
        -P "${skyapi_log_prolog}" \
        -E "${skyapi_log_epilog}; rc skyapi restart" \
        $skyapi_logfile

