| 125 | |
| 126 | === Alternative frontend: mod_wsgi === |
| 127 | |
| 128 | Using 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. |
| 129 | |
| 130 | '''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: |
| 131 | |
| 132 | {{{ |
| 133 | <VirtualHost *:80> |
| 134 | ServerName virtualtrac.local |
| 135 | |
| 136 | # Update user and group to be whatever on your system is intended to run the deamon |
| 137 | # Update the paths to point to virtualenv site-packages (for trac+++) and bin (for script) |
| 138 | WSGIDaemonProcess tracdev user=www group=www threads=25 python-path=/path/to/my/virtualenv/lib/python2.4/site-packages:/path/to/my/virtualenv/bin |
| 139 | |
| 140 | WSGIScriptAlias / /path/to/my/virtualenv/bin/tracdev.wsgi |
| 141 | |
| 142 | <Location /> |
| 143 | WSGIReloadMechanism Process |
| 144 | WSGIProcessGroup virtualtrac |
| 145 | WSGIApplicationGroup %{SERVER} |
| 146 | Order deny,allow |
| 147 | Allow from all |
| 148 | </Location> |
| 149 | |
| 150 | # Authentication |
| 151 | <LocationMatch (/[^/.]+/login)> |
| 152 | # Note: Change settings with regards to auth method, paths and domain |
| 153 | AuthType Digest |
| 154 | AuthName "virtualtrac" |
| 155 | AuthDigestDomain /trac http://virtualtrac.local |
| 156 | AuthDigestProvider file |
| 157 | AuthUserFile /path/to/access.htdigest |
| 158 | Require valid-user |
| 159 | </LocationMatch> |
| 160 | |
| 161 | </VirtualHost> |
| 162 | }}} |
| 163 | |
| 164 | '''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` |
| 165 | |
| 166 | '''Step 3:''' A basic WSGI frontend script |
| 167 | |
| 168 | {{{ |
| 169 | #!python |
| 170 | |
| 171 | import sys |
| 172 | sys.stdout = sys.stderr |
| 173 | |
| 174 | import os |
| 175 | os.environ['TRAC_ENV_DIR'] = "/path/to/trac/project" |
| 176 | # or, alternatively for multiple projects |
| 177 | #os.environ['TRAC_ENV_PARENT_DIR'] = "/parent/path/to/many/projects" |
| 178 | os.environ['PYTHON_EGG_CACHE'] = '/path/to/a/temp/to/cache/eggs' |
| 179 | |
| 180 | import trac.web.main |
| 181 | |
| 182 | import monitor |
| 183 | monitor.start(interval=1.0) |
| 184 | # Additionally monitor easy-install.pth to restart whenever installs are done |
| 185 | monitor.track('/path/to/my/virtualenv/lib/python2.4/site-packages/easy-install.pth') |
| 186 | |
| 187 | application = trac.web.main.dispatch_request |
| 188 | }}} |