Edgewall Software

Changes between Initial Version and Version 1 of TracDev/AlternativeFrontends


Ignore:
Timestamp:
Feb 22, 2010, 4:43:14 AM (14 years ago)
Author:
ryano@…
Comment:

Content moved from TracDev/DevelopmentEnvironmentSetup.

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/AlternativeFrontends

    v1 v1  
     1= Alternative frontends =
     2
     3== Alternative frontend: mod_python ==
     4
     5Virtualenv can also be used with Apache and mod_python, but as mod_python will be a system install it will not be aware of the virtualenv without some configuration. For development this is useful as one Apache can serve various development versions in a more permanent way. This method will use the system Python, but will add the libraries from the virtualenv.
     6
     7'''Step 1:''' Make a new frontend script that for instance can be stored in the virtualenv 'bin' directory.
     8
     9{{{
     10#!python
     11#myvirtualtrac.py
     12
     13import os
     14import site
     15site.addsitedir('/path/to/my/virtualenv/lib/python2.4/site-packages')
     16
     17from trac.web.modpython_frontend import handler
     18}}}
     19
     20'''Step 2:''' Update Apache config to use this script - add or update options according to the default mod_python setup like for instance found in TracModPython.
     21
     22{{{
     23# Extend the path so Apache will find your script on path
     24PythonPath "['/path/to/my/virtualenv/bin'] + sys.path"
     25
     26# Make mod_python use new frontend instead of trac.web.modpython_frontend
     27PythonHandler myvirtualtrac
     28}}}
     29
     30== Alternative frontend: mod_wsgi ==
     31
     32Using Apache, mod_wsgi is a very good alternative to mod_python. Setting this up follows the same pattern, but for development escpecially there is one major advantage: It can quite easily be set up to auto-reload on code changes.
     33
     34'''Step 1:''' Update a default TracModWsgi setup to make a deamonised process, and as of mod_wsgi 2.0 (this setup depends on >= 2.0) there is built-in support for custom paths and similar. Example of a full `VirtualHost` configuration:
     35
     36{{{
     37<VirtualHost *:80>
     38    ServerName virtualtrac.local
     39
     40    # Update user and group to be whatever on your system is intended to run the deamon
     41    # Update the paths to point to virtualenv site-packages (for trac+++) and bin (for script)
     42    WSGIDaemonProcess virtualtrac user=www group=www threads=25 python-path=/path/to/my/virtualenv/lib/python2.4/site-packages:/path/to/my/virtualenv/bin
     43
     44    WSGIScriptAlias / /path/to/my/virtualenv/bin/virtualtrac.wsgi
     45
     46    <Location />
     47      WSGIReloadMechanism Process
     48      WSGIProcessGroup virtualtrac
     49      WSGIApplicationGroup %{SERVER}
     50      Order deny,allow
     51      Allow from all
     52    </Location>
     53
     54    # Authentication
     55    <LocationMatch (/[^/.]+/login)>
     56      # Note: Change settings with regards to auth method, paths and domain
     57      AuthType Digest
     58      AuthName "virtualtrac"
     59      AuthDigestDomain /trac http://virtualtrac.local
     60      AuthDigestProvider file
     61      AuthUserFile /path/to/access.htdigest
     62      Require valid-user
     63    </LocationMatch>
     64
     65</VirtualHost>
     66}}}
     67
     68'''Step 2:''' Go to http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode and save the long Python script that follows the text 'Example code for such an automatic restart mechanism...'. Save it as `/path/to/my/virtualenv/bin/monitor.py`
     69
     70'''Step 3:''' A basic WSGI frontend script, save as `/path/to/my/virtualenv/bin/virtualtrac.wsgi`
     71
     72{{{
     73#!python
     74
     75import sys
     76sys.stdout = sys.stderr
     77
     78import os
     79os.environ['TRAC_ENV_DIR'] = "/path/to/trac/project"
     80# or, alternatively for multiple projects
     81#os.environ['TRAC_ENV_PARENT_DIR'] = "/parent/path/to/many/projects"
     82os.environ['PYTHON_EGG_CACHE'] = '/path/to/a/temp/to/cache/eggs'
     83
     84import trac.web.main
     85
     86import monitor
     87monitor.start(interval=1.0)
     88# Additionally monitor easy-install.pth to restart whenever installs are done
     89monitor.track('/path/to/my/virtualenv/lib/python2.4/site-packages/easy-install.pth')
     90
     91application = trac.web.main.dispatch_request
     92}}}