Merge lp:~clint-fewbar/ubuntu/lucid/squid/fix-upgrades-after-reload into lp:ubuntu/lucid/squid

Proposed by Clint Byrum
Status: Needs review
Proposed branch: lp:~clint-fewbar/ubuntu/lucid/squid/fix-upgrades-after-reload
Merge into: lp:ubuntu/lucid/squid
Diff against target: 56 lines (+38/-0)
2 files modified
debian/changelog (+7/-0)
debian/preinst (+31/-0)
To merge this branch: bzr merge lp:~clint-fewbar/ubuntu/lucid/squid/fix-upgrades-after-reload
Reviewer Review Type Date Requested Status
Chuck Short (community) Approve
Review via email: mp+49741@code.launchpad.net

Description of the change

This branch fixes the problem by checking to see if the problem the recent update is trying to correct has actually happened, and if so, doing a stop/start on the service using invoke-rc.d Between the stop/start, it also kills the errant pid (but only if invoke-rc.d worked, so policy is still respected).

I test this on a lucid vm in the following scenarios:

* bare bones no updates with just 'apt-get install squid' version 2.7.STABLE7-1ubuntu12
 - When preinst is run, the upstart pid and the pidfile agree, and so it exits doing nothing.

* same, but also running 'sudo reload squid', verifying that squid is not tracked by upstart anymore with 'status squid' showing stop/waiting, but 'ps auxw | grep squid' showing a running squid.
 - the job is stopped, the old squid is killed, squid is started again

* start squid, reload, kill -9, leaving stale pid file.
 - Code stops because /proc/`cat pidfile` does not exist.

* modify /etc/init/squid.conf to not use expect fork, and pass -N (basically manually putting in the new job file). This simulates the chance that a user may have applied the fix manually.
 - Code stops because the upstart pid matches the pidfile.

* stopped service before hand
 - pidfile is gone, code is not run

* removed upstart file
 - code checks for that, does not run.

To post a comment you must log in.
Revision history for this message
Chuck Short (zulcss) wrote :

Looks good to me, however can you put the info in the bug report as well. ;)
chuck

review: Approve

Unmerged revisions

53. By Clint Byrum

Detect and deal with the situation where upstart has lost track of
squid. (LP: #717397)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2011-02-01 13:26:36 +0000
3+++ debian/changelog 2011-02-15 00:21:42 +0000
4@@ -1,3 +1,10 @@
5+squid (2.7.STABLE7-1ubuntu12.2) lucid-proposed; urgency=low
6+
7+ * Detect and deal with the situation where upstart has lost track of
8+ squid. (LP: #717397)
9+
10+ -- Clint Byrum <clint@ubuntu.com> Mon, 14 Feb 2011 14:39:47 -0800
11+
12 squid (2.7.STABLE7-1ubuntu12.1) lucid-proposed; urgency=low
13
14 * Run squid with -N and drop 'expect fork' to prevent HUP's from
15
16=== modified file 'debian/preinst'
17--- debian/preinst 2010-04-16 09:00:19 +0000
18+++ debian/preinst 2011-02-15 00:21:42 +0000
19@@ -52,6 +52,37 @@
20 chsh -s /bin/sh proxy
21 fi
22
23+# Because of this bug:
24+# https://bugs.launchpad.net/bugs/573853
25+# Upstart may have lost track of squid. Correct that by using the
26+# pid file to stop it and then start the job back up
27+if [ "$1" = "upgrade" ] \
28+ && dpkg --compare-versions "$2" lt '2.7.STABLE7-1ubuntu12.1' \
29+ && [ -f "/var/run/squid.pid" ] \
30+ && [ -f "/etc/init/squid.conf" ]
31+then
32+ SQUID_PID=`cat /var/run/squid.pid`
33+ # is this still running, and actually squid
34+ if [ -d "/proc/${SQUID_PID}" ] \
35+ && [ "`stat -L -c %D%i /proc/${SQUID_PID}/exe`" = "`stat -L -c %D%i /usr/sbin/squid`" ]
36+ then
37+ UPSTART_SQUID_PID=`initctl status squid | awk -F'process ' '/start\/running, process / { print $2 }'`
38+ PIDFILE_PPID=`awk '{print $4}' /proc/$SQUID_PID/stat`
39+ # If the user has disabled expect fork the pids will be the same
40+ if [ "$UPSTART_SQUID_PID" != "$SQUID_PID" -a "$PIDFILE_PPID" != "$UPSTART_SQUID_PID" ]
41+ then
42+ # stop the job
43+ if invoke-rc.d squid stop
44+ then
45+ # kill the pid file pid
46+ kill ${SQUID_PID}
47+ # start the job again
48+ invoke-rc.d squid start
49+ fi
50+ fi
51+ fi
52+fi
53+
54 #DEBHELPER#
55
56 exit 0

Subscribers

People subscribed via source and target branches

to all changes: