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

%config
    webmin_enable="$openpkg_rc_def"
    webmin_log_file="@l_prefix@/var/webmin/miniserv.log"
    webmin_log_prolog="true"
    webmin_log_epilog="true"
    webmin_log_numfiles="10"
    webmin_log_minsize="1M"
    webmin_log_complevel="9"
    webmin_err_file="@l_prefix@/var/webmin/miniserv.error"
    webmin_err_prolog="true"
    webmin_err_epilog="true"
    webmin_err_numfiles="10"
    webmin_err_minsize="1M"
    webmin_err_complevel="9"

%common
    webmin_pidfile="@l_prefix@/var/webmin/miniserv.pid"
    webmin_signal () {
        [ -f $webmin_pidfile ] && kill -$1 `cat $webmin_pidfile`
    }

%status -u @l_susr@ -o
    webmin_usable="unknown"
    webmin_active="no"
    rcService webmin enable yes && \
        webmin_signal 0 && webmin_active="yes"
    echo "webmin_enable=\"$webmin_enable\""
    echo "webmin_usable=\"$webmin_usable\""
    echo "webmin_active=\"$webmin_active\""

%start -u @l_susr@
    rcService webmin enable yes || exit 0
    rcService webmin active yes && exit 0
    PERLLIB=@l_prefix@/lib/webmin
    export PERLLIB
    exec '@l_prefix@/lib/webmin/miniserv.pl' @l_prefix@/etc/webmin/miniserv.conf

%stop -u @l_susr@
    rcService webmin enable yes || exit 0
    rcService webmin active no && exit 0
    webmin_signal TERM
    sleep 2
    rm -f $ucarp_pidfile 2>/dev/null || true

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

%daily -u @l_susr@
    rcService webmin enable yes || exit 0

    #   rotate logfiles
    rcTmp -i
    hintfile=`rcTmp -f -n hint`
    shtool rotate -f \
        -n ${webmin_log_numfiles} -s ${webmin_log_minsize} -d \
        -z ${webmin_log_complevel} -m 644 -o @l_musr@ -g @l_mgrp@ \
        -P "${webmin_log_prolog}" \
        -E "${webmin_log_epilog}; echo 1 >$hintfile" \
        ${webmin_log_file}
    shtool rotate -f \
        -n ${webmin_err_numfiles} -s ${webmin_err_minsize} -d \
        -z ${webmin_err_complevel} -m 644 -o @l_musr@ -g @l_mgrp@ \
        -P "${webmin_err_prolog}" \
        -E "${webmin_err_epilog}; echo 1 >$hintfile" \
        ${webmin_err_file}
    if [ -s $hintfile ]; then
        rc webmin restart
    fi
    rcTmp -k

