I'm using Python baked into Apache using modwsgi, and i'm discovering that the sys.path doesn't get initialized properly when Apache is began in the rc2.d startup folder than when run in the spend.
Ubuntu Lucid 10.04
First of all, I'm testing the initialization by using this application:
import sys import os def application(environ, start_response): status = '200 OK' output = ['version %s\n'%sys.version] output.append('sys.prefix = %s \n' % repr(sys.prefix)) output.append('sys.exec_prefix = %s \n' % repr(sys.exec_prefix)) output.append('sys.path = %s \n' % repr(sys.path)) output.append('env.PYTHONHOME = %s\n' % repr(os.environ.get('PYTHONHOME'))) output.append('env.PATH = %s\n' % repr(os.environ.get('PATH'))) response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(sum([len(o) for o in output])))] start_response(status, response_headers) return output
When apache2 is began from party, via 'sudo apache2ctl start', or 'sudo /etc/init.d/apache2 start', it initializes properly, and also the application above shows:
version 2.6.5 (r265:79063, Apr 16 2010, 14:15:55) [GCC 4.4.3] sys.prefix = '/usr' sys.exec_prefix = '/usr/local' sys.path = ['/usr/local/lib/python2.6/dist-packages/WebOb-1.0.7-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/twiddler-0.9.1-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/elementtree-1.2.7_20070827_preview-py2.6.egg', '/usr/local/lib/python2.6/dist-packages/lxml-2.3-py2.6-linux-x86_64.egg', '/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/local/lib/python2.6/lib-dynload', '/usr/lib/python2.6/dist-packages', '/usr/lib/pymodules/python2.6', '/usr/local/lib/python2.6/dist-packages', '/usr/local/lib/python2.6/dist-packages'] env.PYTHONHOME = '/usr:/usr/local' env.PATH = '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin'
When apache2 is began from /etc/rc2.d throughout boot, it doesn't initialize properly, and also the application shows:
version 2.6.5 (r265:79063, Apr 16 2010, 14:15:55) [GCC 4.4.3] sys.prefix = '/usr' sys.exec_prefix = '/usr/local' sys.path = ['/usr/lib/python2.6', '/usr/lib/python2.6/plat-linux2', '/usr/lib/python2.6/lib-tk', '/usr/lib/python2.6/lib-old', '/usr/local/lib/python2.6/lib-dynload'] env.PYTHONHOME = '/usr:/usr/local' env.PATH = '/sbin:/usr/sbin:/bin:/usr/bin'
Critical sites aren't found, including dist-packages.
I've attempted moving the apache script earlier and then within the startup sequence, and become evenly bad results. Loading apache last within the startup will get the dysfunctional sys.path loading it in the spend, immediately after, loads properly.
The question, again, is the reason why would the sys.path initialize in a different way run like a startup process than run in the spend?
site.py isn't being run by Python's initialization. Now i'm seeing mod_wsgi errors "not able to import 'site' module". The errors began showing up after supplying a WSGIPythonPath value in Apach2.conf, although the sys.path signs and symptoms happen to be there all along.
There's something concerning the mixture of chrooting Apache and beginning from rc#.d scripts that's breaking Python's site.py loading.
Starting Apache in the spend, via sudo, or sudo -i, from the completely new account, works fine.
You are running like a different user. Party (as well as your other login scripts) set a number of the journey variables advertising media are as the standard user that won't get set when running because the apache user on startup.
Apache is initializing properly. You need to simply be explicit about which pathways you need to include, if you want them.
It is the same reason you frequently have to be more explicit when running cron jobs.
If you use sudo being that user, a part of your overall atmosphere persist, as well as your your python path variables. You should utilize the -i option with sudo to simulate what goes on once the root user initially logs in and runs apache.