1 | #!/usr/bin/python |
---|
2 | |
---|
3 | import os, os.path, sys |
---|
4 | from trac.web import fcgi_frontend |
---|
5 | |
---|
6 | env_path = os.getcwd()+'/tracdata' |
---|
7 | os.environ['TRAC_ENV'] = env_path |
---|
8 | |
---|
9 | def 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 | |
---|
15 | From an Athena machine, type |
---|
16 | ssh %s@scripts trac-admin %s upgrade --no-backup |
---|
17 | ssh %s@scripts trac-admin %s wiki upgrade |
---|
18 | to upgrade, and then |
---|
19 | add scripts |
---|
20 | for-each-server -l %s pkill trac.fcgi |
---|
21 | to get this message out of the way. |
---|
22 | |
---|
23 | Please ask the scripts.mit.edu maintainers for help |
---|
24 | if you have any trouble, at scripts@mit.edu. |
---|
25 | ''' % (locker, env_path, locker, env_path, locker)] |
---|
26 | |
---|
27 | def 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 |
---|
43 | setup_env() |
---|
44 | |
---|
45 | def 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 | |
---|
51 | fcgi_frontend._fcgi.WSGIServer(my_dispatch_request).run() |
---|