Restarting or stopping apache results in waiting forever

apache-2.2mod-wsgi

I have two simple WSGI apps running on top of mod_wsgi and apache2 (worker) on a test development server. There is no mod_python on this machine.

The WSGI configuration is as follows

    WSGIDaemonProcess tops stack-size=524288 maximum-requests=5
    WSGIScriptAlias /tops /home/ubuntu/tops-cloud/tops.wsgi

    <Directory /home/ubuntu/tops-cloud>
            WSGIProcessGroup tops
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
    </Directory>


    WSGIDaemonProcess flaskal maximum-requests=5
    WSGIScriptAlias /c14 /home/ubuntu/c14/flaskal/flaskal.wsgi

    <Directory /home/ubuntu/c14/flaskal>
            WSGIProcessGroup flaskal
            WSGIApplicationGroup %{GLOBAL}
            Order deny,allow
            Allow from all
    </Directory>

If I make changes to the configuration (e.g. number of maximum requests, etc), I need to restart the web server, so I would expect that a simple sudo service apache2 restart does what I need.

Instead, it never ends "waiting", like this:

$ sudo service apache2 restart
 * Restarting web server apache2
... waiting ..................................................

until I just do CTRL-C. At that point, the only way to resume a working server is to kill the process and restart it, not very convenient. The same happens with the stop command.

The error logs at the "debug" level show the following lines after a failed restart

[Wed Nov 14 21:55:19 2012] [notice] caught SIGTERM, shutting down
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=9047): Shutdown requested 'tops'.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=9047): Stopping process 'tops'.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=9047): Destroying interpreters.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=9047): Cleanup interpreter ''.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=9047): Terminating Python.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=8920): Shutdown requested 'flaskal'.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=8920): Stopping process 'flaskal'.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=8920): Destroying interpreters.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=8920): Cleanup interpreter ''.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=8920): Terminating Python.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=8920): Python has shutdown.
[Wed Nov 14 21:55:19 2012] [info] mod_wsgi (pid=9047): Python has shutdown.

If I then try to restart again (with the process still running), I get the following error:

 * Restarting web server apache2                                                                                                            (98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Action 'start' failed.
The Apache error log may have more information.

Unfortunately the Apache error log doesn't have anything.

When apache2 is running properly, both apps work without any problem.

Best Answer

In some cases a log entry will not be written to disk (if logs don't exist or its permissions are wrong). The best way to diagnose an error is to try to start Apache with the following command strace -Ff apachectl start.

Related Topic