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

%config
    thttpd_enable="$openpkg_rc_def"
    thttpd_flags=""
    thttpd_log_prolog="true"
    thttpd_log_epilog="true"
    thttpd_log_numfiles="10"
    thttpd_log_minsize="1M"
    thttpd_log_complevel="9"

%common
    thttpd_cfgfile="@l_prefix@/etc/thttpd/thttpd.conf"
    thttpd_pidfile="@l_prefix@/var/thttpd/thttpd.pid"
    thttpd_signal () {
        [ -f $thttpd_pidfile ] && kill -$1 `cat $thttpd_pidfile`
    }

%status -u @l_susr@ -o
    thttpd_usable="no"
    thttpd_active="no"
    rcService thttpd enable yes && \
        thttpd_signal 0 && thttpd_active="yes"
    echo "thttpd_enable=\"$thttpd_enable\""
    echo "thttpd_usable=\"$thttpd_usable\""
    echo "thttpd_active=\"$thttpd_active\""

%start -u @l_susr@
    rcService thttpd enable yes || exit 0
    rcService thttpd active yes && exit 0
    @l_prefix@/sbin/thttpd -C ${thttpd_cfgfile} ${thttpd_flags}

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

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

%reload -u @l_susr@
    rcService thttpd enable yes || exit 0
    rcService thttpd active no  && exit 0
    thttpd_signal HUP

%daily -u @l_susr@
    rcService thttpd enable yes || exit 0
    shtool rotate -f \
        -n ${thttpd_log_numfiles} -s ${thttpd_log_minsize} -d \
        -z ${thttpd_log_complevel} -m 644 -o @l_rusr@ -g @l_rgrp@ \
        -P "${thttpd_log_prolog}" \
        -E "${thttpd_log_epilog} && rc thttpd reload" \
        @l_prefix@/var/thttpd/thttpd.log

