Bug 701762 - Use wsgi instead of mod-python
Summary: Use wsgi instead of mod-python
Alias: None
Product: Fedora
Classification: Fedora
Component: trac
Version: 15
Hardware: Unspecified
OS: Unspecified
Target Milestone: ---
Assignee: Gwyn Ciesla
QA Contact: Fedora Extras Quality Assurance
Depends On:
TreeView+ depends on / blocked
Reported: 2011-05-03 19:10 UTC by Neal Becker
Modified: 2013-01-10 06:36 UTC (History)
6 users (show)

Fixed In Version: trac-0.12.2-5.fc15
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2011-06-24 03:39:33 UTC
Type: ---

Attachments (Terms of Use)

Description Neal Becker 2011-05-03 19:10:59 UTC
Description of problem:

As I understand it, mod-python is deprecated and wsgi should be used instead.

This requires changing /etc/httpd/conf.d/trac.conf

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
Actual results:

Expected results:

Additional info:

The following seems to work (minimal testing!)
# Replace all occurrences of /srv/trac with your trac root below
# and uncomment the respective SetEnv and PythonOption directives.
WSGIScriptAlias /trac /var/www/cgi-bin/trac.wsgi

<Directory /var/www/>
    WSGIApplicationGroup %{GLOBAL}
    Order deny,allow
    Allow from all
# <LocationMatch /cgi-bin/trac\.f?cgi>
#     SetEnv TRAC_ENV /opt/trac/hn-aci
# </LocationMatch>
# <IfModule mod_python.c>
# <Location /cgi-bin/trac.cgi>
#     SetHandler mod_python
#     PythonHandler trac.web.modpython_frontend
#     #PythonOption TracEnv /srv/trac
# </Location>
# </IfModule>

<Location "/trac/login">

    AuthType Digest
    AuthName "trac"
    AuthDigestDomain /trac
    AuthUserFile /opt/trac/trac.htpasswd
    Require valid-user

Comment 1 Paul Howarth 2011-05-03 20:17:17 UTC
It might also be worth documenting alternative approaches, such as mod_fcgid, which I've been using for a couple of years now. I documented how I set it up here:


Comment 2 Jesse Keating 2011-06-13 23:38:03 UTC
Looks like we would need to ship a trac.wsgi file as well.  Not a big deal, it just has to be created.

Jon, don't suppose you want to take a crack at this?

Comment 3 Gwyn Ciesla 2011-06-14 14:01:57 UTC
Commited file and modified spec to git, didn't build.  Have a peek.

Comment 4 Jesse Keating 2011-06-14 18:24:23 UTC
After discussing on IRC, this looks good.  I do think we should remove the mod_python example, or at least comment in it that it is no longer supported / recommended upstream.  Other than that, build at will.

Comment 5 Fedora Update System 2011-06-14 19:41:11 UTC
trac-0.12.2-5.fc15 has been submitted as an update for Fedora 15.

Comment 6 Fedora Update System 2011-06-15 18:32:33 UTC
Package trac-0.12.2-5.fc15:
* should fix your issue,
* was pushed to the Fedora 15 testing repository,
* should be available at your local mirror within two days.
Update it with:
# su -c 'yum update --enablerepo=updates-testing trac-0.12.2-5.fc15'
as soon as you are able to.
Please go to the following url:
then log in and leave karma (feedback).

Comment 7 Fedora Update System 2011-06-24 03:39:27 UTC
trac-0.12.2-5.fc15 has been pushed to the Fedora 15 stable repository.  If problems still persist, please make note of it in this bug report.

Comment 8 Satoru SATOH 2011-09-05 11:16:40 UTC
%{_var}/www/cgi-bin/trac.wsgi looks a configuration file for apache httpd, not the python script use wsgi as expected.

Maybe I'm wrong but both the followings should be needed, I guess:

a. %{_var}/www/cgi-bin/trac.wsgi (a python script)
b. %{_sysconfdir}/httpd/conf.d/trac-wsgi.conf or some configuration files
   for apache httpd

The content of trac.wsgi may look like (sorry, I don't tested these at all):

#! /usr/bin/python
# trac wsgi wrapper script.
# Example of /etc/trac/wsgi.ini --------------------------
# [environ]
# TRAC_ENV_PARENT_DIR = "/var/lib/trac"
# PYTHON_EGG_CACHE = "/var/tmp/egg-cache"
# --------------------------------------------------------
# SEE ALSO: http://trac.edgewall.org/wiki/TracModWSGI
import ConfigParser as configparser
import os

from trac.web.main import dispatch_request

TRAC_WSGI_SITE_CONFIG = "/etc/trac/wsgi.ini"

# Load environ parameters:
    cparser = configparser.SafeConfigParser()

    TRAC_ENV_PARENT_DIR = cparser.get("environ", "TRAC_ENV_PARENT_DIR")
    PYTHON_EGG_CACHE = cparser.get("environ", "PYTHON_EGG_CACHE")
    TRAC_ENV_PARENT_DIR = "/var/lib/trac"
    PYTHON_EGG_CACHE = "/tmp/.egg-cache"

def application(environ, start_request):

    return dispatch_request(environ, start_request)

# vim:sw=4 ts=4 et:

and corresponding /etc/trac/wsgi.ini refered in the above may look like:

TRAC_ENV_PARENT_DIR = /var/lib/trac
PYTHON_EGG_CACHE = /var/tmp/egg-cache

Comment 9 Anthony Messina 2011-09-05 16:15:30 UTC
Actually, following the instructions here: http://code.google.com/p/modwsgi/wiki/IntegrationWithTrac, the trac.wsgi file can be much simpler:

import trac.web.main
application = trac.web.main.dispatch_request

and the trac.conf (for apache):

WSGIDaemonProcess atrac processes=2 threads=15 maximum-requests=1000
WSGIDaemonProcess btrac processes=2 threads=15 maximum-requests=1000
WSGIDaemonProcess ctrac processes=2 threads=15 maximum-requests=1000

RewriteCond %{REQUEST_URI} ^/(atrac|btrac|ctrac)
RewriteRule . - [E=trac.process_group:%1,E=trac.env_path:/var/www/trac-sites/%1]

WSGIScriptAliasMatch ^/(atrac|btrac|ctrac) /var/www/wsgi/trac.wsgi
<Directory /var/www/wsgi>
  WSGIProcessGroup %{ENV:trac.process_group}
  WSGIApplicationGroup %{GLOBAL}
  Order deny,allow
  Allow from all

The above config would allow the easy addition of multiple trac sites by simply adding another WSGIDaemonProcess line, assuming that all of the sites are kept under /var/www/trac-sites.

In Fedora, the /etc/httpd/conf.d/wsgi.conf file requires the addition of:
WSGISocketPrefix run/wsgi

so that the sockets are placed in the right place: http://code.google.com/p/modwsgi/wiki/ConfigurationIssues#Location_Of_UNIX_Sockets

Note You need to log in before you can comment on or make changes to this bug.