[579] | 1 | #!/usr/bin/python |
---|
[2733] | 2 | """Main FastCGI entry point for web interface""" |
---|
[2660] | 3 | |
---|
| 4 | import cherrypy |
---|
| 5 | import os |
---|
| 6 | import sys |
---|
| 7 | |
---|
[2733] | 8 | import main |
---|
| 9 | |
---|
[2660] | 10 | dev = False |
---|
| 11 | base_dir = os.path.dirname(__file__) |
---|
| 12 | |
---|
[2702] | 13 | def usage(): |
---|
[2740] | 14 | argv0_dir = os.path.dirname(sys.argv[0]) |
---|
| 15 | print >>sys.stderr, """%s <unauth|auth> [config] |
---|
[2702] | 16 | |
---|
[2743] | 17 | Or via the provided wrapper scripts: |
---|
| 18 | %s/auth.fcgi [config] |
---|
| 19 | %s/unauth.fcgi [config] |
---|
| 20 | |
---|
[2702] | 21 | Run server as FastCGI, with CherryPy config from "main.conf". |
---|
| 22 | With `config`, run standalone with CherryPy config from `config`. |
---|
[2733] | 23 | |
---|
[2743] | 24 | Serve the authenticated site with 'auth' or under 'auth.fcgi', |
---|
| 25 | and the unauthenticated site with 'unauth' or under 'unauth.fcgi'. |
---|
| 26 | """ % (sys.argv[0], argv0_dir, argv0_dir) |
---|
[2702] | 27 | sys.exit(2) |
---|
| 28 | |
---|
| 29 | if __name__ == "__main__": |
---|
[2741] | 30 | if '-h' in sys.argv or '--help' in sys.argv: |
---|
[2702] | 31 | usage() |
---|
[2741] | 32 | if not (2 <= len(sys.argv) <= 3): |
---|
| 33 | usage() |
---|
| 34 | |
---|
| 35 | mode = sys.argv[1] |
---|
[2740] | 36 | if len(sys.argv) == 3: |
---|
| 37 | conf_file = sys.argv[2] |
---|
[2660] | 38 | dev = True |
---|
| 39 | else: |
---|
| 40 | conf_file = os.path.join(base_dir, 'main.conf') |
---|
[2728] | 41 | |
---|
| 42 | app_config = { |
---|
| 43 | '/': { |
---|
| 44 | 'tools.invirtwebstate.on': True, |
---|
[2993] | 45 | 'tools.clear_db_cache.on': True, |
---|
[2728] | 46 | }, |
---|
| 47 | } |
---|
[2733] | 48 | |
---|
[2740] | 49 | if mode.startswith('auth'): |
---|
[2734] | 50 | root = main.InvirtWeb() |
---|
[2740] | 51 | app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-auth-web-templatecache" |
---|
| 52 | elif mode.startswith('unauth'): |
---|
[2734] | 53 | root = main.InvirtUnauthWeb() |
---|
[2740] | 54 | app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-unauth-web-templatecache" |
---|
[2733] | 55 | else: |
---|
| 56 | usage() |
---|
| 57 | |
---|
| 58 | app = cherrypy.tree.mount(root, '/', app_config) |
---|
[2729] | 59 | app.merge(conf_file) |
---|
[2660] | 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 |
---|
[2692] | 69 | server = WSGIServer(cherrypy.tree) |
---|
[2660] | 70 | server.run() |
---|