Last update suggestions for (3.5.xx) initscript, awaiting feedback. ;-)
Changelog:
- Raised 'while'-loop-time for stopping squid to 360 seconds until '/var/log/cache/swap.state' is deleted. NOT the whole cache structure! I know, this timeout could not be enough for really BIG caches. The only other choice I know would be to leave this loop alone without the "xxx seconds"-counter and wait how 'squid -k shutdown' handles this. But if it fails, I fear that we could end up in an endless loop. Suggestions are welcome!
- Had to delete 'wait' after killing squidguard, updxlrator, squidclamav and redirect_wrappers - 'while'-loop counter wouldn't work because of this line. Suggestions for better handling?
- Process detection looks for leftover '(squid-1)'-process using 'pgrep'.
- Cosmetic changes to some 'boot_mesg' lines. Added a few. Is it (still) too much? I'd prefer to get a warning (an announcement) if '/var/log/cache/swap.state' was deleted.
- Changed the 'flush'-command to really delete the entire '/var/log/cache'-structure, it will automatically be rebuild during the next start. Reason: a CLEAR cache command should really CLEAR the cache!
Best, Matthias
Signed-off-by: Matthias Fischer matthias.fischer@ipfire.org --- src/initscripts/init.d/squid | 55 ++++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 20 deletions(-)
diff --git a/src/initscripts/init.d/squid b/src/initscripts/init.d/squid index abed90a..1b369ea 100644 --- a/src/initscripts/init.d/squid +++ b/src/initscripts/init.d/squid @@ -94,9 +94,9 @@ case "$1" in stop) iptables -t nat -F SQUID if [ -e /var/run/squid.pid ]; then - boot_mesg "Stopping Squid Proxy Server..." - squid -k shutdown >/dev/null 2>&1 - evaluate_retval + boot_mesg -n "Stopping Squid Proxy Server...\n" + boot_mesg "(this may take up to a few minutes)" + /usr/sbin/squid -k shutdown >/dev/null 2>&1
# Stop squidGuard, updxlrator, squidclamav # and redirect_wrappers. @@ -105,25 +105,41 @@ case "$1" in killproc /usr/bin/squidclamav >/dev/null & killproc /usr/sbin/redirect_wrapper >/dev/null &
- # Wait until all redirectors have been stopped. - wait - - # If squid is still running, wait up to 30 seconds - # before we go on to kill it. - counter=30 - - while [ ${counter} -gt 0 ]; do - statusproc /usr/sbin/squid >/dev/null && break; - sleep 1 - counter=$(( ${counter} - 1)) + # If some squid processes are still running, wait up to 360 seconds + # before we go on to kill the remaining process(es) and delete damaged + # '/var/log/cache/swap.state'. + n=0 + while squid -k check > /dev/null 2>&1 && [ $n -lt 360 ]; do + sleep 2 + n=$(( ${n} + 2 )) + echo -n . done - - # Kill squid service, if still running. - killproc /usr/sbin/squid >/dev/null + echo "" + echo "Done." + echo "Shutdown time:" "$n" "seconds" + + # If (squid-1) is still running after 360 seconds, + # kill all squid processes and delete '/var/log/cache/swap.state'. + if ( pgrep -fl "(squid-1)" > /dev/null 2>&1 ); then + killproc /usr/sbin/squid >/dev/null + rm -rf /var/log/cache/swap.state + echo "" + boot_mesg -n "You should not be reading this warning.\n" + boot_mesg -n "Some squid-processes had to be killed after 360 seconds,\n" + boot_mesg -n "so the cache index file was damaged and had to be deleted.\n" + boot_mesg -n "This file will be rebuild during the next start." + echo_warning + echo "" + else + boot_mesg "All squid processes exited normally." + echo_ok + echo "" + fi + fi
# Trash remain pid file from squid. rm -rf /var/run/squid.pid - fi + ;;
restart) @@ -143,8 +159,7 @@ case "$1" in
flush) $0 stop - echo > /var/log/cache/swap.state - chown squid.squid /var/log/cache/swap.state + rm -rf /var/log/cache/* sleep 1 $0 start ;;