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

Bug 492222

Summary: apache2 init.d script starts apache but reports it as "failed to start" when pidfile exists
Product: Gentoo Linux Reporter: Roman Barczyński <romke>
Component: [OLD] ServerAssignee: Patrick Lauer <patrick>
Status: RESOLVED FIXED    
Severity: normal CC: polynomial-c
Priority: Normal    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: /etc/init.d/apache2 start --debug
proposed fix

Description Roman Barczyński 2013-11-21 20:27:56 UTC
Created attachment 363756 [details]
/etc/init.d/apache2 start --debug

Apache 2.2.25 init.d script fails to recognize when apache is started instantaneously.

Steps to reproduce:
killall -9 apache
/etc/init.d/apache2 zap
# ensure that /var/run/apache2.pid IS PRESENT
/etc/init.d/apache2 start

What happens:
apache warns that pidfile was overwritten
apache starts
init script fails to recognize that apache has started

What should happen:
apache should warn about pidfile being overwritten
apache starts
init script should recognize that apache has started

----- CAUSE -----

This is caused by recent changes to init file by Lars Wendler:

--------------
Make the init script recognize failed start and stop more reliably.

2013-11-07 - Lars Wendler <polynomial-c@gentoo.org>

--- gentoo-apache-2.2.23/init/apache2.initd
+++ gentoo-apache-2.2.23/init/apache2.initd
@@ -77,12 +77,13 @@
        # Use start stop daemon to apply system limits #347301
        start-stop-daemon --start -- ${APACHE2} ${APACHE2_OPTS} -k start

-       i=0
+       local i=0 retval=1
        while [ ! -e "${PIDFILE}" ] && [ $i -lt ${TIMEOUT} ]; do
                sleep 1 && i=$(expr $i + 1)
+               [ -e "${PIDFILE}" ] && retval=0
        done

-       eend $(test $i -lt ${TIMEOUT})
+       eend ${retval}
-------------

This patch 
- defaults retval to 1
- test for pidfile existing that sets retval=0 DEPENDS on pidfile NOT existing (while [ ! -e "${PIDFILE}" ] ...)
Comment 1 Roman Barczyński 2013-11-21 20:35:24 UTC
Created attachment 363758 [details, diff]
proposed fix
Comment 2 Roman Barczyński 2013-11-21 20:38:33 UTC
- Apache 2.2.25 init.d script fails to recognize when apache is started
- instantaneously.
+ Apache 2.2.25 init.d script fails to recognize when apache is started
+ with old pidfile present (e.g. after unclean reboot) or apache creates
+ its pidfile momentarily
Comment 3 Lars Wendler (Polynomial-C) (RETIRED) gentoo-dev 2013-11-22 08:49:22 UTC
+  22 Nov 2013; Lars Wendler <polynomial-c@gentoo.org>
+  files/gentoo-apache-2.2.23-initd_fixups.patch:
+  Fixed startup of apache when pidfile exists. Thanks to Roman Barczyński who
+  reported this in bug #492222.
+