def main(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning("Application started without configuration file.\n" "This is normal only during development") custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "templates")), static_path=os.path.join(os.path.dirname(__file__), os.path.join("web/frontend", "static")), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings) sockjs_settings = custom_settings.get("sockjs_settings", {}) handlers = create_application_handlers(sockjs_settings) try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) logger.info("Engine class: {0}".format(engine_class_path)) app.engine = engine_class(app) logger.info("Storage class: {0}".format(storage_class_path)) app.storage = storage_class(options) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app app.initialize() max_channel_length = custom_settings.get('max_channel_length') if max_channel_length: app.MAX_CHANNEL_LENGTH = max_channel_length admin_api_message_limit = custom_settings.get('admin_api_message_limit') if admin_api_message_limit: app.ADMIN_API_MESSAGE_LIMIT = admin_api_message_limit client_api_message_limit = custom_settings.get('client_api_message_limit') if client_api_message_limit: app.CLIENT_API_MESSAGE_LIMIT = client_api_message_limit owner_api_project_id = custom_settings.get('owner_api_project_id') if owner_api_project_id: app.OWNER_API_PROJECT_ID = owner_api_project_id owner_api_project_param = custom_settings.get('owner_api_project_param') if owner_api_project_param: app.OWNER_API_PROJECT_PARAM = owner_api_project_param connection_expire_check = custom_settings.get('connection_expire_check', True) if connection_expire_check: app.CONNECTION_EXPIRE_CHECK = connection_expire_check connection_expire_collect_interval = custom_settings.get( 'connection_expire_collect_interval') if connection_expire_collect_interval: app.CONNECTION_EXPIRE_COLLECT_INTERVAL = connection_expire_collect_interval connection_expire_check_interval = custom_settings.get( 'connection_expire_check_interval') if connection_expire_check_interval: app.CONNECTION_EXPIRE_CHECK_INTERVAL = connection_expire_check_interval logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # cleaning if hasattr(app.engine, 'clean'): app.engine.clean()
def main(): try: custom_settings = json.load(open(options.config, 'r')) except IOError: logger.warning( "Application started without configuration file.\n" "This is normal only during development" ) custom_settings = {} ioloop_instance = tornado.ioloop.IOLoop.instance() settings = dict( cookie_secret=custom_settings.get("cookie_secret", "bad secret"), login_url="/auth", template_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "templates") ), static_path=os.path.join( os.path.dirname(__file__), os.path.join("web/frontend", "static") ), xsrf_cookies=True, autoescape="xhtml_escape", debug=options.debug, options=options, config=custom_settings ) sockjs_settings = custom_settings.get("sockjs_settings", {}) handlers = create_application_handlers(sockjs_settings) try: app = Application(handlers=handlers, **settings) server = tornado.httpserver.HTTPServer(app) server.listen(options.port) except Exception as e: return stop_running(str(e)) logger.info("Engine class: {0}".format(engine_class_path)) app.engine = engine_class(app) logger.info("Storage class: {0}".format(storage_class_path)) app.storage = storage_class(options) # create references to application from SockJS handlers AdminSocketHandler.application = app Client.application = app app.initialize() max_channel_length = custom_settings.get('max_channel_length') if max_channel_length: app.MAX_CHANNEL_LENGTH = max_channel_length admin_api_message_limit = custom_settings.get('admin_api_message_limit') if admin_api_message_limit: app.ADMIN_API_MESSAGE_LIMIT = admin_api_message_limit client_api_message_limit = custom_settings.get('client_api_message_limit') if client_api_message_limit: app.CLIENT_API_MESSAGE_LIMIT = client_api_message_limit owner_api_project_id = custom_settings.get('owner_api_project_id') if owner_api_project_id: app.OWNER_API_PROJECT_ID = owner_api_project_id owner_api_project_param = custom_settings.get('owner_api_project_param') if owner_api_project_param: app.OWNER_API_PROJECT_PARAM = owner_api_project_param connection_expire_check = custom_settings.get('connection_expire_check', True) if connection_expire_check: app.CONNECTION_EXPIRE_CHECK = connection_expire_check connection_expire_collect_interval = custom_settings.get('connection_expire_collect_interval') if connection_expire_collect_interval: app.CONNECTION_EXPIRE_COLLECT_INTERVAL = connection_expire_collect_interval connection_expire_check_interval = custom_settings.get('connection_expire_check_interval') if connection_expire_check_interval: app.CONNECTION_EXPIRE_CHECK_INTERVAL = connection_expire_check_interval logger.info("Tornado port: {0}".format(options.port)) # finally, let's go try: ioloop_instance.start() except KeyboardInterrupt: logger.info('interrupted') finally: # cleaning if hasattr(app.engine, 'clean'): app.engine.clean()