From c690e8e7f53d20c2297734a0159f7b36d93a8f38 Mon Sep 17 00:00:00 2001 From: gavin Date: Fri, 24 Feb 2023 15:13:36 +0530 Subject: [PATCH] fix: Handle supervisor escalation better (#1438) * fix: Give more meaningful context in subproc failures * fix: Handle supervisor escalation if no exc is raised * fix: only apply sudo if not already running as sudo --- bench/utils/__init__.py | 6 +++--- bench/utils/bench.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index b61f686e1..b9e0cced4 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -150,12 +150,12 @@ def exec_cmd(cmd, cwd=".", env=None, _raise=True): cwd_info = f"cd {cwd} && " if cwd != "." else "" cmd_log = f"{cwd_info}{cmd}" logger.debug(cmd_log) - cmd = split(cmd) - return_code = subprocess.call(cmd, cwd=cwd, universal_newlines=True, env=env) + spl_cmd = split(cmd) + return_code = subprocess.call(spl_cmd, cwd=cwd, universal_newlines=True, env=env) if return_code: logger.warning(f"{cmd_log} executed with exit code {return_code}") if _raise: - raise CommandFailedError + raise CommandFailedError from subprocess.CalledProcessError(return_code, cmd) return return_code diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 353526d55..3fe7f85b6 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -298,6 +298,12 @@ def restart_supervisor_processes(bench_path=".", web_workers=False, _raise=False sudo = "sudo " supervisor_status = get_cmd_output("sudo supervisorctl status", cwd=bench_path) + if not sudo and ( + "error: , [Errno 13] Permission denied" in supervisor_status + ): + sudo = "sudo " + supervisor_status = get_cmd_output("sudo supervisorctl status", cwd=bench_path) + if web_workers and f"{bench_name}-web:" in supervisor_status: group = f"{bench_name}-web:\t"