[mod_python] Startup Options

Daniel West dwmp at opti.cgi.net
Wed Jan 14 21:31:04 EST 2004


mod_python's PythonImport is a neat feature; it allows you to run a script 
when an Apache process fires up.  However, it doesn't work under 
VirtualHosts, only the main server config (mod_python 3.0 and up).  I need 
to support multiple users all who have their own VirtualHosts and all whom 
need PythonImport to setup database connections under their VirtualHost's 
interpreter.  The startup scripts and handler code are naturally located 
under each users' home directory for privacy.

My first attempt was simply to use PythonPath and PythonImport under each 
VirtualHost.  This is straight forward and simple.  Append to the path so 
that the Import can find the startup code in the home directory of each 
user and then issue the PythonImport for their startup script.  This 
doesn't work because PythonImport only works in the main server config.

My second attempt was to use a generic loader with PythonImport (located in 
site-packages) and then use PythonOption to pass it the path and actual 
startup script for each interpreter (VirtualHost).  This doesn't work 
because you can't access PythonOption variables until a request is made.

My third thought was to setup individual scripts for each VirtualHost in 
the site-packages directory with the startup information for each 
user.  The problem here is that the startup scripts have to be owned by the 
user and not world readable (their database passwords are in there).  This 
causes a read problem for server processes run as the user nobody.

I'm not sure how else to make this happen and it's very frustrating.  I 
have all the elements I need, I just can't find a way to put them together 
to accomplish a seemingly simple task.

It sure would be nice if PyhtonImport could be made to run under 
VirtualHosts.  Failing that, a way to get to a VirtualHost's PythonOptions 
would do.  Grisha?

-Dan



More information about the Mod_python mailing list