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 i=0 - while pidof "${APACHE2}" >/dev/null && [ $i -lt ${TIMEOUT} ]; do + while [ -d /proc/${PID} ] && [ $i -lt ${TIMEOUT} ]; do sleep 1 && i=$(expr $i + 1) done
Thank you for report. This does not look like a good way to fix. After reading note in "Graceful Restart" section of the document: http://httpd.apache.org/docs/2.2/stopping.html 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 ...
And the same problem exists when we have multi instances apache, btw.
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.
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.