Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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
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)
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)
def get_process(self, namespec):
""" This method returns the process configuration related to a namespec. """
# WARN: the following line may throw a KeyError exception
application_name, process_name = split_namespec(namespec)
return self.supervisord.process_groups[application_name].processes[process_name]
def _get_application_process(self, namespec):
""" Return the ApplicationStatus and ProcessStatus corresponding to the namespec.
A BAD_NAME exception is raised if the application or the process is not found. """
application_name, process_name = split_namespec(namespec)
return (self._get_application(application_name),
self._get_process(namespec) if process_name else None)
if not names:
self.ctl.output('Error: clear requires a process name')
self.ctl.exitstatus = LSBInitExitStatuses.GENERIC
self.help_clear()
return
supervisor = self.ctl.get_supervisor()
if 'all' in names:
results = supervisor.clearAllProcessLogs()
for result in results:
self.ctl.output(self._clearresult(result))
self.ctl.set_exitstatus_from_xmlrpc_fault(result['status'])
else:
for name in names:
group_name, process_name = split_namespec(name)
try:
supervisor.clearProcessLogs(name)
except xmlrpclib.Fault as e:
error = {'status': e.faultCode,
'name': process_name,
'group': group_name,
'description': e.faultString}
self.ctl.output(self._clearresult(error))
self.ctl.set_exitstatus_from_xmlrpc_fault(error['status'])
else:
name = make_namespec(group_name, process_name)
self.ctl.output('%s: cleared' % name)
callback = rpcinterface.system.multicall(
[ {'methodName':'supervisor.stopAllProcesses'},
{'methodName':'supervisor.startAllProcesses'} ] )
def restartall():
result = callback()
if result is NOT_DONE_YET:
return NOT_DONE_YET
return 'All restarted at %s' % time.ctime()
restartall.delay = 0.05
return restartall
elif namespec:
def wrong():
return 'No such process named %s' % namespec
wrong.delay = 0.05
group_name, process_name = split_namespec(namespec)
group = supervisord.process_groups.get(group_name)
if group is None:
return wrong
process = group.processes.get(process_name)
if process is None:
return wrong
if action == 'start':
try:
bool_or_callback = (
rpcinterface.supervisor.startProcess(namespec)
)
except RPCError, e:
if e.code == Faults.NO_FILE:
msg = 'no such file'
elif e.code == Faults.NOT_EXECUTABLE: