public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
From: Matthias Fischer <matthias.fischer@ipfire.org>
To: development@lists.ipfire.org
Subject: [PATCH] squid init v3: Update-suggestions for (3.5.xx)-initscript
Date: Sun, 15 May 2016 18:43:13 +0200	[thread overview]
Message-ID: <1463330593-2110-1-git-send-email-matthias.fischer@ipfire.org> (raw)

[-- Attachment #1: Type: text/plain, Size: 3348 bytes --]

These changes are mainly meant for upcoming squid 3.5.xx,
but should still work with 3.4.xx:

- Raised 'while-loop'-time for stopping squid to 360 seconds,
  even bigger caches should get a chance. ;-)

- Changed the 'while-loop' from using 'statusproc' to 'squid -k check',
  since 'statusproc' didn't find the still running '(squid-1)'-process.
  Thus, 'squid' hadn't enough time to close the index. This led to a
  damaged 'swap.state'-file and "Rebuilding storage in /var/log/cache"
  always ended with "(dirty log)".

- Process detection for leftover '(squid-1)'-process uses 'pgrep'.

- Cosmetic changes to some 'boot_mesg' lines. Added a few.

- Changed the 'flush'-command to delete the entire '/var/log/cache'-structure,
  it will automatically be rebuild during the next start.

Best,
Matthias

Signed-off-by: Matthias Fischer <matthias.fischer(a)ipfire.org>
---
 src/initscripts/init.d/squid | 43 ++++++++++++++++++++++++++++---------------
 1 file changed, 28 insertions(+), 15 deletions(-)

diff --git a/src/initscripts/init.d/squid b/src/initscripts/init.d/squid
index abed90a..47bf182 100644
--- a/src/initscripts/init.d/squid
+++ b/src/initscripts/init.d/squid
@@ -94,8 +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
+			boot_mesg -n "Shutting down Squid Proxy Server...\n"
+			boot_mesg "(this may take up to a few minutes)."
+			/usr/sbin/squid -k shutdown >/dev/null 2>&1
 			evaluate_retval
 
 			# Stop squidGuard, updxlrator, squidclamav
@@ -108,22 +109,35 @@ case "$1" in
 			# 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;
+			# If some squid processes are still running, wait up to 360 seconds
+			# before we go on to kill all and delete entire cache structure.
+			n=0
+			while [ /usr/sbin/squid -k check > /dev/null 2>&1 ] && [ $n -lt 360 ]; do
 				sleep 1
-				counter=$(( ${counter} - 1))
+				n=$(( ${n} + 1 ))
 			done
 
-			# Kill squid service, if still running.
-			killproc /usr/sbin/squid >/dev/null
+			# If (squid-1) is still running after 360 seconds,
+			# kill all squid processes and delete damaged cache structure.
+			if ( pgrep -fl "(squid-1)" > /dev/null 2>&1 ); then
+				killproc /usr/sbin/squid >/dev/null
+				rm -rf /var/log/cache/*
+				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 index file and cache contents had to be deleted.\n"
+				boot_mesg -n "Therefore, the complete cache structure will be rebuild\n"
+				boot_mesg "during next start."
+				echo_warning
+			else
+				boot_mesg "All squid processes exited normally."
+				echo_ok
+				boot_mesg ""
+			fi
+		fi
 
-			# Trash remain pid file from squid.
+			# Delete remaining pid file from squid if it still exists.
 			rm -rf /var/run/squid.pid
-		fi
+
 		;;
 
 	restart)
@@ -143,8 +157,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
 		;;
-- 
2.8.2


             reply	other threads:[~2016-05-15 16:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-15 16:43 Matthias Fischer [this message]
2016-05-16 15:13 ` Michael Tremer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1463330593-2110-1-git-send-email-matthias.fischer@ipfire.org \
    --to=matthias.fischer@ipfire.org \
    --cc=development@lists.ipfire.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox