zoe-web.py 1.66 KB
Newer Older
1 2
#!/usr/bin/env python3

3
import argparse
4 5 6
import logging
from tornado.wsgi import WSGIContainer
from tornado.httpserver import HTTPServer
7
from tornado.ioloop import IOLoop
8

9
from zoe_web import app
10

11
from common.configuration import ipcconf, init as conf_init
12

13
log = logging.getLogger("zoe_web")
14 15


16 17 18
def process_arguments() -> argparse.Namespace:
    argparser = argparse.ArgumentParser(description="Zoe Web - Container Analytics as a Service web client")
    argparser.add_argument('-d', '--debug', action='store_true', default=False, help='Enable debug output')
19 20
    argparser.add_argument('--ipc-server', default='localhost', help='Address of the Zoe scheduler process')
    argparser.add_argument('--ipc-port', default=8723, type=int, help='Port of the Zoe scheduler process')
21 22 23 24

    return argparser.parse_args()


25
def main():
26 27
    args = process_arguments()
    if args.debug:
28
        logging.basicConfig(level=logging.DEBUG)
29 30 31 32 33
    else:
        logging.basicConfig(level=logging.INFO)
    logging.getLogger("requests").setLevel(logging.WARNING)
    logging.getLogger("tornado").setLevel(logging.WARNING)

34 35
    ipcconf['server'] = args.ipc_server
    ipcconf['port'] = args.ipc_port
36

37 38
    zoeconf = conf_init()

39
    log.info("Starting HTTP server...")
40
    app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
41
    app.secret_key = zoeconf.cookies_secret_key
42 43

    http_server = HTTPServer(WSGIContainer(app))
44
    http_server.listen(5000, "0.0.0.0")
45
    ioloop = IOLoop.instance()
46 47 48 49 50
#    PeriodicCallback(email_task, int(conf["email_task_interval"]) * 1000).start()
    try:
        ioloop.start()
    except KeyboardInterrupt:
        print("CTRL-C detected, terminating")
51

52 53 54

if __name__ == "__main__":
    main()