def _initrp(conf_path, app_section, *args, **kwargs): try: # appconfig 是装饰后的 loadwsgi.appconfig() # conf是保存配置信息的字典,eg: # {'log_name': 'proxy_logging', 'log_headers': 'false', 'account_autocreate': 'true', # 'bind_port': '8080', '__file__': '/etc/swift/proxy-server.conf', # 'allow_account_management': 'true', 'log_address': '/dev/log', # 'here': '/etc/swift', 'log_facility': 'LOG_LOCAL1', 'user': '******', # '__name__': 'proxy-server', 'log_level': 'DEBUG'} conf = appconfig(conf_path, name=app_section) except Exception as e: raise ConfigFileError("Error trying to load config from %s: %s" % (conf_path, e)) validate_configuration() # pre-configure logger log_name = conf.get('log_name', app_section) if 'logger' in kwargs: logger = kwargs.pop('logger') else: #创建 logger 对象 logger = get_logger(conf, log_name, log_to_console=kwargs.pop('verbose', False), log_route='wsgi') # disable fallocate if desired if config_true_value(conf.get('disable_fallocate', 'no')): disable_fallocate() monkey_patch_mimetools() return (conf, logger, log_name)
def _initrp(conf_path, app_section, *args, **kwargs): try: conf = appconfig(conf_path, name=app_section) except Exception as e: raise ConfigFileError("Error trying to load config from %s: %s" % (conf_path, e)) validate_configuration() # pre-configure logger log_name = conf.get('log_name', app_section) if 'logger' in kwargs: logger = kwargs.pop('logger') else: logger = get_logger(conf, log_name, log_to_console=kwargs.pop('verbose', False), log_route='wsgi') # disable fallocate if desired if config_true_value(conf.get('disable_fallocate', 'no')): disable_fallocate() monkey_patch_mimetools() return (conf, logger, log_name)
def __init__(self, serialized_path, reload_time=15, ring_name=None): # can't use the ring unless HASH_PATH_SUFFIX is set validate_configuration() if ring_name: self.serialized_path = os.path.join(serialized_path, ring_name + ".ring.gz") else: self.serialized_path = os.path.join(serialized_path) self.reload_time = reload_time self._reload(force=True)
def __init__(self, serialized_path, reload_time=15, ring_name=None): # can't use the ring unless HASH_PATH_SUFFIX is set validate_configuration() if ring_name: self.serialized_path = os.path.join(serialized_path, ring_name + '.ring.gz') else: self.serialized_path = os.path.join(serialized_path) self.reload_time = reload_time self._reload(force=True)
def setup(self, **kwargs): utils.validate_configuration() utils.drop_privileges(self.daemon.conf.get('user', 'swift')) utils.capture_stdio(self.logger, **kwargs) def kill_children(*args): self.running = False self.logger.info('SIGTERM received') signal.signal(signal.SIGTERM, signal.SIG_IGN) os.killpg(0, signal.SIGTERM) os._exit(0) signal.signal(signal.SIGTERM, kill_children) self.running = True
def run(self, once=False, **kwargs): """Run the daemon""" utils.validate_configuration() utils.drop_privileges(self.conf.get('user', 'swift')) utils.capture_stdio(self.logger, **kwargs) def kill_children(*args): signal.signal(signal.SIGTERM, signal.SIG_IGN) os.killpg(0, signal.SIGTERM) sys.exit() signal.signal(signal.SIGTERM, kill_children) if once: self.run_once(**kwargs) else: self.run_forever(**kwargs)
def __init__(self, serialized_path, reload_time=None, ring_name=None, validation_hook=lambda ring_data: None): # can't use the ring unless HASH_PATH_SUFFIX is set validate_configuration() if ring_name: self.serialized_path = os.path.join(serialized_path, ring_name + '.ring.gz') else: self.serialized_path = os.path.join(serialized_path) self.reload_time = (DEFAULT_RELOAD_TIME if reload_time is None else reload_time) self._validation_hook = validation_hook self._reload(force=True)
def __init__(self, serialized_path, reload_time=15, ring_name=None, validation_hook=lambda ring_data: None): # can't use the ring unless HASH_PATH_SUFFIX is set # self.partFileDict = {} # self.partFileBufferSize = 0 validate_configuration() if ring_name: self.serialized_path = os.path.join(serialized_path, ring_name + '.ring.gz') else: self.serialized_path = os.path.join(serialized_path) self.reload_time = reload_time self._validation_hook = validation_hook self._reload(force=True)
def _initrp(conf_path, app_section, *args, **kwargs): try: conf = appconfig(conf_path, name=app_section) except Exception as e: raise ConfigFileError("Error trying to load config from %s: %s" % (conf_path, e)) validate_configuration() # pre-configure logger log_name = conf.get("log_name", app_section) if "logger" in kwargs: logger = kwargs.pop("logger") else: logger = get_logger(conf, log_name, log_to_console=kwargs.pop("verbose", False), log_route="wsgi") # disable fallocate if desired if config_true_value(conf.get("disable_fallocate", "no")): disable_fallocate() monkey_patch_mimetools() return (conf, logger, log_name)
def _initrp(conf_path, app_section, *args, **kwargs): try: conf = appconfig(conf_path, name=app_section) except Exception as e: raise ConfigFileError("Error trying to load config from %s: %s" % (conf_path, e)) validate_configuration() # pre-configure logger log_name = conf.get('log_name', app_section) if 'logger' in kwargs: logger = kwargs.pop('logger') else: logger = get_logger(conf, log_name, log_to_console=kwargs.pop('verbose', False), log_route='wsgi') # disable fallocate if desired if config_true_value(conf.get('disable_fallocate', 'no')): disable_fallocate() return (conf, logger, log_name)
# TODO: pull pieces of this out to test def run_wsgi(conf_file, app_section, *args, **kwargs): """ Loads common settings from conf, then instantiates app and runs the server using the specified number of workers. :param conf_file: Path to paste.deploy style configuration file :param app_section: App name from conf file to load config from """ try: conf = appconfig("config:%s" % conf_file, name=app_section) except Exception, e: print "Error trying to load config %s: %s" % (conf_file, e) return validate_configuration() # pre-configure logger log_name = conf.get("log_name", app_section) if "logger" in kwargs: logger = kwargs.pop("logger") else: logger = get_logger(conf, log_name, log_to_console=kwargs.pop("verbose", False), log_route="wsgi") # bind to address and port sock = get_socket(conf, default_port=kwargs.get("default_port", 8080)) # remaining tasks should not require elevated privileges drop_privileges(conf.get("user", "swift")) # Ensure the application can be loaded before proceeding. loadapp("config:%s" % conf_file, global_conf={"log_name": log_name})
Loads common settings from conf Sets the logger Loads the request processor :param conf_file: Path to paste.deploy style configuration file :param app_section: App name from conf file to load config from :returns the loaded application entry point :raises ConfigFileError: Exception is raised for config file error """ try: conf = appconfig('config:%s' % conf_file, name=app_section) except Exception, e: raise ConfigFileError("Error trying to load config %s: %s" % (conf_file, e)) validate_configuration() # pre-configure logger log_name = conf.get('log_name', app_section) if 'logger' in kwargs: logger = kwargs.pop('logger') else: logger = get_logger(conf, log_name, log_to_console=kwargs.pop('verbose', False), log_route='wsgi') # disable fallocate if desired if config_true_value(conf.get('disable_fallocate', 'no')): disable_fallocate()
def __init__(self, pickle_gz_path, reload_time=15): # can't use the ring unless HASH_PATH_SUFFIX is set validate_configuration() self.pickle_gz_path = pickle_gz_path self.reload_time = reload_time self._reload(force=True)