source: package_branches/invirt-web/cherrypy-rebased/code/invirt.fcgi @ 3034

Last change on this file since 3034 was 2739, checked in by quentin, 15 years ago

Properly separate the auth.fcgi and unauth.fcgi scripts

  • Property svn:executable set to *
File size: 1.8 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%s/auth.fcgi [config]
17%s/unauth.fcgi [config]
18
19Run server as FastCGI, with CherryPy config from "main.conf".
20
21With `config`, run standalone with CherryPy config from `config`.
22
23Run this script as either 'auth.fcgi' or 'unauth.fcgi', to get
24the authenticated or unauthenticated site respectively, or pass
25'auth' or 'unauth' as the first parameter.
26""" % (sys.argv[0], argv0_dir, argv0_dir)
27    sys.exit(2)
28
29if __name__ == "__main__":
30    if len(sys.argv) > 3 or len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv:
31        usage()
32    if len(sys.argv) == 3:
33        mode = sys.argv[1]
34        conf_file = sys.argv[2]
35        dev = True
36    else:
37        mode = sys.argv[1]
38        conf_file = os.path.join(base_dir, 'main.conf')
39
40    app_config = {
41        '/': {
42            'tools.invirtwebstate.on': True,
43            },
44        }
45
46    if mode.startswith('auth'):
47        root = main.InvirtWeb()
48        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-auth-web-templatecache"
49    elif mode.startswith('unauth'):
50        root = main.InvirtUnauthWeb()
51        app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-unauth-web-templatecache"
52    else:
53        usage()
54
55    app = cherrypy.tree.mount(root, '/', app_config)
56    app.merge(conf_file)
57    cherrypy.config.update(conf_file)
58
59    if dev:
60        cherrypy.server.quickstart()
61        cherrypy.engine.start()
62        cherrypy.engine.block()
63    else:
64        cherrypy.engine.start(blocking=False)
65        from flup.server.fcgi import WSGIServer
66        server = WSGIServer(cherrypy.tree)
67        server.run()
Note: See TracBrowser for help on using the repository browser.