本文整理汇总了Python中supervisor.options.split_namespec函数的典型用法代码示例。如果您正苦于以下问题:Python split_namespec函数的具体用法?Python split_namespec怎么用?Python split_namespec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_namespec函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: 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)
示例2: status
def status(self, names):
'''
status <name>\t\tGet status for a single process
status <gname>:*\tGet status for all processes in a group
status <name> <name>\tGet status for multiple named processes
status\t\t\tGet all process status info
'''
self.reread()
all_infos = self.supervisor.getAllProcessInfo()
if "all" in names:
matching_infos = all_infos
else:
matching_infos = []
for name in names:
bad_name = True
group_name, process_name = split_namespec(name)
for info in all_infos:
matched = info['group'] == group_name
if process_name is not None:
matched = matched and info['name'] == process_name
if matched:
bad_name = False
matching_infos.append(info)
if bad_name:
if process_name is None:
msg = "%s: ERROR (no such group)" % group_name
else:
msg = "%s: ERROR (no such process)" % name
self.logger.info(msg)
return matching_infos
示例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:
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)
示例4: sendProcessSignal
def sendProcessSignal(self, name, signal = signal.SIGHUP):
""" Send an arbitrary UNIX signal to the process named by name
@param string name The name of the process to signal (or 'group:name')
@param int signal the integer UNIX signal to send. SIGHUP by default.
@return boolean result
"""
self._update('sendProcessSignal')
group, process = self._getGroupAndProcess(name)
if process is None:
group_name, process_name = split_namespec(name)
return self.sendGroupSignal(group_name, signal = signal)
if process.get_state() not in RUNNING_STATES:
raise RPCError(Faults.NOT_RUNNING)
msg = process.signal(signal)
if not msg is None:
raise RPCError(Faults.FAILED, msg)
cb = lambda: True
cb.delay = 0
cb.rpcinterface = self
return cb
示例5: do_status
def do_status(self, arg):
if not self.ctl.upcheck():
return
supervisor = self.ctl.get_supervisor()
all_infos = supervisor.getAllProcessInfo()
names = arg.split()
if not names or "all" in names:
matching_infos = all_infos
else:
matching_infos = []
for name in names:
bad_name = True
group_name, process_name = split_namespec(name)
for info in all_infos:
matched = info['group'] == group_name
if process_name is not None:
matched = matched and info['name'] == process_name
if matched:
bad_name = False
matching_infos.append(info)
if bad_name:
if process_name is None:
msg = "%s: ERROR (no such group)" % group_name
else:
msg = "%s: ERROR (no such process)" % name
self.ctl.output(msg)
self._show_statuses(matching_infos)
示例6: do_kill
def do_kill(self, arg):
if not self.ctl.upcheck():
return
args = arg.strip().split()
if not args:
self.ctl.output("Error: kill requires a signal and process name")
self.help_kill()
return
signal = args[0]
names = args[1:]
if not names:
self.ctl.output("Error: kill requires a process name")
self.help_start()
return
for name in names:
group_name, process_name = split_namespec(name)
if process_name is None:
results = self.laforge.killProcessGroup(group_name, signal)
for result in results:
result = self._killresult(result)
self.ctl.output(result)
else:
try:
result = self.laforge.killProcess(name, signal)
except xmlrpclib.Fault, e:
error = self._killresult({'status':e.faultCode,
'name':name,
'description':e.faultString})
self.ctl.output(error)
else:
self.ctl.output('%s: signal sent' % name)
示例7: signalProcess
def signalProcess(self, name, signal):
""" Send an arbitrary UNIX signal to the process named by name
@param string name Name of the process to signal (or 'group:name')
@param string signal Signal to send, as name ('HUP') or number ('1')
@return boolean
"""
self._update('signalProcess')
group, process = self._getGroupAndProcess(name)
if process is None:
group_name, process_name = split_namespec(name)
return self.signalProcessGroup(group_name, signal=signal)
try:
sig = signal_number(signal)
except ValueError:
raise RPCError(Faults.BAD_SIGNAL, signal)
if process.get_state() not in RUNNING_STATES:
raise RPCError(Faults.NOT_RUNNING)
msg = process.signal(sig)
if not msg is None:
raise RPCError(Faults.FAILED, msg)
return True
示例8: handle_request
def handle_request(self, request):
if request.command != 'GET':
request.error (400) # bad request
return
path, params, query, fragment = request.split_uri()
if '%' in path:
path = http_server.unquote(path)
# strip off all leading slashes
while path and path[0] == '/':
path = path[1:]
path, process_name_and_channel = path.split('/', 1)
try:
process_name, channel = process_name_and_channel.split('/', 1)
except ValueError:
# no channel specified, default channel to stdout
process_name = process_name_and_channel
channel = 'stdout'
from supervisor.options import split_namespec
group_name, process_name = split_namespec(process_name)
group = self.supervisord.process_groups.get(group_name)
if group is None:
request.error(404) # not found
return
process = group.processes.get(process_name)
if process is None:
request.error(404) # not found
return
logfile = getattr(process.config, '%s_logfile' % channel, None)
if logfile is None or not os.path.exists(logfile):
# XXX problematic: processes that don't start won't have a log
# file and we probably don't want to go into fatal state if we try
# to read the log of a process that did not start.
request.error(410) # gone
return
mtime = os.stat(logfile)[stat.ST_MTIME]
request['Last-Modified'] = http_date.build_http_date(mtime)
request['Content-Type'] = 'text/plain'
# the lack of a Content-Length header makes the outputter
# send a 'Transfer-Encoding: chunked' response
request.push(tail_f_producer(request, logfile, 1024))
request.done()
示例9: force_process_state
def force_process_state(self, namespec, state):
""" Publishes a fake process event showing a state for the process. """
application_name, process_name = split_namespec(namespec)
# create payload from event
payload = {'processname': process_name,
'groupname': application_name,
'state': state,
'now': int(time.time()),
'pid': 0,
'expected': False}
self.logger.debug('payload={}'.format(payload))
self.publisher.send_process_event(payload)
示例10: stopProcess
def stopProcess(self, name, wait=True):
""" Stop a process named by name
@param string name The name of the process to stop (or 'group:name')
@param boolean wait Wait for the process to be fully stopped
@return boolean result Always return True unless error
"""
self._update('stopProcess')
group, process = self._getGroupAndProcess(name)
if process is None:
group_name, process_name = split_namespec(name)
return self.stopProcessGroup(group_name, wait)
if process.get_state() not in RUNNING_STATES:
raise RPCError(Faults.NOT_RUNNING)
msg = process.stop()
if msg is not None:
raise RPCError(Faults.FAILED, msg)
# We'll try to reap any killed child. FWIW, reap calls waitpid, and
# then, if waitpid returns a pid, calls finish() on the process with
# that pid, which drains any I/O from the process' dispatchers and
# changes the process' state. I chose to call reap without once=True
# because we don't really care if we reap more than one child. Even if
# we only reap one child. we may not even be reaping the child that we
# just stopped (this is all async, and process.stop() may not work, and
# we'll need to wait for SIGKILL during process.transition() as the
# result of normal select looping).
self.supervisord.reap()
if wait and process.get_state() not in STOPPED_STATES:
def onwait():
# process will eventually enter a stopped state by
# virtue of the supervisord.reap() method being called
# during normal operations
self.supervisord.options.logger.info(
'waiting for %s to stop' % process.config.name
)
if process.get_state() not in STOPPED_STATES:
return NOT_DONE_YET
return True
onwait.delay = 0
onwait.rpcinterface = self
return onwait # deferred
return True
示例11: do_signal
def do_signal(self, arg):
if not self.ctl.upcheck():
return
args = arg.split()
if len(args) < 2:
self.ctl.output(
'Error: signal requires a signal name and a process name')
self.help_signal()
return
sig = args[0]
names = args[1:]
supervisor = self.ctl.get_supervisor()
if 'all' in names:
results = supervisor.signalAllProcesses(sig)
for result in results:
result = self._signalresult(result)
self.ctl.output(result)
else:
for name in names:
group_name, process_name = split_namespec(name)
if process_name is None:
try:
results = supervisor.signalProcessGroup(
group_name, sig
)
for result in results:
result = self._signalresult(result)
self.ctl.output(result)
except xmlrpclib.Fault as e:
if e.faultCode == xmlrpc.Faults.BAD_NAME:
error = "%s: ERROR (no such group)" % group_name
self.ctl.output(error)
else:
raise
else:
try:
supervisor.signalProcess(name, sig)
except xmlrpclib.Fault as e:
error = self._signalresult({'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: signalled' % name)
示例12: start
def start(self, names):
'''
start <name>\t\tStart a process
start <gname>:*\t\tStart all processes in a group
start <name> <name>\tStart multiple processes or groups
start all\t\tStart all processes
'''
self.reread()
if not names:
self.logger.info("Error: start requires a process name")
return []
results = []
if 'all' in names:
results = self.supervisor.startAllProcesses()
for result in results:
result = self._startresult(result)
self.logger.info(result)
else:
for name in names:
group_name, process_name = split_namespec(name)
if process_name is None:
try:
_results = self.supervisor.startProcessGroup(group_name)
results.extend(_results)
for result in _results:
result = self._startresult(result)
self.logger.info(result)
except xmlrpclib.Fault, e:
if e.faultCode == xmlrpc.Faults.BAD_NAME:
error = "%s: ERROR (no such group)" % group_name
self.logger.info(error)
else:
raise
else:
try:
result = self.supervisor.startProcess(name)
results.append(result)
except xmlrpclib.Fault, e:
error = self._startresult({'status': e.faultCode,
'name': process_name,
'group': group_name,
'description': e.faultString})
self.logger.info(error)
else:
name = make_namespec(group_name, process_name)
示例13: stopProcess
def stopProcess(self, name, wait=True):
""" Stop a process named by name
:param name: The name of the process to stop (or 'group:name')
:type name: string
:param wait: Wait for the process to be fully stopped
:type wait: boolean
:return: Always return True unless error
:rtype: boolean
"""
self._update('stopProcess')
group, process = self._getGroupAndProcess(name)
if process is None:
group_name, process_name = split_namespec(name)
return self.stopProcessGroup(group_name, wait)
stopped = []
called = []
def killit():
if not called:
if process.get_state() not in RUNNING_STATES:
raise RPCError(Faults.NOT_RUNNING)
# use a mutable for lexical scoping; see startProcess
called.append(1)
if not stopped:
msg = process.stop()
if msg is not None:
raise RPCError(Faults.FAILED, msg)
stopped.append(1)
if wait:
return NOT_DONE_YET
else:
return True
if process.get_state() not in (ProcessStates.STOPPED,
ProcessStates.EXITED):
return NOT_DONE_YET
else:
return True
killit.delay = 0.2
killit.rpcinterface = self
return killit # deferred
示例14: _getGroupAndProcess
def _getGroupAndProcess(self, name):
# get process to start from name
group_name, process_name = split_namespec(name)
group = self.supervisord.process_groups.get(group_name)
if group is None:
raise RPCError(Faults.BAD_NAME, name)
if process_name is None:
return group, None
process = group.processes.get(process_name)
if process is None:
raise RPCError(Faults.BAD_NAME, name)
return group, process
示例15: do_stop
def do_stop(self, arg):
if not self.ctl.upcheck():
return
names = arg.split()
supervisor = self.ctl.get_supervisor()
if not names:
self.ctl.output("Error: stop requires a process name")
self.help_stop()
return
if "all" in names:
results = supervisor.stopAllProcesses()
for result in results:
result = self._stopresult(result)
self.ctl.output(result)
else:
for name in names:
group_name, process_name = split_namespec(name)
if process_name is None:
try:
results = supervisor.stopProcessGroup(group_name)
for result in results:
result = self._stopresult(result)
self.ctl.output(result)
except xmlrpclib.Fault, e:
if e.faultCode == xmlrpc.Faults.BAD_NAME:
error = "%s: ERROR (no such group)" % group_name
self.ctl.output(error)
else:
raise
else:
try:
result = supervisor.stopProcess(name)
except xmlrpclib.Fault, e:
error = self._stopresult(
{
"status": e.faultCode,
"name": process_name,
"group": group_name,
"description": e.faultString,
}
)
self.ctl.output(error)
else: