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

%config
    openssh_enable="$openpkg_rc_def"
    openssh_log_prolog="true"
    openssh_log_epilog="true"
    openssh_log_numfiles="10"
    openssh_log_minsize="1M"
    openssh_log_complevel="9"

%common
    openssh_pidfile="@l_prefix@/var/openssh/run/openssh.pid"
    openssh_signal () {
        [ -f $openssh_pidfile ] && kill -$1 `cat $openssh_pidfile`
    }

%status -u @l_susr@ -o
    openssh_usable="unknown"
    openssh_active="no"
    rcService openssh enable yes && \
        openssh_signal 0 && openssh_active="yes"
    echo "openssh_enable=\"$openssh_enable\""
    echo "openssh_usable=\"$openssh_usable\""
    echo "openssh_active=\"$openssh_active\""

%start -u @l_susr@
    rcService openssh enable yes || exit 0
    rcService openssh active yes && exit 0
    @l_prefix@/bin/sshd

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

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

%daily -u @l_susr@
    rcService openssh enable yes || exit 0
    shtool rotate -f \
        -n ${openssh_log_numfiles} -s ${openssh_log_minsize} -d \
        -z ${openssh_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${openssh_log_prolog}" \
        -E "${openssh_log_epilog}; rc openssh restart" \
        @l_prefix@/var/openssh/log/openssh.log

