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

%config
    lsh_enable="$openpkg_rc_def"
    lsh_log_prolog="true"
    lsh_log_epilog="true"
    lsh_log_numfiles="10"
    lsh_log_minsize="1M"
    lsh_log_complevel="9"

%common
    lsh_cfgfile="@l_prefix@/etc/lsh/lsh.cfg"
    lsh_logfile="@l_prefix@/var/lsh/lsh.log"
    lsh_pidfile="@l_prefix@/var/lsh/lsh.pid"
    lsh_signal () {
        [ -f $lsh_pidfile ] && kill -$1 `cat $lsh_pidfile`
    }

%status -u @l_susr@ -o
    lsh_usable="unknown"
    lsh_active="no"
    rcService lsh enable yes && \
        lsh_signal 0 && lsh_active="yes"
    echo "lsh_enable=\"$lsh_enable\""
    echo "lsh_usable=\"$lsh_usable\""
    echo "lsh_active=\"$lsh_active\""

%start -u @l_susr@
    rcService lsh enable yes || exit 0
    rcService lsh active yes && exit 0
    @l_prefix@/bin/lsh-make-seed \
        --server --sloppy --quiet || true
    @l_prefix@/sbin/lshd \
        --daemonic \
        --pid-file=$lsh_pidfile \
        --log-file=$lsh_logfile \
        --host-key=@l_prefix@/etc/lsh/lsh.key \
        --subsystems=sftp=@l_prefix@/sbin/lsh-sftp-server \
        `sed -e '/^#.*/d' <$lsh_cfgfile`

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

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

%daily -u @l_susr@
    rcService lsh enable yes || exit 0
    shtool rotate -f \
        -n ${lsh_log_numfiles} -s ${lsh_log_minsize} -d \
        -z ${lsh_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${lsh_log_prolog}" \
        -E "${lsh_log_epilog}; rc lsh restart" \
        $lsh_logfile

