source: branches/locker-dev/locker/deploy/trac/trac.fcgi @ 1527

Last change on this file since 1527 was 1527, checked in by andersk, 14 years ago
Import trac from production.
  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/usr/bin/python
2
3import os, os.path, sys
4from trac.web import fcgi_frontend
5
6env_path = os.getcwd()+'/tracdata'
7os.environ['TRAC_ENV'] = env_path
8
9def send_upgrade_message(environ, start_response):
10    import pwd
11    start_response('500 Internal Server Error', [])
12    locker = pwd.getpwuid(os.getuid())[0]
13    return ['''This Trac instance needs to be upgraded.
14
15From an Athena machine, type
16  ssh %s@scripts trac-admin %s upgrade --no-backup
17  ssh %s@scripts trac-admin %s wiki upgrade
18to upgrade, and then
19  add scripts
20  for-each-server -l %s pkill trac.fcgi
21to get this message out of the way.
22
23Please ask the scripts.mit.edu maintainers for help
24if you have any trouble, at scripts@mit.edu.
25''' % (locker, env_path, locker, env_path, locker)]
26
27def setup_env():
28    '''Obtain the environment, handling the needs-upgrade check, and cache it.
29
30    This mimics open_environment in trac/env.py.'''
31    import trac.env
32    env = trac.env.Environment(env_path)
33    needs_upgrade = False
34    try:
35        needs_upgrade = env.needs_upgrade()
36    except Exception, e: # e.g. no database connection
37        env.log.exception(e)
38    if env.needs_upgrade():
39        fcgi_frontend._fcgi.WSGIServer(send_upgrade_message).run()
40        sys.exit(0)
41    if hasattr(trac.env, 'env_cache'):
42        trac.env.env_cache[env_path] = env
43setup_env()
44
45def my_dispatch_request(environ, start_response):
46    if ('REDIRECT_URL' in environ and 'PATH_INFO' in environ
47        and environ['REDIRECT_URL'].endswith(environ['PATH_INFO'])):
48        environ['SCRIPT_NAME'] = environ['REDIRECT_URL'][:-len(environ['PATH_INFO'])]
49    return fcgi_frontend.dispatch_request(environ, start_response)
50
51fcgi_frontend._fcgi.WSGIServer(my_dispatch_request).run()
Note: See TracBrowser for help on using the repository browser.