Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 384267

Summary: www-servers/apache-2.2.21: 'pidof' finds other instances of /usr/sbin/apache2
Product: Gentoo Linux Reporter: Stef Simoens <stef.simoens>
Component: New packagesAssignee: Apache Team - Bugzilla Reports <apache-bugs>
Severity: normal CC: bug, pva
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Package list:
Runtime testing required: ---

Description Stef Simoens 2011-09-24 00:03:24 UTC
I'm running apache2 both in a host and in a container.
The apache2 init-script on the host does not stop the service correctly, as 'pidof' returns the pids of /usr/sbin/apache2 in the container.

Reproducible: Always

Steps to Reproduce:
1. Setup with Host and Container. Run both in host and container apache2 HTTP server
2. Restart apache2 with /etc/init.d/apache2 restart
Actual Results:  
* Stopping apache2 ...                                                                       [ !! ]
* ERROR: apache2 failed to stop

+ it takes TIMEOUT seconds until the script ends

Expected Results:  
Correct restart of apache2

Following patch corrects the problem. Don't use pidof, but check the pid that start-stop-daemon is (trying to) stop.

--- apache2.orig	2011-09-24 01:51:11.390216190 +0200
+++ apache2	2011-09-24 02:02:24.062555913 +0200
@@ -83,11 +83,13 @@
 stop() {
 	checkconfd || return 1
+	PID=`cat ${PIDFILE} 2>/dev/null`
 	ebegin "Stopping ${SVCNAME}"
 	start-stop-daemon --stop --pidfile ${PIDFILE} -- ${APACHE2} ${APACHE2_OPTS} -k stop
-	while pidof "${APACHE2}" >/dev/null && [ $i -lt ${TIMEOUT} ]; do
+	while [ -d /proc/${PID} ] && [ $i -lt ${TIMEOUT} ]; do
 		sleep 1 && i=$(expr $i + 1)
Comment 1 Peter Volkov (RETIRED) gentoo-dev 2011-10-08 19:13:53 UTC
Thank you for report. This does not look like a good way to fix. After reading note in "Graceful Restart" section of the document: I see that apache leaves children behind:

"In the case of graceful restarts it will also leave children running when it exits. (These are the children which are "gracefully exiting" by handling their last request.)"

So I'm going to go with 

while pgrep -p ${PID} >/dev/null && [ $i -lt ${TIMEOUT} ]; do
Comment 2 Marcin Mirosław 2011-10-14 11:52:24 UTC
And the same problem exists when we have multi instances apache, btw.
Comment 3 Marcin Mirosław 2011-10-14 12:04:10 UTC
Peter, i tried your proposal of fix. There is problem, when start-stop-daemon stops apache, then pid file disappear. Pgrep started with empty arg (pgrep -P "") exits with code error 0. Probably variable PID should be checking if is empty.
Comment 4 Peter Volkov (RETIRED) gentoo-dev 2011-10-18 06:43:12 UTC
Thank you for report. Fixed in 2.2.21-r1. Please, try it out and report if issue still persist.

Marcin I've posted just idea, not the full patch. Full patch was just commited.