本文整理汇总了Python中supervisor.options.make_namespec函数的典型用法代码示例。如果您正苦于以下问题:Python make_namespec函数的具体用法?Python make_namespec怎么用?Python make_namespec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_namespec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: act
def act(self, subject, msg):
messages = [msg]
def write(msg):
self.stderr.write('%s\n' % msg)
self.stderr.flush()
messages.append(msg)
try:
specs = self.rpc.supervisor.getAllProcessInfo()
except Exception as e:
write('Exception retrieving process info %s, not acting' % e)
return
waiting = list(self.programs)
write(msg)
if self.any:
write('Restarting all running processes')
for spec in specs:
name = spec['name']
group = spec['group']
self.restart(spec, write)
namespec = make_namespec(group, name)
if name in waiting:
waiting.remove(name)
if namespec in waiting:
waiting.remove(namespec)
else:
write('Restarting selected processes %s' % self.programs)
for spec in specs:
name = spec['name']
group = spec['group']
namespec = make_namespec(group, name)
if (name in self.programs) or (namespec in self.programs):
self.restart(spec, write)
if name in waiting:
waiting.remove(name)
if namespec in waiting:
waiting.remove(namespec)
if waiting:
write(
'Programs not restarted because they did not exist: %s' %
waiting)
if self.email:
message = '\n'.join(messages)
self.mail(self.email, subject, message)
示例2: clearall
def clearall():
if not callbacks:
return results
group, process, callback = callbacks.pop(0)
name = make_namespec(group.config.name, process.config.name)
try:
callback(name)
except RPCError as e:
results.append(
{"name": process.config.name, "group": group.config.name, "status": e.code, "description": e.text}
)
else:
results.append(
{
"name": process.config.name,
"group": group.config.name,
"status": Faults.SUCCESS,
"description": "OK",
}
)
if callbacks:
return NOT_DONE_YET
return results
示例3: do_clear
def do_clear(self, arg):
if not self.ctl.upcheck():
return
names = arg.split()
if not names:
self.ctl.output("Error: clear requires a process name")
self.help_clear()
return
supervisor = self.ctl.get_supervisor()
if "all" in names:
results = supervisor.clearAllProcessLogs()
for result in results:
result = self._clearresult(result)
self.ctl.output(result)
else:
for name in names:
group_name, process_name = split_namespec(name)
try:
result = supervisor.clearProcessLogs(name)
except xmlrpclib.Fault, e:
error = self._clearresult(
{"status": e.faultCode, "name": process_name, "group": group_name, "description": e.faultString}
)
self.ctl.output(error)
else:
name = make_namespec(group_name, process_name)
self.ctl.output("%s: cleared" % name)
示例4: allfunc
def allfunc(processes=processes,
predicate=predicate,
func=func,
extra_kwargs=extra_kwargs,
callbacks=callbacks, # used only to fool scoping, never passed by caller
results=results): # used only to fool scoping, never passed by caller
if not callbacks:
for group, process in processes:
name = make_namespec(group.config.name, process.config.name)
if predicate(process):
try:
callback = func(name, **extra_kwargs)
except RPCError as e:
results.append({
'name': process.config.name,
'group': group.config.name,
'status': e.code,
'description': e.text
})
continue
if isinstance(callback, types.FunctionType):
callbacks.append((group, process, callback))
else:
results.append({
'name': process.config.name,
'group': group.config.name,
'status': Faults.SUCCESS,
'description': 'OK'
})
if not callbacks:
return results
for struct in callbacks[:]:
group, process, cb = struct
try:
value = cb()
except RPCError as e:
results.append({
'name': process.config.name,
'group': group.config.name,
'status': e.code,
'description': e.text
})
callbacks.remove(struct)
else:
if value is not NOT_DONE_YET:
results.append({
'name': process.config.name,
'group': group.config.name,
'status': Faults.SUCCESS,
'description': 'OK'
})
callbacks.remove(struct)
if callbacks:
return NOT_DONE_YET
return results
示例5: _restart_process
def _restart_process(self, process_spec):
"""Restart a process.
"""
name_spec = make_namespec(
process_spec[GROUP_KEY], process_spec[NAME_KEY])
rpc_client = childutils.getRPCInterface(self._environment)
process_spec = rpc_client.supervisor.getProcessInfo(name_spec)
if process_spec[STATE_KEY] is ProcessStates.RUNNING:
self._log('Trying to stop process %s', name_spec)
try:
rpc_client.supervisor.stopProcess(name_spec)
self._log('Stopped process %s', name_spec)
except xmlrpclib.Fault as exc:
self._log('Failed to stop process %s: %s', name_spec, exc)
try:
self._log('Starting process %s', name_spec)
rpc_client.supervisor.startProcess(name_spec, False)
except xmlrpclib.Fault as exc:
self._log('Failed to start process %s: %s', name_spec, exc)
else:
self._log('%s not in RUNNING state, cannot restart', name_spec)
示例6: allfunc
def allfunc(
processes=processes,
predicate=predicate,
func=func,
extra_kwargs=extra_kwargs,
callbacks=callbacks, # used only to fool scoping, never passed by caller
results=results, # used only to fool scoping, never passed by caller
):
if not callbacks:
for group, process in processes:
name = make_namespec(group.config.name, process.config.name)
if predicate(process):
try:
callback = func(name, **extra_kwargs)
except RPCError, e:
results.append({'name':process.config.name,
'group':group.config.name,
'status':e.code,
'description':e.text})
continue
if isinstance(callback, types.FunctionType):
callbacks.append((group, process, callback))
else:
results.append(
{'name':process.config.name,
'group':group.config.name,
'status':Faults.SUCCESS,
'description':'OK'}
)
示例7: restart
def restart(self, spec, write):
namespec = make_namespec(spec['group'], spec['name'])
if spec['state'] is ProcessStates.RUNNING:
if self.coredir and self.gcore:
corename = os.path.join(self.coredir, namespec)
cmd = self.gcore + ' "%s" %s' % (corename, spec['pid'])
with os.popen(cmd) as m:
write('gcore output for %s:\n\n %s' % (
namespec, m.read()))
write('%s is in RUNNING state, restarting' % namespec)
try:
self.rpc.supervisor.stopProcess(namespec)
except xmlrpclib.Fault as e:
write('Failed to stop process %s: %s' % (
namespec, e))
try:
self.rpc.supervisor.startProcess(namespec)
except xmlrpclib.Fault as e:
write('Failed to start process %s: %s' % (
namespec, e))
else:
write('%s restarted' % namespec)
else:
write('%s not in RUNNING state, NOT restarting' % namespec)
示例8: clearall
def clearall():
if not callbacks:
return results
group, process, callback = callbacks.pop(0)
name = make_namespec(group.config.name, process.config.name)
try:
callback(name)
except RPCError as e:
results.append(
{'name': process.config.name,
'group': group.config.name,
'status': e.code,
'description': e.text})
else:
results.append(
{'name': process.config.name,
'group': group.config.name,
'status': Faults.SUCCESS,
'description': 'OK'}
)
if callbacks:
return NOT_DONE_YET
return results
示例9: stopAllProcesses
def stopAllProcesses(self, wait=True):
""" Stop all processes in the process list
@param boolean wait Wait for each process to be fully stopped
@return array result An array of process status info structs
"""
self._update('stopAllProcesses')
processes = self._getAllProcesses()
results=[]
for group, process in processes:
name = make_namespec(group.config.name, process.config.name)
grp, proc = self._getGroupAndProcess(name)
msg=proc.stop()
results.append(
{'name':process.config.name,
'group':group.config.name,
'status':Faults.SUCCESS,
'description':'OK'}
)
#killall.rpcinterface = self
return results # deferred
示例10: stopProcessGroup
def stopProcessGroup(self, name, wait=True):
""" Stop all processes in the process group named 'name'
@param string name The group name
@param boolean wait Wait for each process to be fully stopped
@return array result An array of process status info structs
"""
self._update('stopProcessGroup')
group = self.supervisord.process_groups.get(name)
if group is None:
raise RPCError(Faults.BAD_NAME, name)
processes = group.processes.values()
processes.sort()
processes = [ (group, process) for process in processes ]
results=[]
for group, process in processes:
name = make_namespec(group.config.name, process.config.name)
grp, proc = self._getGroupAndProcess(name)
msg=proc.stop()
results.append(
{'name':process.config.name,
'group':group.config.name,
'status':Faults.SUCCESS,
'description':'OK'}
)
return results # deferred
示例11: _restart_processes
def _restart_processes(self):
try:
specs = self.rpc.supervisor.getAllProcessInfo()
except Exception as e:
print("Unable to get process info: {}. No action taken.".format(e), file=self.stderr)
else:
waiting = set(self.restart_programs)
for spec in specs:
name = spec["name"]
namespec = make_namespec(spec["group"], name)
if self.restart_any_program or name in waiting or namespec in waiting:
if spec["state"] is ProcessStates.RUNNING:
print("Restarting process: {}.".format(namespec), file=self.stderr)
try:
self.rpc.supervisor.stopProcess(namespec)
except xmlrpclib.Fault as e:
print("Unable to stop process {}: {}.".format(namespec, e), file=self.stderr)
try:
self.rpc.supervisor.startProcess(namespec)
except xmlrpclib.Fault as e:
print("Unable to start process {}: {}.".format(namespec, e), file=self.stderr)
else:
print("Restarted process {}.".format(namespec), file=self.stderr)
else:
print("Process {} is not in RUNNING state. No action taken.".format(namespec))
waiting.discard(name)
waiting.discard(namespec)
if len(waiting) > 0:
print("Programs specified could not be found: {}.".format(", ".join(waiting)), file=self.stderr)
示例12: do_clear
def do_clear(self, arg):
if not self.ctl.upcheck():
return
names = arg.split()
if not names:
self.ctl.output('Error: clear requires a process name')
self.help_clear()
return
supervisor = self.ctl.get_supervisor()
if 'all' in names:
results = supervisor.clearAllProcessLogs()
for result in results:
result = self._clearresult(result)
self.ctl.output(result)
else:
for name in names:
group_name, process_name = split_namespec(name)
try:
supervisor.clearProcessLogs(name)
except xmlrpclib.Fault as e:
error = self._clearresult({'status': e.faultCode,
'name': process_name,
'group': group_name,
'description': e.faultString})
self.ctl.output(error)
else:
name = make_namespec(group_name, process_name)
self.ctl.output('%s: cleared' % name)
示例13: match
def match(spec):
name = spec['name']
group = spec['group']
namespec = make_namespec(name, group)
for pattern in self.programs:
if fnmatch.fnmatch(name, pattern) or fnmatch.fnmatch(namespec, pattern):
return True
return False
示例14: logname
def logname(self):
"""
The name of this subprocess as used in logging.
"""
if self.group is None:
return self.config.name
else:
return make_namespec(self.group.config.name, self.config.name)
示例15: _getGroupProcessInfo
def _getGroupProcessInfo(self, group):
""" Get info about the processes of a certian group
@return array result An array of process status results
"""
output = []
for process in group.processes.values():
name = make_namespec(group.config.name, process.config.name)
output.append(self.getProcessInfo(name))
return output