A
A
Alexey2011-08-31 10:09:56
Apache HTTP Server
Alexey, 2011-08-31 10:09:56

Does Apache take too long to restart?

The stop is done by the following script:

PID=`cat /var/run/apache2.pid`<br/>
kill -TERM $PID<br/>
if [ -n &quot;${PID:-}&quot; ]; then<br/>
 i=0<br/>
 while kill -0 &quot;${PID:-}&quot; 2&gt; /dev/null; do<br/>
 if [ $i = '60' ]; then<br/>
 break;<br/>
 else<br/>
 if [ $i = '0' ]; then<br/>
 echo -n &quot; waiting &quot;<br/>
 else<br/>
 echo -n &quot;.&quot;<br/>
 fi<br/>
 i=$(($i+1))<br/>
 sleep 1<br/>
 fi<br/>
 done<br/>
fi

As a result, the script executes even without waiting (does not draw dots), then a certain script is launched that works with the database, etc. (about 10-20 seconds) more, and then Apache starts up. But in the end we get an error:
(98)Address already in use: make_sock: could not bind to address 127.0.0.1:80<br/>
no listening sockets available, shutting down<br/>
Unable to open logs

From which it is clear that the old Apache hangs running. Somewhere in 2-3 minutes it is possible to launch a new copy. Actually the question is why is it so slow to die. Previously, this was not observed, I noticed this only after updating Nginx to the latest version (apache - backend, nginx - frontend).
PS nginx is killed right BEFORE apache with this command:
kill -TERM `cat /var/run/nginx/nginx.pid`
PPS Apache/2.2.14 (Ubuntu), nginx/1.1.0, Ubuntu 10 LTS Server

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
DmZ, 2011-09-01
@DmZ

The script works "without waiting (does not draw dots)" - because it is crookedly written.
while kill -0 "${PID:-}" 2> /dev/null; do
will always be FALSE when the process is running, because kill -0 returns 0 (i.e. false) if the process can be signaled.
If you rewrite the script to something like this, then it will wait for the process to complete: Next, you should check who exactly occupies the socket and what state it is in, for example netstat -anptl | grep 127.0.0.1:80 And dance further from this (well, no one forbade watching the logs during the stop).
kill -0 ${PID:-}
while [ $? -eq 0 ]; do
.....
kill -0 ${PID:-}
done;

S
s0rr0w, 2011-08-31
@s0rr0w

And if you try apache2ctl stop or apache2ctl -k stop?
Those. stop work not through kill.

M
Michael, 2011-09-02
@1099511627776

Maybe try multi-apachectl for different copies of apache. Just googled
www.macnews.co.il/mageworks/scripts/multi-apachectl/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question