source: trunk/packages/invirt-web/code/invirt.fcgi @ 3052

Last change on this file since 3052 was 2993, checked in by broder, 15 years ago

Clear all objects from the SQLAlchemy session at the start of each request.

The SA identity mapper isn't *supposed* to be a cache, but it sure can
act like one sometimes.

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/usr/bin/python
2"""Main FastCGI entry point for web interface"""
3
4import cherrypy
5import os
6import sys
7
8import main
9
10dev = False
11base_dir = os.path.dirname(__file__)
12
13def usage():
14    argv0_dir = os.path.dirname(sys.argv[0])
15    print >>sys.stderr, """%s <unauth|auth> [config]
16
17Or via the provided wrapper scripts:
18%s/auth.fcgi [config]
19%s/unauth.fcgi [config]
20
21Run server as FastCGI, with CherryPy config from "main.conf".
22With `config`, run standalone with CherryPy config from `config`.
23
24Serve the authenticated site with 'auth' or under 'auth.fcgi',
25and the unauthenticated site with 'unauth' or under 'unauth.fcgi'.
26""" % (sys.argv[0], argv0_dir, argv0_dir)
27    sys.exit(2)
28
29if __name__ == "__main__":
30    if '-h' in sys.argv or '--help' in sys.argv:
31        usage()
32    if not (2 <= len(sys.argv) <= 3):
33        usage()
34
35    mode = sys.argv[1]
36    if len(sys.argv) == 3:
37        conf_file = sys.argv[2]
38        dev = True
39    else:
40        conf_file = os.path.join(base_dir, 'main.conf')
41
42    app_config = {
43        '/': {
44            'tools.invirtwebstate.on': True,
45            'tools.clear_db_cache.on': True,
46            },
47        }
48
49    if mode.startswith('auth'):
50        root = main.InvirtWeb()
51        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-auth-web-templatecache"
52    elif mode.startswith('unauth'):
53        root = main.InvirtUnauthWeb()
54        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-unauth-web-templatecache"
55    else:
56        usage()
57
58    app = cherrypy.tree.mount(root, '/', app_config)
59    app.merge(conf_file)
60    cherrypy.config.update(conf_file)
61
62    if dev:
63        cherrypy.server.quickstart()
64        cherrypy.engine.start()
65        cherrypy.engine.block()
66    else:
67        cherrypy.engine.start(blocking=False)
68        from flup.server.fcgi import WSGIServer
69        server = WSGIServer(cherrypy.tree)
70        server.run()
Note: See TracBrowser for help on using the repository browser.