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

%config
    supervisord_enable="$openpkg_rc_def"
    supervisord_flags=""
    supervisord_log_prolog="true"
    supervisord_log_epilog="true"
    supervisord_log_numfiles="10"
    supervisord_log_minsize="1M"
    supervisord_log_complevel="9"

%common
    supervisord_cfgfile="@l_prefix@/etc/supervisord/supervisord.conf"
    supervisord_pidfile="@l_prefix@/var/supervisord/run/supervisord.pid"
    supervisord_logfile="@l_prefix@/var/supervisord/log/supervisord.log"
    supervisord_signal () {
        [ -f $supervisord_pidfile ] && kill -$1 `cat $supervisord_pidfile`
    }

%status -u @l_susr@ -o
    supervisord_usable="unknown"
    supervisord_active="no"
    rcService supervisord enable yes && \
        supervisord_signal 0 && supervisord_active="yes"
    echo "supervisord_enable=\"$supervisord_enable\""
    echo "supervisord_usable=\"$supervisord_usable\""
    echo "supervisord_active=\"$supervisord_active\""

%start -u @l_susr@
    rcService supervisord enable yes || exit 0
    rcService supervisord active yes && exit 0
    @l_prefix@/sbin/supervisord -d -c $supervisord_cfgfile

%stop -u @l_susr@
    rcService supervisord enable yes || exit 0
    rcService supervisord active no  && exit 0
    @l_prefix@/sbin/supervisord -c $supervisord_cfgfile ctl shutdown
    sleep 2
    supervisord_signal TERM
    sleep 2
    rm -f $supervisord_pidfile >/dev/null 2>&1 || true

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

%reload -u @l_susr@
    rcService supervisord enable yes || exit 0
    rcService supervisord active no  && exit 0
    @l_prefix@/sbin/supervisord -c $supervisord_cfgfile ctl reload

%daily -u @l_susr@
    rcService supervisord enable yes || exit 0
    shtool rotate -f \
        -n $supervisord_log_numfiles -s $supervisord_log_minsize -d \
        -z $supervisord_log_complevel -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "$supervisord_log_prolog" \
        -E "$supervisord_log_epilog; rc supervisord reload" \
        $supervisord_logfile

