#!@l_prefix@/lib/openpkg/bash @l_prefix@/etc/rc
##
##  rc.openssh -- Run-Commands for OpenSSH Daemon
##

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

%common
    openssh_signal () {
        if [ -f "@l_prefix@/var/openssh/sshd.pid" ]; then
            kill -$1 `cat @l_prefix@/var/openssh/sshd.pid`
        fi
    }

%start -p 200 -u root
    opServiceEnabled openssh || exit 0
    @l_prefix@/bin/sshd

%stop -p 200 -u root
    opServiceEnabled openssh || exit 0
    openssh_signal TERM

%restart -u root
    opServiceEnabled openssh || exit 0
    openssh_signal TERM
    sleep 2
    @l_prefix@/bin/sshd

%daily -u root
    opServiceEnabled openssh || exit 0
    opTmpDirGen openssh
    opTmpDirFile openssh hint hintfile
    prolog="true"
    if [ ".$openssh_log_prolog" != . ]; then
        prolog="$prolog; $openssh_log_prolog"
    fi
    epilog="echo 'epilog' >$hintfile"
    if [ ".$openssh_log_epilog" != . ]; then
        epilog="$epilog; $openssh_log_epilog"
    fi
    shtool rotate -f \
        -n${openssh_log_numfiles} -s${openssh_log_minsize} \
        -d -z${openssh_log_complevel} \
        -o@l_musr@ -g@l_mgrp@ -m644 \
        -P "$prolog" \
        -E "$epilog" \
        @l_prefix@/var/openssh/sshd.log
    if [ ".`cat $hintfile`" = ".epilog" ]; then
        openssh_signal TERM
        sleep 2
        @l_prefix@/bin/sshd
    fi
    opTmpDirDel openssh

