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

%config
    sslh_enable="$openpkg_rc_def"
    sslh_bind="127.0.0.1:443"
    sslh_connect_ssl="127.0.0.1:442"
    sslh_connect_ssh="127.0.0.1:22"
    sslh_timeout="2"
    sslh_log_prolog="true"
    sslh_log_epilog="true"
    sslh_log_numfiles="10"
    sslh_log_minsize="1M"
    sslh_log_complevel="9"

%common
    sslh_pidfile="@l_prefix@/var/sslh/sslh.pid"
    sslh_logfile="@l_prefix@/var/sslh/sslh.log"
    sslh_signal () {
        [ -f $sslh_pidfile ] && kill -$1 `cat $sslh_pidfile`
    }

%status -u @l_susr@ -o
    sslh_usable="unknown"
    sslh_active="no"
    rcService sslh enable yes && \
        sslh_signal 0 && sslh_active="yes"
    echo "sslh_enable=\"$sslh_enable\""
    echo "sslh_usable=\"$sslh_usable\""
    echo "sslh_active=\"$sslh_active\""

%start -u @l_susr@
    rcService sslh enable yes || exit 0
    rcService sslh active yes && exit 0
    @l_prefix@/sbin/sslh \
        -t "$sslh_timeout" \
        -p "$sslh_bind" \
        -l "$sslh_connect_ssl" \
        -s "$sslh_connect_ssh" \
        -u "@l_nusr@" \
        -P "$sslh_pidfile"

%stop -u @l_susr@
    rcService sslh enable yes || exit 0
    rcService sslh active no  && exit 0
    sslh_signal TERM
    sleep 2
    rm -f $sslh_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_susr@
    rcService sslh enable yes || exit 0
    shtool rotate -f \
        -n ${sslh_log_numfiles} -s ${sslh_log_minsize} -d \
        -z ${sslh_log_complevel} -m 664 -o @l_susr@ -g @l_mgrp@ \
        -P "${sslh_log_prolog}" \
        -E "${sslh_log_epilog}; rc sslh restart" \
        $sslh_logfile

