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

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

%common
    supervisord_pidfile="@l_prefix@/var/supervisord/supervisord.pid"
    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@/bin/supervisord

%stop -u @l_susr@
    rcService supervisord enable yes || exit 0
    rcService supervisord active no  && exit 0
    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
    supervisord_signal USR2

