zoe-web.py 1.77 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 rpycconf
12

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


16 17 18 19 20 21 22 23 24
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')
    argparser.add_argument('--rpyc-server', default=None, help='Specify an RPyC server instead of using autodiscovery')
    argparser.add_argument('--rpyc-port', default=4000, type=int, help='Specify an RPyC server port, default is 4000')

    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 34
    else:
        logging.basicConfig(level=logging.INFO)
    logging.getLogger("requests").setLevel(logging.WARNING)
    logging.getLogger("tornado").setLevel(logging.WARNING)

    if args.rpyc_server is None:
35
        rpycconf['client_rpyc_autodiscovery'] = True
36
    else:
37 38 39
        rpycconf['client_rpyc_autodiscovery'] = False
        rpycconf['client_rpyc_server'] = args.rpyc_server
        rpycconf['client_rpyc_port'] = args.rpyc_port
40 41

    log.info("Starting HTTP server...")
42
    app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
43 44

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

53 54 55

if __name__ == "__main__":
    main()