views:

14

answers:

1

I am trying to deploy my project using mod_wsgi. Unfortunately I get:

[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] Exception in WSGI handler: 
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] Traceback (most recent call last):
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/home/project/project/wsgi/project.wsgi", line 26, in application
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     return handler(environ, start_response)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/core/handlers/wsgi.py", line 230, in __call__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     self.load_middleware()
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/core/handlers/base.py", line 33, in load_middleware
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     for middleware_path in settings.MIDDLEWARE_CLASSES:
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/utils/functional.py", line 276, in __getattr__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     self._setup()
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/conf/__init__.py", line 40, in _setup
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     self._wrapped = Settings(settings_module)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/conf/__init__.py", line 73, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/site-packages/Django-1.2.1-py2.5.egg/django/utils/importlib.py", line 35, in import_module
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     __import__(name)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/home/project/project/__init__.py", line 7, in <module>
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     logging.config.fileConfig(settings.LOG_CONFIG)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/config.py", line 84, in fileConfig
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     handlers = _install_handlers(cp, formatters)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/config.py", line 152, in _install_handlers
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     h = apply(klass, args)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/handlers.py", line 109, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     BaseRotatingHandler.__init__(self, filename, mode, encoding)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/handlers.py", line 61, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     logging.FileHandler.__init__(self, filename, mode, encoding)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]   File "/usr/lib/python2.5/logging/__init__.py", line 772, in __init__
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64]     stream = open(filename, mode)
[Wed Oct 27 15:32:33 2010] [error] [client 10.13.3.64] IOError: [Errno 13] Permission denied: 'project.log'

I have an entry for my project inside /etc/apache2/sites-enabled/:

SetEnv app_settings project.config.production
WSGIDaemonProcess project user=project group=project threads=1 processes=1 home=/home/project/project python-path=/home/project
<VirtualHost *>
        ServerName project.internal
        WSGIScriptAlias / /home/project/project/wsgi/project.wsgi
        WSGIProcessGroup %{GLOBAL}
</VirtualHost>

My logs should be stored inside the project directory. I have investigated it a little and just before project.log is supposed to be opened I run os.getcwd(), which returned /. Can anyone tell me, what I might have misconfigured that this happens?

+1  A: 

This is not much of an answer, but I set my site up to only use absolute pathnames, pulling in the base paths from settings.py. You can have variables in settings.py that aren't official Django settings names, and as long as you name them using ALLCAPS_WITH_UNDERSCORES style, it will let you import those with import settings.

IIRC, daemons in general should use absolute pathnames. Apparently, using relative pathnames can be a security hole.

Mike DeSimone
Using absolute path in logging config worked (used by python logging system), but I am pretty certain, that relative path can be used too - on other server we had django deployed that way. I'd like to do that same way.
gruszczy
Then you may need to do an `os.chdir()` in your `project.wsgi` file; maybe `os.chdir(os.path.dirname(sys.argv[0]))`? The key point is that relative paths are *fragile*; you can run your program from anywhere by executing `/home/project/project/wsgi/project.wsgi`. So can there really be a guarantee that the working directory will always be the same?
Mike DeSimone