With a little side of applesauce...

Tuesday, January 30, 2007

Debian Sarge - Can’t stop those apache2 processes?

If you are having problems killing apache2 processes with the /etc/init.d/apache2 script, run it with the -x switch:

/bin/bash -x /etc/init.d/apache2 stop

My output looked like this:


mymachine:/etc/apache2# /bin/bash -x /etc/init.d/apache2 stop
+ ENV=env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin
+ NO_START=0
+ set -e
+ '[' -x /usr/sbin/apache2 ']'
+ HAVE_APACHE2=1
+ test -f /etc/default/rcS
+ . /etc/default/rcS
++ TMPTIME=0
++ SULOGIN=no
++ DELAYLOGIN=yes
++ UTC=no
++ VERBOSE=yes
++ EDITMOTD=yes
++ FSCKFIX=no
+ test -f /etc/default/apache2
+ . /etc/default/apache2
++ NO_START=0
+ '[' 0 '!=' 0 -a stop '!=' stop ']'
+ APACHE2=env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin /usr/sbin/apache2
+ APACHE2CTL=env -i LANG=C PATH=/usr/local/bin:/usr/bin:/bin /usr/sbin/apache2ctl
+ echo -n 'Stopping web server: Apache2'
Stopping web server: Apache2+ apache_stop
+ PID=
+ PIDFILE=
++ grep '^PidFile' /etc/apache2/access /etc/apache2/apache2.conf /etc/apache2/apache2.conf~ /etc/apache2/conf.d /etc/apache2/envvars /etc/apache2/httpd.conf /etc/apache2/magic /etc/apache2/mods-available /etc/apache2/mods-enabled /etc/apache2/old /etc/apache2/ports.conf /etc/apache2/README /etc/apache2/sites-available /etc/apache2/sites-enabled /etc/apache2/ssl /etc/apache2/ssl.crt /etc/apache2/ssl.key -r
++ awk '{print $2}'
+ PIDFILE=/var/run/apache2.pid
+ '[' -e /var/run/apache2.pid ']'
++ cat /var/run/apache2.pid
+ PID=21370
+ PIDFILE=/var/run/apache2.pid
+ '[' -e /var/run/apache2.pid ']'
++ cat /var/run/apache2.pid
+ PID=21370
+ PIDFILE=/opt/apache/logs/httpd.pid
+ '[' -e /opt/apache/logs/httpd.pid ']'
+ PIDFILE=/opt/apache/logs/httpd.pid
+ '[' -e /opt/apache/logs/httpd.pid ']'
++ apache2 -t
+ '[' -e /opt/apache/logs/httpd.pid ']'
+ echo -n ' ... no pidfile found! not running?'
... no pidfile found! not running?+ echo .

Do you notice that it searches for the PID in both:

/var/run/apache2.pid

and:

/opt/apache/logs/httpd.pid

The reason this is happening is that /etc/init.d/apache2 searches recursively through the /etc/apache2/ directory for the PidFile directive, and I had created a backup of the conf file in a subdirectory of /etc/apache2. Here is the offending code:

# apache2 allows more than PidFile entry in the config but only
# the last found in the config is used
for PFILE in `grep ^PidFile /etc/apache2/* -r | awk '{print $2}'`; do
PIDFILE="$PFILE"
if [ -e "$PIDFILE" ]; then
PID=`cat $PIDFILE`

Here is the Debian Bug Report <#303076>

AND, it is fixed in apache2-common 2.0.55-4, which is available in etch:

dpkg-source: extracting apache2 in apache2-2.0.55
dpkg-source: unpacking apache2_2.0.55.orig.tar.gz
dpkg-source: applying ./apache2_2.0.55-4.diff.gz

(It is fixed in sid as well).

No comments: