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

%config
    shellinabox_enable="$openpkg_rc_def"
    shellinabox_flags="--localhost-only --port=4200 --disable-ssl --service=/:SSH:localhost"
    shellinabox_log_prolog="true"
    shellinabox_log_epilog="true"
    shellinabox_log_numfiles="10"
    shellinabox_log_minsize="1M"
    shellinabox_log_complevel="9"

%common
    shellinabox_pidfile="@l_prefix@/var/shellinabox/shellinabox.pid"
    shellinabox_logfile="@l_prefix@/var/shellinabox/shellinabox.log"
    shellinabox_signal () {
        [ -f $shellinabox_pidfile ] && kill -$1 `cat $shellinabox_pidfile`
    }

%status -u @l_susr@ -o
    shellinabox_usable="unknown"
    shellinabox_active="no"
    rcService shellinabox enable yes && \
        shellinabox_signal 0 && shellinabox_active="yes"
    echo "shellinabox_enable=\"$shellinabox_enable\""
    echo "shellinabox_usable=\"$shellinabox_usable\""
    echo "shellinabox_active=\"$shellinabox_active\""

%start -u @l_susr@
    rcService shellinabox enable yes || exit 0
    rcService shellinabox active yes && exit 0
    cmd="@l_prefix@/bin/shellinaboxd"
    cmd="$cmd --verbose"
    cmd="$cmd --user=@l_nusr@ --group=@l_ngrp@"
    cmd="$cmd --background --pidfile=$shellinabox_pidfile"
    cmd="$cmd ${shellinabox_flags}"
    cmd="$cmd >$shellinabox_logfile 2>&1 </dev/null"
    eval "$cmd"

%stop -u @l_susr@
    rcService shellinabox enable yes || exit 0
    rcService shellinabox active no  && exit 0
    shellinabox_signal TERM
    sleep 2

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

%daily -u @l_susr@
    rcService shellinabox enable yes || exit 0
    shtool rotate -f \
        -n ${shellinabox_log_numfiles} -s ${shellinabox_log_minsize} -d \
        -z ${shellinabox_log_complevel} -m 644 -o @l_nusr@ -g @l_ngrp@ \
        -P "${shellinabox_log_prolog}" \
        -E "${shellinabox_log_epilog}; rc shellinabox restart" \
        $shellinabox_logfile

