def __init__(self, options): # Launch reverse proxy start_proxy(options) make_dirs = [ os.path.dirname(os.path.abspath(options.access_log)), os.path.dirname(os.path.abspath(options.error_log)), os.path.dirname(os.path.abspath(config.get_object_store())) ] for directory in make_dirs: if not os.path.isdir(directory): os.makedirs(directory) self.configObj = WokConfig() # We'll use the session timeout (= 10 minutes) and the # nginx timeout (= 10 minutes). This monitor isn't involved # in anything other than monitor the timeout of the connection, # thus it is safe to unsubscribe. cherrypy.engine.timeout_monitor.unsubscribe() cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache) cherrypy.tools.wokauth = cherrypy.Tool('before_handler', auth.wokauth) # Setting host to 127.0.0.1. This makes wok run # as a localhost app, inaccessible to the outside # directly. You must go through the proxy. cherrypy.server.socket_host = '127.0.0.1' cherrypy.server.socket_port = options.cherrypy_port max_body_size_in_bytes = eval(options.max_body_size) * 1024 cherrypy.server.max_request_body_size = max_body_size_in_bytes cherrypy.log.access_file = options.access_log cherrypy.log.error_file = options.error_log logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG) dev_env = options.environment != 'production' # Enable cherrypy screen logging if running environment # is not 'production' if dev_env: cherrypy.log.screen = True # Create handler to rotate access log file h = logging.handlers.RotatingFileHandler(options.access_log, 'a', 10000000, 1000) h.setLevel(logLevel) h.setFormatter(cherrypy._cplogging.logfmt) # Add access log file to cherrypy configuration cherrypy.log.access_log.addHandler(h) # Create handler to rotate error log file h = logging.handlers.RotatingFileHandler(options.error_log, 'a', 10000000, 1000) h.setLevel(logLevel) h.setFormatter(cherrypy._cplogging.logfmt) # Add rotating log file to cherrypy configuration cherrypy.log.error_log.addHandler(h) # Handling running mode if not dev_env: cherrypy.config.update({'environment': 'production'}) if hasattr(options, 'model'): model_instance = options.model else: model_instance = model.Model() for ident, node in sub_nodes.items(): if node.url_auth: cfg = self.configObj ident = "/%s" % ident cfg[ident] = {'tools.wokauth.on': True} self.app = cherrypy.tree.mount(WokRoot(model_instance, dev_env), config=self.configObj) self._load_plugins(options) # Terminate proxy when cherrypy server is terminated cherrypy.engine.subscribe('exit', terminate_proxy) cherrypy.lib.sessions.init()
def __init__(self, options): # Launch reverse proxy start_proxy(options) make_dirs = [ os.path.abspath(config.get_log_download_path()), os.path.abspath(configParser.get("logging", "log_dir")), os.path.dirname(os.path.abspath(options.access_log)), os.path.dirname(os.path.abspath(options.error_log)), os.path.dirname(os.path.abspath(config.get_object_store())) ] for directory in make_dirs: if not os.path.isdir(directory): os.makedirs(directory) self.configObj = WokConfig() # We'll use the session timeout (= 10 minutes) and the # nginx timeout (= 10 minutes). This monitor isn't involved # in anything other than monitor the timeout of the connection, # thus it is safe to unsubscribe. cherrypy.engine.timeout_monitor.unsubscribe() cherrypy.tools.nocache = cherrypy.Tool('on_end_resource', set_no_cache) cherrypy.tools.wokauth = cherrypy.Tool('before_handler', auth.wokauth) # Setting host to 127.0.0.1. This makes wok run # as a localhost app, inaccessible to the outside # directly. You must go through the proxy. cherrypy.server.socket_host = '127.0.0.1' cherrypy.server.socket_port = options.cherrypy_port max_body_size_in_bytes = eval(options.max_body_size) * 1024 cherrypy.server.max_request_body_size = max_body_size_in_bytes cherrypy.log.access_file = options.access_log cherrypy.log.error_file = options.error_log logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG) dev_env = options.environment != 'production' # Enable cherrypy screen logging if running environment # is not 'production' if dev_env: cherrypy.log.screen = True # close standard file handlers because we are going to use a # watchedfiled handler, otherwise we will have two file handlers # pointing to the same file, duplicating log enries for handler in cherrypy.log.access_log.handlers[:]: if isinstance(handler, logging.FileHandler): cherrypy.log.access_log.removeHandler(handler) for handler in cherrypy.log.error_log.handlers[:]: if isinstance(handler, logging.FileHandler): cherrypy.log.error_log.removeHandler(handler) # Create handler to access log file h = logging.handlers.WatchedFileHandler(options.access_log, 'a', delay=1) h.setLevel(logLevel) h.setFormatter(cherrypy._cplogging.logfmt) # Add access log file to cherrypy configuration cherrypy.log.access_log.addHandler(h) # Create handler to error log file h = SafeWatchedFileHandler(options.error_log, 'a', delay=1) h.setLevel(logLevel) h.setFormatter(cherrypy._cplogging.logfmt) # Add error log file to cherrypy configuration cherrypy.log.error_log.addHandler(h) # start request logger self.reqLogger = RequestLogger() # only add logrotate if wok is installed if paths.installed: # redefine logrotate configuration according to wok.conf data = Template(LOGROTATE_TEMPLATE) data = data.safe_substitute( log_dir=configParser.get("logging", "log_dir"), log_size=configParser.get("logging", "log_size") ) # Write file to be used for nginx. config_file = open(os.path.join(paths.logrotate_dir, "wokd"), "w") config_file.write(data) config_file.close() # Handling running mode if not dev_env: cherrypy.config.update({'environment': 'production'}) if hasattr(options, 'model'): model_instance = options.model else: model_instance = model.Model() for ident, node in sub_nodes.items(): if node.url_auth: cfg = self.configObj ident = "/%s" % ident cfg[ident] = {'tools.wokauth.on': True} self.app = cherrypy.tree.mount(WokRoot(model_instance, dev_env), config=self.configObj) self._load_plugins(options) # Terminate proxy when cherrypy server is terminated cherrypy.engine.subscribe('exit', terminate_proxy) cherrypy.lib.sessions.init()
def __init__(self, options): # Launch reverse proxy start_proxy(options) make_dirs = [ os.path.abspath(config.get_log_download_path()), os.path.abspath(configParser.get("logging", "log_dir")), os.path.dirname(os.path.abspath(options.access_log)), os.path.dirname(os.path.abspath(options.error_log)), os.path.dirname(os.path.abspath(config.get_object_store())), ] for directory in make_dirs: if not os.path.isdir(directory): os.makedirs(directory) self.configObj = WokConfig() # We'll use the session timeout (= 10 minutes) and the # nginx timeout (= 10 minutes). This monitor isn't involved # in anything other than monitor the timeout of the connection, # thus it is safe to unsubscribe. cherrypy.engine.timeout_monitor.unsubscribe() cherrypy.tools.nocache = cherrypy.Tool("on_end_resource", set_no_cache) cherrypy.tools.wokauth = cherrypy.Tool("before_handler", auth.wokauth) # Setting host to 127.0.0.1. This makes wok run # as a localhost app, inaccessible to the outside # directly. You must go through the proxy. cherrypy.server.socket_host = "127.0.0.1" cherrypy.server.socket_port = options.cherrypy_port max_body_size_in_bytes = eval(options.max_body_size) * 1024 cherrypy.server.max_request_body_size = max_body_size_in_bytes cherrypy.log.access_file = options.access_log cherrypy.log.error_file = options.error_log logLevel = LOGGING_LEVEL.get(options.log_level, logging.DEBUG) dev_env = options.environment != "production" # Enable cherrypy screen logging if running environment # is not 'production' if dev_env: cherrypy.log.screen = True # close standard file handlers because we are going to use a # watchedfiled handler, otherwise we will have two file handlers # pointing to the same file, duplicating log enries for handler in cherrypy.log.access_log.handlers[:]: if isinstance(handler, logging.FileHandler): cherrypy.log.access_log.removeHandler(handler) for handler in cherrypy.log.error_log.handlers[:]: if isinstance(handler, logging.FileHandler): cherrypy.log.error_log.removeHandler(handler) # Create handler to access log file h = logging.handlers.WatchedFileHandler(options.access_log, "a", delay=1) h.setLevel(logLevel) h.setFormatter(cherrypy._cplogging.logfmt) # Add access log file to cherrypy configuration cherrypy.log.access_log.addHandler(h) # Create handler to error log file h = SafeWatchedFileHandler(options.error_log, "a", delay=1) h.setLevel(logLevel) h.setFormatter(cherrypy._cplogging.logfmt) # Add error log file to cherrypy configuration cherrypy.log.error_log.addHandler(h) # start request logger self.reqLogger = RequestLogger() # only add logrotate if wok is installed if paths.installed: # redefine logrotate configuration according to wok.conf logrotate_file = os.path.join(paths.logrotate_dir, "wokd.in") with open(logrotate_file) as template: data = template.read() data = Template(data) data = data.safe_substitute(log_dir=configParser.get("logging", "log_dir")) # Write file to be used for nginx. config_file = open(os.path.join(paths.logrotate_dir, "wokd"), "w") config_file.write(data) config_file.close() # Handling running mode if not dev_env: cherrypy.config.update({"environment": "production"}) if hasattr(options, "model"): model_instance = options.model else: model_instance = model.Model() for ident, node in sub_nodes.items(): if node.url_auth: cfg = self.configObj ident = "/%s" % ident cfg[ident] = {"tools.wokauth.on": True} self.app = cherrypy.tree.mount(WokRoot(model_instance, dev_env), config=self.configObj) self._load_plugins(options) # Terminate proxy when cherrypy server is terminated cherrypy.engine.subscribe("exit", terminate_proxy) cherrypy.lib.sessions.init()