[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(): |
---|
[2739] | 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] |
---|
[2702] | 18 | |
---|
| 19 | Run server as FastCGI, with CherryPy config from "main.conf". |
---|
| 20 | |
---|
| 21 | With `config`, run standalone with CherryPy config from `config`. |
---|
[2733] | 22 | |
---|
| 23 | Run this script as either 'auth.fcgi' or 'unauth.fcgi', to get |
---|
[2739] | 24 | the authenticated or unauthenticated site respectively, or pass |
---|
| 25 | 'auth' or 'unauth' as the first parameter. |
---|
| 26 | """ % (sys.argv[0], argv0_dir, argv0_dir) |
---|
[2702] | 27 | sys.exit(2) |
---|
| 28 | |
---|
| 29 | if __name__ == "__main__": |
---|
[2739] | 30 | if len(sys.argv) > 3 or len(sys.argv) == 1 or '-h' in sys.argv or '--help' in sys.argv: |
---|
[2702] | 31 | usage() |
---|
[2739] | 32 | if len(sys.argv) == 3: |
---|
| 33 | mode = sys.argv[1] |
---|
| 34 | conf_file = sys.argv[2] |
---|
[2660] | 35 | dev = True |
---|
| 36 | else: |
---|
[2739] | 37 | mode = sys.argv[1] |
---|
[2660] | 38 | conf_file = os.path.join(base_dir, 'main.conf') |
---|
[2728] | 39 | |
---|
| 40 | app_config = { |
---|
| 41 | '/': { |
---|
| 42 | 'tools.invirtwebstate.on': True, |
---|
| 43 | }, |
---|
| 44 | } |
---|
[2733] | 45 | |
---|
[2739] | 46 | if mode.startswith('auth'): |
---|
[2734] | 47 | root = main.InvirtWeb() |
---|
[2739] | 48 | app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-auth-web-templatecache" |
---|
| 49 | elif mode.startswith('unauth'): |
---|
[2734] | 50 | root = main.InvirtUnauthWeb() |
---|
[2739] | 51 | app_config['/']['tools.mako.module_directory'] = "/tmp/invirt-unauth-web-templatecache" |
---|
[2733] | 52 | else: |
---|
| 53 | usage() |
---|
| 54 | |
---|
| 55 | app = cherrypy.tree.mount(root, '/', app_config) |
---|
[2729] | 56 | app.merge(conf_file) |
---|
[2660] | 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 |
---|
[2692] | 66 | server = WSGIServer(cherrypy.tree) |
---|
[2660] | 67 | server.run() |
---|