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

%config
    webdav_enable="$openpkg_rc_def"
    webdav_flags=""
    webdav_log_prolog="true"
    webdav_log_epilog="true"
    webdav_log_numfiles="10"
    webdav_log_minsize="1M"
    webdav_log_complevel="9"

%common
    webdav_cfgfile="@l_prefix@/etc/webdav/webdav.yaml"
    webdav_pidfile="@l_prefix@/var/webdav/run/webdav.pid"
    webdav_logfile="@l_prefix@/var/webdav/log/webdav.log"
    webdav_signal () {
        [ -f $webdav_pidfile ] && kill -$1 `cat $webdav_pidfile`
    }

%status -u @l_rusr@ -o
    webdav_usable="unknown"
    webdav_active="no"
    rcService webdav enable yes && \
        webdav_signal 0 && webdav_active="yes"
    echo "webdav_enable=\"$webdav_enable\""
    echo "webdav_usable=\"$webdav_usable\""
    echo "webdav_active=\"$webdav_active\""

%start -u @l_rusr@
    rcService webdav enable yes || exit 0
    rcService webdav active yes && exit 0
    (   GOMAXPROCS=32
        export GOMAXPROCS
        nohup @l_prefix@/sbin/webdav \
            --config $webdav_cfgfile \
            </dev/null >>$webdav_logfile 2>&1 &
        echo $! >$webdav_pidfile
    ) >/dev/null 2>&1

%stop -u @l_rusr@
    rcService webdav enable yes || exit 0
    rcService webdav active no  && exit 0
    webdav_signal TERM
    sleep 2
    rm -f $webdav_pidfile >/dev/null 2>&1 || true

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

%daily -u @l_rusr@
    rcService webdav enable yes || exit 0
    shtool rotate -f \
        -n ${webdav_log_numfiles} -s ${webdav_log_minsize} -d \
        -z ${webdav_log_complevel} -m 664 -o @l_rusr@ -g @l_rgrp@ \
        -P "${webdav_log_prolog}" \
        -E "${webdav_log_epilog}; rc webdav restart" \
        $webdav_logfile

