[579] | 1 | #!/usr/bin/python |
---|
[2660] | 2 | """Main FastCGI entry point for web interface""" |
---|
| 3 | |
---|
| 4 | import cherrypy |
---|
| 5 | import os |
---|
| 6 | import sys |
---|
[2692] | 7 | from main import InvirtWeb, InvirtUnauthWeb |
---|
[2660] | 8 | |
---|
| 9 | dev = False |
---|
| 10 | base_dir = os.path.dirname(__file__) |
---|
| 11 | |
---|
[2702] | 12 | def usage(): |
---|
| 13 | print >>sys.stderr, """%s [config] |
---|
| 14 | |
---|
| 15 | Run server as FastCGI, with CherryPy config from "main.conf". |
---|
| 16 | |
---|
| 17 | With `config`, run standalone with CherryPy config from `config`. |
---|
| 18 | """ % sys.argv[0] |
---|
| 19 | sys.exit(2) |
---|
| 20 | |
---|
| 21 | if __name__ == "__main__": |
---|
[2661] | 22 | static_dir = os.path.join(base_dir, 'static') |
---|
| 23 | |
---|
[2702] | 24 | if len(sys.argv) > 2: |
---|
| 25 | usage() |
---|
[2660] | 26 | if len(sys.argv) > 1: |
---|
[2702] | 27 | if sys.argv[1] in ('-h', '--help'): |
---|
| 28 | usage() |
---|
[2660] | 29 | conf_file = sys.argv[1] |
---|
| 30 | dev = True |
---|
| 31 | else: |
---|
| 32 | conf_file = os.path.join(base_dir, 'main.conf') |
---|
[2661] | 33 | app = cherrypy.tree.mount(InvirtWeb(), |
---|
[2681] | 34 | '/', |
---|
[2669] | 35 | {'/': {'tools.staticdir.root': static_dir, |
---|
| 36 | 'tools.invirtwebstate.on': True}, |
---|
[2661] | 37 | '/static': {'tools.staticdir.on': True, |
---|
| 38 | 'tools.staticdir.dir': static_dir} |
---|
| 39 | }) |
---|
[2660] | 40 | app.merge(conf_file) |
---|
[2692] | 41 | unauthApp = cherrypy.tree.mount(InvirtUnauthWeb(), |
---|
| 42 | '/unauth', |
---|
| 43 | {'/': {'tools.invirtwebstate.on': True}}) |
---|
| 44 | unauthApp.merge(conf_file) |
---|
[2660] | 45 | cherrypy.config.update(conf_file) |
---|
| 46 | |
---|
| 47 | if dev: |
---|
| 48 | cherrypy.server.quickstart() |
---|
| 49 | cherrypy.engine.start() |
---|
| 50 | cherrypy.engine.block() |
---|
| 51 | else: |
---|
| 52 | cherrypy.engine.start(blocking=False) |
---|
| 53 | from flup.server.fcgi import WSGIServer |
---|
[2692] | 54 | server = WSGIServer(cherrypy.tree) |
---|
[2660] | 55 | server.run() |
---|