Bug 701762

Summary: Use wsgi instead of mod-python
Product: [Fedora] Fedora Reporter: Neal Becker <ndbecker2>
Component: tracAssignee: Gwyn Ciesla <gwync>
Status: CLOSED ERRATA QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 15CC: amessina, dcantrell, fschwarz, gwync, paul, ssato
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: trac-0.12.2-5.fc15 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2011-06-24 03:39:33 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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:
1.
2.
3.
  
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
</Directory>
# <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
</Location>

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:

http://www.city-fan.org/tips/TracWithFastCGIonFedora

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.
https://admin.fedoraproject.org/updates/trac-0.12.2-5.fc15

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:
https://admin.fedoraproject.org/updates/trac-0.12.2-5.fc15
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):

-----------------------------------:X----------------------------------
#! /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:
try:
    cparser = configparser.SafeConfigParser()
    cparser.read(TRAC_WSGI_SITE_CONFIG)

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



def application(environ, start_request):
    os.environ['TRAC_ENV_PARENT_DIR'] = TRAC_ENV_PARENT_DIR
    os.environ['PYTHON_EGG_CACHE'] = PYTHON_EGG_CACHE

    return dispatch_request(environ, start_request)


# vim:sw=4 ts=4 et:
-----------------------------------:X----------------------------------


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

-----------------------------------:X----------------------------------
[environ]
TRAC_ENV_PARENT_DIR = /var/lib/trac
PYTHON_EGG_CACHE = /var/tmp/egg-cache
-----------------------------------:X----------------------------------

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:

trac.wsgi:
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
</Directory>

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