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

%config
    cups_enable="$openpkg_rc_def"
    cups_access_file="@l_prefix@/var/cups/log/access_log"
    cups_access_prolog="true"
    cups_access_epilog="true"
    cups_access_numfiles="10"
    cups_access_minsize="1M"
    cups_access_complevel="9"
    cups_error_file="@l_prefix@/var/cups/log/error_log"
    cups_error_prolog="true"
    cups_error_epilog="true"
    cups_error_numfiles="10"
    cups_error_minsize="1M"
    cups_error_complevel="9"
    cups_page_file="@l_prefix@/var/cups/log/page_log"
    cups_page_prolog="true"
    cups_page_epilog="true"
    cups_page_numfiles="10"
    cups_page_minsize="1M"
    cups_page_complevel="9"

%common
    cups_pidfile="@l_prefix@/var/cups/cupsd.pid"
    cups_signal () {
        [ -f $cups_pidfile ] && kill -$1 `cat $cups_pidfile`
    }

%status -u @l_susr@ -o
    cups_usable="unknown"
    cups_active="no"
    rcService cups enable yes && \
        cups_signal 0 && cups_active="yes"
    echo "cups_enable=\"$cups_enable\""
    echo "cups_usable=\"$cups_usable\""
    echo "cups_active=\"$cups_active\""

%start -u @l_susr@
    rcService cups enable yes || exit 0
    rcService cups active yes && exit 0
    @l_prefix@/libexec/cups/cupsd

%stop -u @l_susr@
    rcService cups enable yes || exit 0
    rcService cups active no && exit 0
    cups_signal TERM
    rm -f $cups_pidfile 2>/dev/null || true

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

%daily -u @l_susr@
    rcService cups enable yes || exit 0
    shtool rotate -f \
        -n ${cups_access_numfiles} -s ${cups_access_minsize} -d \
        -z ${cups_access_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${cups_access_prolog}" \
        -E "${cups_access_epilog}; echo 1 >$hintfile" \
        ${cups_access_file}
    shtool rotate -f \
        -n ${cups_error_numfiles} -s ${cups_error_minsize} -d \
        -z ${cups_error_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${cups_error_prolog}" \
        -E "${cups_error_epilog}; echo 1 >$hintfile" \
        ${cups_error_file}
    shtool rotate -f \
        -n ${cups_page_numfiles} -s ${cups_page_minsize} -d \
        -z ${cups_page_complevel} -o @l_susr@ -g @l_mgrp@ -m 644 \
        -P "${cups_page_prolog}" \
        -E "${cups_page_epilog}; echo 1 >$hintfile" \
        ${cups_page_file}
    if [ -s $hintfile ]; then
        rc cups restart
    fi

