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'} )
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)
def _clearresult(self, result): name = make_namespec(result['group'], result['name']) code = result['status'] template = '%s: ERROR (%s)' if code == xmlrpc.Faults.BAD_NAME: return template % (name, 'no such process') elif code == xmlrpc.Faults.FAILED: return template % (name, 'failed') elif code == xmlrpc.Faults.SUCCESS: return '%s: cleared' % name raise ValueError('Unknown result code %s for %s' % (code, name))
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, e: results.append( {'name':process.config.name, 'group':group.config.name, 'status':e.code, 'description':e.text})
def getAllProcessInfo(self): """ Get info about all processes @return array result An array of process status results """ self._update('getAllProcessInfo') all_processes = self._getAllProcesses(lexical=True) output = [] for group, process in all_processes: name = make_namespec(group.config.name, process.config.name) output.append(self.getProcessInfo(name)) return output
def _show_statuses(self, process_infos): namespecs, maxlen = [], 30 for i, info in enumerate(process_infos): namespecs.append(make_namespec(info['group'], info['name'])) if len(namespecs[i]) > maxlen: maxlen = len(namespecs[i]) template = '%(namespec)-' + str(maxlen + 3) + 's%(state)-10s%(desc)s' for i, info in enumerate(process_infos): line = template % { 'namespec': namespecs[i], 'state': info['statename'], 'desc': info['description'] } self.ctl.output(line)
def _formatConfigInfo(self, configinfo): name = make_namespec(configinfo['group'], configinfo['name']) formatted = {'name': name} if configinfo['inuse']: formatted['inuse'] = 'in use' else: formatted['inuse'] = 'avail' if configinfo['autostart']: formatted['autostart'] = 'auto' else: formatted['autostart'] = 'manual' formatted['priority'] = "%s:%s" % (configinfo['group_prio'], configinfo['process_prio']) template = '%(name)-32s %(inuse)-9s %(autostart)-9s %(priority)s' return template % formatted
def _signalresult(self, result, success='signalled'): name = make_namespec(result['group'], result['name']) code = result['status'] fault_string = result['description'] template = '%s: ERROR (%s)' if code == xmlrpc.Faults.BAD_NAME: return template % (name, 'no such process') elif code == xmlrpc.Faults.BAD_SIGNAL: return template % (name, 'bad signal name') elif code == xmlrpc.Faults.NOT_RUNNING: return template % (name, 'not running') elif code == xmlrpc.Faults.SUCCESS: return '%s: %s' % (name, success) elif code == xmlrpc.Faults.FAILED: return fault_string # assertion raise ValueError('Unknown result code %s for %s' % (code, name))
def _startresult(self, result): name = make_namespec(result['group'], result['name']) code = result['status'] template = '%s: ERROR (%s)' if code == xmlrpc.Faults.BAD_NAME: return template % (name, 'no such process') elif code == xmlrpc.Faults.NO_FILE: return template % (name, 'no such file') elif code == xmlrpc.Faults.NOT_EXECUTABLE: return template % (name, 'file is not executable') elif code == xmlrpc.Faults.ALREADY_STARTED: return template % (name, 'already started') elif code == xmlrpc.Faults.SPAWN_ERROR: return template % (name, 'spawn error') elif code == xmlrpc.Faults.ABNORMAL_TERMINATION: return template % (name, 'abnormal termination') elif code == xmlrpc.Faults.SUCCESS: return '%s: started' % name # assertion raise ValueError('Unknown result code %s for %s' % (code, name))
def actions_for_process(self, process): state = process.get_state() processname = urllib.quote( make_namespec(process.group.config.name, process.config.name)) start = { 'name': 'Start', 'href': 'index.html?processname=%s&action=start' % processname, 'target': None, } restart = { 'name': 'Restart', 'href': 'index.html?processname=%s&action=restart' % processname, 'target': None, } stop = { 'name': 'Stop', 'href': 'index.html?processname=%s&action=stop' % processname, 'target': None, } clearlog = { 'name': 'Clear Log', 'href': 'index.html?processname=%s&action=clearlog' % processname, 'target': None, } tailf = { 'name': 'Tail -f', 'href': 'logtail/%s' % processname, 'target': '_blank' } if state == ProcessStates.RUNNING: actions = [restart, stop, clearlog, tailf] elif state in (ProcessStates.STOPPED, ProcessStates.EXITED, ProcessStates.FATAL): actions = [start, None, clearlog, tailf] else: actions = [None, None, clearlog, tailf] return actions
def render(self): form = self.context.form response = self.context.response processname = form.get('processname') action = form.get('action') message = form.get('message') if action: if not self.callback: self.callback = self.make_callback(processname, action) return NOT_DONE_YET else: message = self.callback() if message is NOT_DONE_YET: return NOT_DONE_YET if message is not None: server_url = form['SERVER_URL'] location = server_url + '?message=%s' % urllib.quote( message) response['headers']['Location'] = location supervisord = self.context.supervisord rpcinterface = RootRPCInterface([ ('supervisor', SupervisorNamespaceRPCInterface(supervisord)) ]) processnames = [] groups = supervisord.process_groups.values() for group in groups: gprocnames = group.processes.keys() for gprocname in gprocnames: processnames.append((group.config.name, gprocname)) processnames.sort() data = [] for groupname, processname in processnames: actions = self.actions_for_process( supervisord.process_groups[groupname].processes[processname]) sent_name = make_namespec(groupname, processname) info = rpcinterface.supervisor.getProcessInfo(sent_name) data.append({ 'status': info['statename'], 'name': processname, 'group': groupname, 'actions': actions, 'state': info['state'], 'description': info['description'], }) root = self.clone() if message is not None: statusarea = root.findmeld('statusmessage') statusarea.attrib['class'] = 'status_msg' statusarea.content(message) if data: iterator = root.findmeld('tr').repeat(data) shaded_tr = False for tr_element, item in iterator: status_text = tr_element.findmeld('status_text') status_text.content(item['status'].lower()) status_text.attrib['class'] = self.css_class_for_state( item['state']) info_text = tr_element.findmeld('info_text') info_text.content(item['description']) anchor = tr_element.findmeld('name_anchor') processname = make_namespec(item['group'], item['name']) anchor.attributes(href='tail.html?processname=%s' % urllib.quote(processname)) anchor.content(processname) actions = item['actions'] actionitem_td = tr_element.findmeld('actionitem_td') for li_element, actionitem in actionitem_td.repeat(actions): anchor = li_element.findmeld('actionitem_anchor') if actionitem is None: anchor.attrib['class'] = 'hidden' else: anchor.attributes(href=actionitem['href'], name=actionitem['name']) anchor.content(actionitem['name']) if actionitem['target']: anchor.attributes(target=actionitem['target']) if shaded_tr: tr_element.attrib['class'] = 'shade' shaded_tr = not shaded_tr else: table = root.findmeld('statustable') table.replace('No programs to manage') root.findmeld('supervisor_version').content(VERSION) copyright_year = str(datetime.date.today().year) root.findmeld('copyright_date').content(copyright_year) return root.write_xhtmlstring()
self.ctl.output(error) else: raise else: try: result = supervisor.startProcess(name) except xmlrpclib.Fault, e: error = self._startresult({ '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: started' % name) def help_start(self): self.ctl.output("start <name>\t\tStart a process") self.ctl.output("start <gname>:*\t\tStart all processes in a group") self.ctl.output( "start <name> <name>\tStart multiple processes or groups") self.ctl.output("start all\t\tStart all processes") def _signalresult(self, result, success='signalled'): name = make_namespec(result['group'], result['name']) code = result['status'] fault_string = result['description'] template = '%s: ERROR (%s)' if code == xmlrpc.Faults.BAD_NAME: