Discussion:
apache/mod_wsgi daemon mode
Graham Dumpleton
2008-02-03 23:40:03 UTC
Permalink
I am trying to configure mod_wsgi to run in daemon mode with
Apache. I can easily get it to run 'normally' under Apache
but I obtain permission errors _or_ process-failures in
... (13)Permission denied: mod_wsgi (pid=26962): Unable
to connect
to WSGI daemon process '<process-name>' on
'/etc/httpd/logs/wsgi.26957.0.1.sock' after multiple attempts.
...
<http://groups.google.com/group/modwsgi/browse_thread/thread/6d3a2f4d7...>
The problem was WSGI trying to create its .sock file in /var/log/httpd but failing and therefore not running at all. The user I had specified did not have enough permissions to do so (part of the point _of_ running in daemon mode, LOL). Oddly, I had attempted to grant the permissions for the user but see now there was an error in how I did that... oops.
WSGISocketPrefix /tmp/wsgi
Also documented in:

http://code.google.com/p/modwsgi/wiki/ConfigurationIssues

Since you have given a real live example error message from logs for
when it goes wrong, I'll be able to include this in the documentation.
That may make it easier for others to find that page when they do a
Google search. At the moment the page only mentioned that you would
get a '503 Service Temporarily Unavailable' response in browser.

Graham
We now have successss!
WSGISocketPrefix /tmp/wsgi
<VirtualHost host.domain.com:80>
ServerName host.domain.com
WSGIDaemonProcess <process-name> user=<user> group=<group> threads=10 \
maximum-requests=500
WSGIScriptAlias /something /path/to/<script>.wsgi
<Directory /path/to/<script>.wsgi>
WSGIApplicationGroup <user>
WSGIProcessGroup <process-name>
Order deny,allow
Allow from all
</Directory>
Thanks, Brian, for pointing me back to the modwsgi list for another look!
Scott
Scott SA
2008-02-03 22:23:03 UTC
Permalink
HI,

I'm posting this here because it is, I believe, a python config issue (mine) that is not correct, but frustration and inexperience has left me without further [visible] options for rectification.

I am trying to configure mod_wsgi to run in daemon mode with Apache. I can easily get it to run 'normally' under Apache but I obtain permission errors _or_ process-failures in daemon mode. Specifically:

... (13)Permission denied: mod_wsgi (pid=26962): Unable to connect
to WSGI daemon process '<process-name>' on
'/etc/httpd/logs/wsgi.26957.0.1.sock' after multiple attempts.


My httpd.conf contains an entry like this, and has had several variations:

<VirtualHost host.domain.com:80>
ServerName host.domain.com

WSGIDaemonProcess <process-name> user=<user> group=<group> threads=10 \
maximum-requests=500

# the following line has been added/removed with no improved results
WSGIProcessGroup <process-name>

WSGIScriptAlias /something /path/to/<script>.wsgi

<Directory /path/to/<script>.wsgi>
# the following two lines have been added/removed
#with no improved results
WSGIApplicationGroup <user>
WSGIProcessGroup <process-name>

Order deny,allow
Allow from all
</Directory>

...
</VirtualHost>


My <script>.wsgi is as follows - but we never get this far!:

import os, sys
sys.stdout = sys.stderr

# in this instance, I've been testing with a trac instance
os.environ['TRAC_ENV'] = '/path/to/trac'

import trac.web.main
application = trac.web.main.dispatch_request



I have made changes in a number of combinations, trying to pinpoint where the problem is occurring. If I don't attempt to run this as a daemon, all is fine. I have noted where I have added/removed the ProcessGroup adn ApplicationGroup directives in an attempt to find the root of problem.

The host is Apache 2.2n under CentOS 5.1 i386 running Python 2.4

I have read, and re-read, mimicked settings from the following sites:

http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac
http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines
http://code.google.com/p/modwsgi/wiki/ConfigurationDirectives

as well as several excelent postings from Graham Dumpleton

So, if you listen close enough, you will hear the sound of my head banging against an unforgiving brick wall ;-)

Thanks in advance to any and all relevent advice or suggestions.

Scott
Brian Smith
2008-02-03 23:03:23 UTC
Permalink
Also, mod_wsgi has its own mailing list:
http://groups.google.com/group/modwsgi
Post by Scott SA
I am trying to configure mod_wsgi to run in daemon mode with Apache. I
can easily get it to run 'normally' under Apache but I obtain
... (13)Permission denied: mod_wsgi (pid=26962): Unable to
connect
to WSGI daemon process '<process-name>' on
'/etc/httpd/logs/wsgi.26957.0.1.sock' after multiple attempts.
The host is Apache 2.2n under CentOS 5.1 i386 running Python 2.4
Try again after "sudo /usr/sbin/setenforce 0". If it works with SELinux
disabled then you will have to do a bit more work to get it working with
SELinux enabled. I suggest creating a directory that is labeled with the
Apache read/write type, and setting the WSGI socket prefix such that the
domain sockets will get put in that directory. If that doesn't solve the
problem then use the procedures in the SELinux documentation to create a
security policy. And then, please share it with me. :)

Regards,
Brian
Scott SA
2008-02-03 23:33:43 UTC
Permalink
Post by Brian Smith
I am trying to configure mod_wsgi to run in daemon mode with
Apache. I can easily get it to run 'normally' under Apache
but I obtain permission errors _or_ process-failures in
... (13)Permission denied: mod_wsgi (pid=26962): Unable
to connect
to WSGI daemon process '<process-name>' on
'/etc/httpd/logs/wsgi.26957.0.1.sock' after multiple attempts.
The host is Apache 2.2n under CentOS 5.1 i386 running Python 2.4
Try again after "sudo /usr/sbin/setenforce 0". If it works with SELinux
disabled then you will have to do a bit more work to get it working with
SELinux enabled. I suggest creating a directory that is labeled with the
Apache read/write type, and setting the WSGI socket prefix such that the
domain sockets will get put in that directory. If that doesn't solve the
problem then use the procedures in the SELinux documentation to create a
security policy. And then, please share it with me. :)
I disabled SELinux during system install and have double-checked it is not running.
Post by Brian Smith
http://groups.google.com/group/modwsgi
I had previoiusly done what I _thought_ was a good job of searching the wsgi mailing list (really!). A reworking of my google search parameters finally yeildd a helpful thread:

<http://groups.google.com/group/modwsgi/browse_thread/thread/6d3a2f4d7c294dc/ba5cd5055bb5cc62?lnk=gst&q=daemon+unable-to-connect#ba5cd5055bb5cc62>

The problem was WSGI trying to create its .sock file in /var/log/httpd but failing and therefore not running at all. The user I had specified did not have enough permissions to do so (part of the point _of_ running in daemon mode, LOL). Oddly, I had attempted to grant the permissions for the user but see now there was an error in how I did that... oops.

By adding the following to my config:

WSGISocketPrefix /tmp/wsgi

We now have successss!


So my config now looks like:

WSGISocketPrefix /tmp/wsgi

<VirtualHost host.domain.com:80>
ServerName host.domain.com

WSGIDaemonProcess <process-name> user=<user> group=<group> threads=10 \
maximum-requests=500

WSGIScriptAlias /something /path/to/<script>.wsgi

<Directory /path/to/<script>.wsgi>
WSGIApplicationGroup <user>
WSGIProcessGroup <process-name>

Order deny,allow
Allow from all
</Directory>


Thanks, Brian, for pointing me back to the modwsgi list for another look!

Scott

Loading...