def node_start(clear=False, nodeos_stdout=None, verbosity=None): args_ = args(clear) if setup.is_print_command_line: print("nodeos command line:") print(config.node_exe() + " " + " ".join(args_)) if config.is_nodeos_in_window(): if is_windows_ubuntu(): args_.insert(0, config.node_exe()) subprocess.call([ "cmd.exe", "/c", "start", "/MIN", "bash.exe", "-c", " ".join(args_) ]) elif uname() == "Darwin": subprocess.Popen("open -a " + config.node_exe() + " --args " + " ".join(args_), shell=True) else: args_.insert(0, config.node_exe()) subprocess.Popen("gnome-terminal -- " + " ".join(args_), shell=True) else: if not nodeos_stdout: nodeos_stdout = config.nodeos_stdout() std_out_handle = subprocess.DEVNULL if nodeos_stdout: try: std_out_handle = open(nodeos_stdout, 'w') except Exception as e: raise errors.Error(''' Error when preparing to start the local EOS node, opening the given stdout log file that is {} Error message is {} '''.format(nodeos_stdout, str(e))) def onExit(): if not std_out_handle == subprocess.DEVNULL: try: std_out_handle.close() except: pass args_.insert(0, config.node_exe()) def runInThread(): proc = subprocess.Popen(" ".join(args_), stdin=subprocess.DEVNULL, stdout=std_out_handle, stderr=subprocess.DEVNULL, shell=True) proc.wait() onExit() return thread = threading.Thread(target=runInThread) thread.start()
def node_start(clear=False, verbosity=None): args_ = args(clear) if setup.is_print_command_line: print("nodeos command line:") print(config.node_exe() + " " + " ".join(args_)) if config.is_nodeos_in_window(): if is_windows_ubuntu(): args_.insert(0, config.node_exe()) subprocess.call([ "cmd.exe", "/c", "start", "/MIN", "bash.exe", "-c", " ".join(args_) ]) elif uname() == "Darwin": subprocess.Popen("open -a " + config.node_exe() + " --args " + " ".join(args_), shell=True) else: args_.insert(0, config.node_exe()) subprocess.Popen("gnome-terminal -- " + " ".join(args_), shell=True) else: args_.insert(0, config.node_exe()) subprocess.Popen(" ".join(args_), stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True) node_probe(verbosity)
def node_start(clear=False, nodeos_stdout=None): '''Start the local EOSIO node. Args: clear (bool): If set, the blockchain is deleted and then re-created. nodeos_stdout (str): If set, a file where *stdout* stream of the local *nodeos* is send. Note that the file can be included to the configuration of EOSFactory, see :func:`.core.config.nodeos_stdout`. If the file is set with the configuration, and in the same time it is set with this argument, the argument setting prevails. ''' args_ = args(clear) if not nodeos_stdout: nodeos_stdout = config.nodeos_stdout() global std_out_handle std_out_handle = subprocess.DEVNULL if nodeos_stdout: try: std_out_handle = open(nodeos_stdout, 'w') except Exception as e: raise errors.Error(''' Error when preparing to start the local EOS node, opening the given stdout log file that is {} Error message is {} '''.format(nodeos_stdout, str(e))) def onExit(): global std_out_handle if not std_out_handle == subprocess.DEVNULL: try: std_out_handle.close() except: pass if setup.is_save_command_lines: setup.add_to__command_line_file(config.node_exe() + " " + " ".join(args_)) if setup.is_print_command_lines: print("######## nodeos command line:") print(config.node_exe() + " " + " ".join(args_)) args_.insert(0, config.node_exe()) def runInThread(): proc = subprocess.Popen(" ".join(args_), stdin=subprocess.DEVNULL, stdout=std_out_handle, stderr=subprocess.DEVNULL, shell=True) proc.wait() onExit() return thread = threading.Thread(target=runInThread) thread.start()
def is_local_node_process_running(name=None): if not name: name = config.node_exe() response = subprocess.run('ps aux | grep -v grep | grep ' + name, shell=True, stdout=subprocess.PIPE) out = response.stdout.decode("utf-8") return name in out
def nodeos(args): '''Given the ``args``, reset or resume the local node asynchronously. ''' args.insert(0, config.node_exe()) # print(" ".join(args)) subprocess.Popen(" ".join(args), stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, shell=True)
def node_stop(verbose=True): # You can see if the process is a zombie by using top or # the following command: # ps aux | awk '$8=="Z" {print $2}' kill_keosd() pids = kill(os.path.splitext(os.path.basename(config.node_exe()))[0]) if verbose: logger.INFO(''' Local node is stopped {}. '''.format(str(pids)))
def get_pid(name=None): """Return process ids found by name. """ if not name: name = os.path.splitext(os.path.basename(config.node_exe()))[0] pids = [] processes = [p.info for p in psutil.process_iter(attrs=["pid", "name"]) \ if p.info["name"] and name in p.info["name"]] for process in processes: pids.append(process["pid"]) return pids
def get_pid(name=None): """Return process ids found by (partial) name or regex. >>> get_process_id('kthreadd') [2] >>> get_process_id('watchdog') [10, 11, 16, 21, 26, 31, 36, 41, 46, 51, 56, 61] # ymmv >>> get_process_id('non-existent process') [] """ if not name: name = os.path.splitext(os.path.basename(config.node_exe()))[0] command_line = ['pgrep', '-f', name] stdout = utils.process( command_line, "Cannot determine PID of any nodeos process.") return [int(pid) for pid in stdout.split()]
def on_nodeos_error(clear=False): node_stop() args_ = args(clear) args_.insert(0, config.node_exe()) command_line = " ".join(args_) raise errors.Error(''' The local ``nodeos`` failed to start twice in sequence. Perhaps, something is wrong with configuration of the system. See the command line issued: ''') print("\n{}\n".format(command_line)) logger.INFO(''' Now, see the result of an execution of the command line: ''') def runInThread(): p = subprocess.run( command_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) err_msg = p.stderr.decode("ISO-8859-1") if "error" in err_msg and not "exit shutdown" in err_msg: raise errors.Error(err_msg) elif not err_msg or "exit shutdown" in err_msg: logger.OUT( ''' Just another instability incident of the ``nodeos`` executable. Rerun the script. ''' ) else: print(err_msg) thread = threading.Thread(target=runInThread) thread.start() time.sleep(10) node_stop() exit()
def kill(name): pids = get_pid(name) count = 10 for pid in pids: p = psutil.Process(pid) p.terminate() while count > 0: time.sleep(1) if not psutil.pid_exists(pid): break count = count -1 if count <= 0: raise errors.Error(''' Failed to kill {}. Pid is {}. '''.format( os.path.splitext(os.path.basename(config.node_exe()))[0], str(pids)) ) return pids
def on_nodeos_error(clear=False): ERROR_WAIT_TIME = 5 NOT_ERROR = [ "exit shutdown", "configuration items in the config.ini file are redundantly", ] node_stop() args_ = args(clear) args_.insert(0, config.node_exe()) command_line = " ".join(args_) logger.ERROR(''' The local 'nodeos' failed to start few times in sequence. Perhaps, something is wrong with configuration of the system. See the command line issued: ''') print("\n{}\n".format(command_line)) print(''' Now, see the result of execution of the command line: ''') def runInThread(): proc = subprocess.Popen( " ".join(args_), stdin=subprocess.DEVNULL, stdout=std_out_handle, stderr=subprocess.PIPE, shell=True) out, err = proc.communicate() err_msg = err.decode("ISO-8859-1") not_error = False if err_msg: for item in NOT_ERROR: if item in err_msg: not_error = True break if not_error: print( ''' Just another hang incident of the 'nodeos' executable.''') if clear: print( ''' Rerun the script. ''') else: print( ''' Rerun the script with 'nodeos' restarted. ''') else: print(err_msg) thread = threading.Thread(target=runInThread) thread.start() # Wait for the nodeos process to crash for i in (0, int(ERROR_WAIT_TIME)): print(".", end="", flush=True) time.sleep(ERROR_WAIT_TIME) print() # Kill the process: it is stuck, or it is running well. node_stop() exit()
def is_local_node_process_running(name=None): if not name: name = config.node_exe() return name in utils.process( 'ps aux | grep -v grep | grep ' + name, shell=True)