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

%config
    squid_enable="$openpkg_rc_def"
    squid_log_prolog="true"
    squid_log_epilog="true"
    squid_log_numfiles="10"
    squid_log_minsize="1M"
    squid_log_complevel="9"

%status -u @l_susr@ -o
    squid_usable="unknown"
    squid_active="no"
    rcService squid enable yes && \
        @l_prefix@/sbin/squid -k check 2>/dev/null && squid_active="yes"
    echo "squid_enable=\"$squid_enable\""
    echo "squid_usable=\"$squid_usable\""
    echo "squid_active=\"$squid_active\""

%start -u @l_susr@
    rcService squid enable yes || exit 0
    rcService squid active yes && exit 0
    @l_prefix@/sbin/squid -s
    sleep 2

%stop -u @l_susr@
    rcService squid enable yes || exit 0
    rcService squid active no  && exit 0
    @l_prefix@/sbin/squid -k shutdown
    i=0
    while [ $i -lt 40 ]; do
        @l_prefix@/sbin/squid -k check 2>/dev/null
        if [ $? -ne 0 ]; then
            break
        fi
        sleep 1
        i=`expr $i + 1`
    done

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

%reload -u @l_susr@
    rcService squid enable yes || exit 0
    @l_prefix@/sbin/squid -k reconfigure

%daily -u @l_susr@
    rcService squid enable yes || exit 0
    @l_prefix@/sbin/squid -k rotate
    shtool rotate -f \
        -n ${squid_log_numfiles} -s ${squid_log_minsize} -d \
        -z ${squid_log_complevel} -m 644 -o @l_susr@ -g @l_mgrp@ \
        -P "${squid_log_prolog}" \
        -E "${squid_log_epilog}; rc squid reload" \
        @l_prefix@/var/squid/log/squid.log

