def load_from_config(cls, config): if 'env' in config: config['env'] = parse_env_dict(config['env']) cfg = config.copy() w = cls(name=config.pop('name'), cmd=config.pop('cmd'), **config) w._cfg = cfg return w
def load_from_config(cls, config): if "env" in config: config["env"] = parse_env_dict(config["env"]) cfg = config.copy() w = cls(name=config.pop("name"), cmd=config.pop("cmd"), **config) w._cfg = cfg return w
def convert_option(key, val): if key == "numprocesses": return int(val) elif key == "warmup_delay": return float(val) elif key == "working_dir": return val elif key == "uid": return val elif key == "gid": return val elif key == "send_hup": return util.to_bool(val) elif key == "shell": return util.to_bool(val) elif key == "copy_env": return util.to_bool(val) elif key == "env": return util.parse_env_dict(val) elif key == "cmd": return val elif key == "flapping_attempts": return int(val) elif key == "flapping_window": return float(val) elif key == "retry_in": return float(val) elif key == "max_retry": return int(val) elif key == "graceful_timeout": return float(val) elif key == 'max_age': return int(val) elif key == 'max_age_variance': return int(val) elif key == 'respawn': return util.to_bool(val) elif key.startswith('stderr_stream.') or key.startswith('stdout_stream.'): subkey = key.split('.', 1)[-1] if subkey in ('class', 'filename'): return val elif subkey in ('max_bytes', 'backup_count'): return int(val) elif subkey == 'refresh_time': # Deprecated but warning below return elif key.startswith('hooks.'): subkey = key.split('.', 1)[-1] if subkey in ('before_start', 'after_start', 'before_stop', 'after_stop', 'before_spawn'): return val raise ArgumentError("unknown key %r" % key)
def load_from_config(cls, config): cfgdict = cls.cfg2dict(config) if 'env' in config: config['env'] = parse_env_dict(config['env']) w = cls(name=config.pop('name'), cmd=config.pop('cmd'), **config) # store config for checking later if config has changed w.cfg = cfgdict return w
def convert_option(key, val): if key == "numprocesses": return int(val) elif key == "warmup_delay": return float(val) elif key == "working_dir": return val elif key == "uid": return val elif key == "gid": return val elif key == "send_hup": return util.to_bool(val) elif key == "shell": return util.to_bool(val) elif key == "copy_env": return util.to_bool(val) elif key == "env": return util.parse_env_dict(val) elif key == "cmd": return val elif key == "flapping_attempts": return int(val) elif key == "flapping_window": return float(val) elif key == "retry_in": return float(val) elif key == "max_retry": return int(val) elif key == "graceful_timeout": return float(val) elif key == 'max_age': return int(val) elif key == 'max_age_variance': return int(val) elif key == 'respawn': return util.to_bool(val) elif key.startswith('stderr_stream.') or key.startswith('stdout_stream.'): subkey = key.split('.', 1)[-1] if subkey in ('max_bytes', 'backup_count'): return int(val) return val elif key.startswith('hooks.'): subkey = key.split('.', 1)[-1] if subkey in ('before_start', 'after_start', 'before_stop', 'after_stop', 'before_spawn'): return val raise ArgumentError("unknown key %r" % key)
def convert_option(key, val): if key == "numprocesses": return int(val) elif key == "warmup_delay": return float(val) elif key == "working_dir": return val elif key == "uid": return val elif key == "gid": return val elif key == "send_hup": return util.to_bool(val) elif key == "shell": return util.to_bool(val) elif key == "copy_env": return util.to_bool(val) elif key == "env": return util.parse_env_dict(val) elif key == "cmd": return val elif key == "flapping_attempts": return int(val) elif key == "flapping_window": return float(val) elif key == "retry_in": return float(val) elif key == "max_retry": return int(val) elif key == "graceful_timeout": return float(val) elif key == 'max_age': return int(val) elif key == 'max_age_variance': return int(val) elif key == 'respawn': return util.to_bool(val) raise ArgumentError("unknown key %r" % key)
def convert_option(key, val): if key == "numprocesses": return int(val) elif key == "warmup_delay": return float(val) elif key == "working_dir": return val elif key == "uid": return val elif key == "gid": return val elif key == "send_hup": return util.to_bool(val) elif key == "shell": return util.to_bool(val) elif key == "copy_env": return util.to_bool(val) elif key == "env": return util.parse_env_dict(val) elif key == "cmd": return val elif key == "flapping_attempts": return int(val) elif key == "flapping_window": return float(val) elif key == "retry_in": return float(val) elif key == "max_retry": return int(val) elif key == "graceful_timeout": return float(val) elif key == 'max_age': return int(val) elif key == 'max_age_variance': return int(val) raise ArgumentError("unknown key %r" % key)
def load_from_config(cls, config, **extras): if 'env' in config: config['env'] = parse_env_dict(config['env']) config.update(extras) return cls(name=config.pop('name'), cmd=config.pop('cmd'), **config)
def reload_from_config(self, config_file=None, inside_circusd=False): new_cfg = get_config(config_file if config_file else self.config_file) # if arbiter is changed, reload everything if self.get_arbiter_config(new_cfg) != self._cfg: yield self._restart(inside_circusd=inside_circusd) return ignore_sn = set(['circushttpd']) ignore_wn = set(['circushttpd', 'circusd-stats']) # Gather socket names. current_sn = set([i.name for i in self.sockets.values()]) - ignore_sn new_sn = set([i['name'] for i in new_cfg.get('sockets', [])]) added_sn = new_sn - current_sn deleted_sn = current_sn - new_sn maybechanged_sn = current_sn - deleted_sn changed_sn = set([]) wn_with_changed_socket = set([]) wn_with_deleted_socket = set([]) # get changed sockets for n in maybechanged_sn: s = self.get_socket(n) if self.get_socket_config(new_cfg, n) != s._cfg: changed_sn.add(n) # just delete the socket and add it again deleted_sn.add(n) added_sn.add(n) # Get the watchers whichs use these, so they could be # deleted and added also for w in self.iter_watchers(): if 'circus.sockets.%s' % n.lower() in w.cmd: wn_with_changed_socket.add(w.name) # get deleted sockets for n in deleted_sn: s = self.get_socket(n) s.close() # Get the watchers whichs use these, these should not be # active anymore for w in self.iter_watchers(): if 'circus.sockets.%s' % n.lower() in w.cmd: wn_with_deleted_socket.add(w.name) del self.sockets[s.name] # get added sockets for n in added_sn: socket_config = self.get_socket_config(new_cfg, n) s = CircusSocket.load_from_config(socket_config) s.bind_and_listen() self.sockets[s.name] = s if added_sn or deleted_sn: # make sure all existing watchers get the new sockets in # their attributes and get the old removed # XXX: is this necessary? self.sockets is an mutable # object for watcher in self.iter_watchers(): # XXX: What happens as initalize is called on a # running watcher? watcher.initialize(self.evpub_socket, self.sockets, self) # Gather watcher names. current_wn = set([i.name for i in self.iter_watchers()]) - ignore_wn new_wn = set([i['name'] for i in new_cfg.get('watchers', [])]) new_wn = new_wn | set([i['name'] for i in new_cfg.get('plugins', [])]) added_wn = (new_wn - current_wn) | wn_with_changed_socket deleted_wn = current_wn - new_wn - wn_with_changed_socket maybechanged_wn = current_wn - deleted_wn changed_wn = set([]) if wn_with_deleted_socket and wn_with_deleted_socket not in new_wn: raise ValueError('Watchers %s uses a socket which is deleted' % wn_with_deleted_socket) # get changed watchers for n in maybechanged_wn: w = self.get_watcher(n) new_watcher_cfg = (self.get_watcher_config(new_cfg, n) or self.get_plugin_config(new_cfg, n)) old_watcher_cfg = w._cfg.copy() if 'env' in new_watcher_cfg: new_watcher_cfg['env'] = parse_env_dict(new_watcher_cfg['env']) # discarding env exceptions for key in _ENV_EXCEPTIONS: if 'env' in new_watcher_cfg and key in new_watcher_cfg['env']: del new_watcher_cfg['env'][key] if 'env' in new_watcher_cfg and key in old_watcher_cfg['env']: del old_watcher_cfg['env'][key] diff = DictDiffer(new_watcher_cfg, old_watcher_cfg).changed() if diff == set(['numprocesses']): # if nothing but the number of processes is # changed, just changes this w.set_numprocesses(int(new_watcher_cfg['numprocesses'])) changed = False else: changed = len(diff) > 0 if changed: # Others things are changed. Just delete and add the watcher. changed_wn.add(n) deleted_wn.add(n) added_wn.add(n) # delete watchers for n in deleted_wn: w = self.get_watcher(n) yield w._stop() del self._watchers_names[w.name.lower()] self.watchers.remove(w) # add watchers for n in added_wn: new_watcher_cfg = (self.get_plugin_config(new_cfg, n) or self.get_watcher_config(new_cfg, n)) w = Watcher.load_from_config(new_watcher_cfg) w.initialize(self.evpub_socket, self.sockets, self) yield self.start_watcher(w) self.watchers.append(w) self._watchers_names[w.name.lower()] = w
def convert_option(key, val): if key == "numprocesses": return int(val) elif key == "warmup_delay": return float(val) elif key == "working_dir": return val elif key == "uid": return val elif key == "gid": return val elif key == "send_hup": return util.to_bool(val) elif key == "stop_signal": return util.to_signum(val) elif key == "stop_children": return util.to_bool(val) elif key == "shell": return util.to_bool(val) elif key == "copy_env": return util.to_bool(val) elif key == "env": return util.parse_env_dict(val) elif key == "cmd": return val elif key == "args": return val elif key == "retry_in": return float(val) elif key == "max_retry": return int(val) elif key == "graceful_timeout": return float(val) elif key == 'max_age': return int(val) elif key == 'max_age_variance': return int(val) elif key == 'respawn': return util.to_bool(val) elif key == "singleton": return util.to_bool(val) elif key.startswith('stderr_stream.') or key.startswith('stdout_stream.'): subkey = key.split('.', 1)[-1] if subkey in ('max_bytes', 'backup_count'): return int(val) return val elif key == 'hooks': res = {} for hook in val.split(','): if hook == '': continue hook = hook.split(':') if len(hook) != 2: raise ArgumentError(hook) name, value = hook if name not in _HOOKS: raise ArgumentError(name) res[name] = value return res elif key.startswith('hooks.'): # we can also set a single hook name = key.split('.', 1)[-1] if name not in _HOOKS: raise ArgumentError(name) return val elif key.startswith('rlimit_'): return int(val) raise ArgumentError("unknown key %r" % key)
def convert_option(key, val): if key == "numprocesses": return int(val) elif key == "warmup_delay": return float(val) elif key == "working_dir": return val elif key == "uid": return val elif key == "gid": return val elif key == "send_hup": return util.to_bool(val) elif key == "shell": return util.to_bool(val) elif key == "copy_env": return util.to_bool(val) elif key == "env": return util.parse_env_dict(val) elif key == "cmd": return val elif key == "flapping_attempts": return int(val) elif key == "flapping_window": return float(val) elif key == "retry_in": return float(val) elif key == "max_retry": return int(val) elif key == "graceful_timeout": return float(val) elif key == 'max_age': return int(val) elif key == 'max_age_variance': return int(val) elif key == 'respawn': return util.to_bool(val) elif key.startswith('stderr_stream.') or key.startswith('stdout_stream.'): subkey = key.split('.', 1)[-1] if subkey in ('max_bytes', 'backup_count'): return int(val) return val elif key == 'hooks': res = {} for hook in val.split(','): if hook == '': continue hook = hook.split(':') if len(hook) != 2: raise ArgumentError(hook) name, value = hook if name not in _HOOKS: raise ArgumentError(name) res[name] = value return res elif key.startswith('hooks.'): # we can also set a single hook name = key.split('.', 1)[-1] if name not in _HOOKS: raise ArgumentError(name) return val raise ArgumentError("unknown key %r" % key)
def convert_option(key, val): if key == "numprocesses": return int(val) elif key == "warmup_delay": return float(val) elif key == "working_dir": return val elif key == "uid": return val elif key == "gid": return val elif key == "send_hup": return util.to_bool(val) elif key == "shell": return util.to_bool(val) elif key == "copy_env": return util.to_bool(val) elif key == "env": return util.parse_env_dict(val) elif key == "cmd": return val elif key == "flapping_attempts": return int(val) elif key == "flapping_window": return float(val) elif key == "retry_in": return float(val) elif key == "max_retry": return int(val) elif key == "graceful_timeout": return float(val) elif key == "max_age": return int(val) elif key == "max_age_variance": return int(val) elif key == "respawn": return util.to_bool(val) elif key.startswith("stderr_stream.") or key.startswith("stdout_stream."): subkey = key.split(".", 1)[-1] if subkey in ("max_bytes", "backup_count"): return int(val) return val elif key == "hooks": res = {} for hook in val.split(","): if hook == "": continue hook = hook.split(":") if len(hook) != 2: raise ArgumentError(hook) name, value = hook if name not in _HOOKS: raise ArgumentError(name) res[name] = value return res elif key.startswith("hooks."): # we can also set a single hook name = key.split(".", 1)[-1] if name not in _HOOKS: raise ArgumentError(name) return val raise ArgumentError("unknown key %r" % key)