def do_shutdown(self, arg): if self.ctl.options.interactive: yesno = raw_input('Really shut the remote supervisord process ' 'down y/N? ') really = yesno.lower().startswith('y') else: really = 1 if really: supervisor = self.ctl.get_supervisor() try: supervisor.shutdown() except xmlrpclib.Fault as e: if e.faultCode == xmlrpc.Faults.SHUTDOWN_STATE: self.ctl.output('ERROR: already shutting down') else: raise except socket.error as e: if e.args[0] == errno.ECONNREFUSED: msg = 'ERROR: %s refused connection (already shut down?)' self.ctl.output(msg % self.ctl.options.serverurl) elif e.args[0] == errno.ENOENT: msg = 'ERROR: %s no such file (already shut down?)' self.ctl.output(msg % self.ctl.options.serverurl) else: raise else: self.ctl.output('Shut down')
def do_fg(self,args=None): if not self.ctl.upcheck(): return if not args: self.ctl.output('Error: no process name supplied') self.help_fg() return args = args.split() if len(args) > 1: self.ctl.output('Error: too many process names supplied') return program = args[0] supervisor = self.ctl.get_supervisor() try: info = supervisor.getProcessInfo(program) except xmlrpclib.Fault as msg: if msg.faultCode == xmlrpc.Faults.BAD_NAME: self.ctl.output('Error: bad process name supplied') return # for any other fault self.ctl.output(str(msg)) return if not info['state'] == states.ProcessStates.RUNNING: self.ctl.output('Error: process not running') return # everything good; continue a = None try: a = fgthread(program,self.ctl) # this thread takes care of # the output/error messages a.start() while True: # this takes care of the user input inp = raw_input() + '\n' try: supervisor.sendProcessStdin(program, inp) except xmlrpclib.Fault as msg: if msg.faultCode == xmlrpc.Faults.NOT_RUNNING: self.ctl.output('Process got killed') self.ctl.output('Exiting foreground') a.kill() return info = supervisor.getProcessInfo(program) if not info['state'] == states.ProcessStates.RUNNING: self.ctl.output('Process got killed') self.ctl.output('Exiting foreground') a.kill() return continue except (KeyboardInterrupt, EOFError): if a: a.kill() self.ctl.output('Exiting foreground') return
def onecmd(self, line): """ Override the onecmd method to: - catch and print all exceptions - allow for composite commands in interactive mode (foo; bar) - call 'do_foo' on plugins rather than ourself """ origline = line lines = line.split(';') # don't filter(None, line.split), as we pop line = lines.pop(0) # stuffing the remainder into cmdqueue will cause cmdloop to # call us again for each command. self.cmdqueue.extend(lines) cmd, arg, line = self.parseline(line) if not line: return self.emptyline() if cmd is None: return self.default(line) self._complete_info = None self.lastcmd = line if cmd == '': return self.default(line) else: do_func = self._get_do_func(cmd) if do_func is None: return self.default(line) try: try: return do_func(arg) except xmlrpclib.ProtocolError as e: if e.errcode == 401: if self.options.interactive: self.output('Server requires authentication') username = raw_input('Username:'******'Password:'******'') self.options.username = username self.options.password = password return self.onecmd(origline) else: self.options.usage( 'Server requires authentication') else: raise do_func(arg) except SystemExit: raise except Exception: (file, fun, line), t, v, tbinfo = asyncore.compact_traceback() error = 'error: %s, %s: file: %s line: %s' % (t, v, file, line) self.error_output(error) if not self.options.interactive: sys.exit(2)
def onecmd(self, line): """ Override the onecmd method to: - catch and print all exceptions - allow for composite commands in interactive mode (foo; bar) - call 'do_foo' on plugins rather than ourself """ origline = line lines = line.split(';') # don't filter(None, line.split), as we pop line = lines.pop(0) # stuffing the remainder into cmdqueue will cause cmdloop to # call us again for each command. self.cmdqueue.extend(lines) cmd, arg, line = self.parseline(line) if not line: return self.emptyline() if cmd is None: return self.default(line) self._complete_info = None self.lastcmd = line if cmd == '': return self.default(line) else: do_func = self._get_do_func(cmd) if do_func is None: return self.default(line) try: try: return do_func(arg) except xmlrpclib.ProtocolError as e: if e.errcode == 401: if self.options.interactive: self.output('Server requires authentication') username = raw_input('Username:'******'Password:'******'') self.options.username = username self.options.password = password return self.onecmd(origline) else: self.options.usage('Server requires authentication') else: raise do_func(arg) except SystemExit: raise except Exception: (file, fun, line), t, v, tbinfo = asyncore.compact_traceback() error = 'error: %s, %s: file: %s line: %s' % (t, v, file, line) self.output(error) if not self.options.interactive: sys.exit(2)
def do_reload(self, arg): if self.ctl.options.interactive: yesno = raw_input('Really restart the remote supervisord process ' 'y/N? ') really = yesno.lower().startswith('y') else: really = 1 if really: supervisor = self.ctl.get_supervisor() try: supervisor.restart() except xmlrpclib.Fault as e: if e.faultCode == xmlrpc.Faults.SHUTDOWN_STATE: self.ctl.output('ERROR: already shutting down') else: raise else: self.ctl.output('Restarted supervisord')
# first grab the timestamp ts = sock.recv (1024)[:-2] sock.send (hex_digest (ts+password) + '\r\n') while 1: d = sock.recv (1024) if not d: lock.release() print('Connection closed. Hit <return> to exit') thread.exit() sys.stdout.write (d) sys.stdout.flush() def writer (lock, sock, barrel="just kidding"): while lock.locked(): sock.send ( sys.stdin.readline()[:-1] + '\r\n' ) if __name__ == '__main__': if len(sys.argv) == 1: print('Usage: %s host port') sys.exit(0) print_function('Enter Password: '******'') p = raw_input() s = socket.socket (socket.AF_INET, socket.SOCK_STREAM) s.connect((sys.argv[1], int(sys.argv[2]))) l = thread.allocate_lock() l.acquire() thread.start_new_thread (reader, (l, s, p)) writer (l, s)
def softspace (self, *args): pass def more (self): if self.data: result = self.data[:512] self.data = self.data[512:] return result else: return '' if __name__ == '__main__': if '-s' in sys.argv: sys.argv.remove ('-s') print_function('Enter password: '******'') password = raw_input() else: password = None if '-e' in sys.argv: sys.argv.remove ('-e') encrypt = 1 else: encrypt = 0 if len(sys.argv) > 1: port = int(sys.argv[1]) else: port = 8023 if password is not None: