From 346d08d30f1dcd660da3d449065f7b41e480d23d Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 14 Sep 2023 04:29:58 +0530 Subject: [PATCH 1/4] feat: pass verbose to yarn install --- bench/app.py | 3 ++- bench/utils/bench.py | 11 +++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/bench/app.py b/bench/app.py index 48fbb985b..f07251e4c 100755 --- a/bench/app.py +++ b/bench/app.py @@ -578,7 +578,8 @@ def install_app( install_python_dev_dependencies(apps=app, bench_path=bench_path, verbose=verbose) if os.path.exists(os.path.join(app_path, "package.json")): - bench.run("yarn install", cwd=app_path) + yarn_install = "yarn install --verbose" if verbose else "yarn install" + bench.run(yarn_install, cwd=app_path) bench.apps.sync(app_name=app, required=resolution, branch=tag, app_dir=app_path) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 1fede3a22..cbaa62968 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -47,7 +47,7 @@ def get_venv_path(verbose=False, python="python3"): log("venv cannot be found", level=2) -def update_node_packages(bench_path=".", apps=None): +def update_node_packages(bench_path=".", apps=None, verbose=None): print("Updating node packages...") from distutils.version import LooseVersion @@ -60,7 +60,7 @@ def update_node_packages(bench_path=".", apps=None): if v < LooseVersion("11.x.x-develop"): update_npm_packages(bench_path, apps=apps) else: - update_yarn_packages(bench_path, apps=apps) + update_yarn_packages(bench_path, apps=apps, verbose=verbose) def install_python_dev_dependencies(bench_path=".", apps=None, verbose=False): @@ -110,9 +110,11 @@ def _generate_dev_deps_pattern(pyproject_path): return requirements_pattern -def update_yarn_packages(bench_path=".", apps=None): +def update_yarn_packages(bench_path=".", apps=None, verbose=None): + import bench.cli as bench_cli from bench.bench import Bench + verbose = bench_cli.verbose or verbose bench = Bench(bench_path) apps = apps or bench.apps apps_dir = os.path.join(bench.name, "apps") @@ -127,7 +129,8 @@ def update_yarn_packages(bench_path=".", apps=None): app_path = os.path.join(apps_dir, app) if os.path.exists(os.path.join(app_path, "package.json")): click.secho(f"\nInstalling node dependencies for {app}", fg="yellow") - bench.run("yarn install", cwd=app_path) + yarn_install = "yarn install --verbose" if verbose else "yarn install" + bench.run(yarn_install, cwd=app_path) def update_npm_packages(bench_path=".", apps=None): From 00391bfeb90ad59da93059745473e1eac4e5a5d1 Mon Sep 17 00:00:00 2001 From: Revant Nandgaonkar Date: Thu, 14 Sep 2023 04:35:30 +0530 Subject: [PATCH 2/4] feat: pass verbose to npm install --- bench/utils/bench.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index cbaa62968..44a1c457a 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -58,7 +58,7 @@ def update_node_packages(bench_path=".", apps=None, verbose=None): # After rollup was merged, frappe_version = 10.1 # if develop_verion is 11 and up, only then install yarn if v < LooseVersion("11.x.x-develop"): - update_npm_packages(bench_path, apps=apps) + update_npm_packages(bench_path, apps=apps, verbose=verbose) else: update_yarn_packages(bench_path, apps=apps, verbose=verbose) @@ -133,7 +133,9 @@ def update_yarn_packages(bench_path=".", apps=None, verbose=None): bench.run(yarn_install, cwd=app_path) -def update_npm_packages(bench_path=".", apps=None): +def update_npm_packages(bench_path=".", apps=None, verbose=None): + verbose = bench.cli.verbose or verbose + npm_install = "npm install --verbose" if verbose else "npm install" apps_dir = os.path.join(bench_path, "apps") package_json = {} @@ -165,7 +167,7 @@ def update_npm_packages(bench_path=".", apps=None): with open(os.path.join(bench_path, "package.json"), "w") as f: f.write(json.dumps(package_json, indent=1, sort_keys=True)) - exec_cmd("npm install", cwd=bench_path) + exec_cmd(npm_install, cwd=bench_path) def migrate_env(python, backup=False): From 2ec0c0a95ab896ed4d060b7774490015a2b3c320 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 3 Nov 2023 21:38:47 +0530 Subject: [PATCH 3/4] fix: more reliable gunicorn restart killasgroup will ensure that all child processes die even if gunicorn fails to do it. This isn't truly required because stopwaitsecs and gunicorn graceful timeout work fine. In any case, if supervisor has to send SIGKILL, it better send it to entire process group. --- bench/config/templates/supervisor.conf | 1 + 1 file changed, 1 insertion(+) diff --git a/bench/config/templates/supervisor.conf b/bench/config/templates/supervisor.conf index c6a0fb0d7..57fd85748 100644 --- a/bench/config/templates/supervisor.conf +++ b/bench/config/templates/supervisor.conf @@ -11,6 +11,7 @@ autorestart=true stdout_logfile={{ bench_dir }}/logs/web.log stderr_logfile={{ bench_dir }}/logs/web.error.log stopwaitsecs=40 +killasgroup=true user={{ user }} directory={{ sites_dir }} From 839bd7c630e82b89189da48fd67ecf6d7748bf79 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 7 Dec 2023 16:12:10 +0530 Subject: [PATCH 4/4] feat(supervisor): restart each group separately Signed-off-by: Akhil Narang --- bench/utils/bench.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bench/utils/bench.py b/bench/utils/bench.py index 44a1c457a..b825200db 100644 --- a/bench/utils/bench.py +++ b/bench/utils/bench.py @@ -310,22 +310,23 @@ def restart_supervisor_processes(bench_path=".", web_workers=False, _raise=False 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" + groups = [f"{bench_name}-web:\t"] elif f"{bench_name}-workers:" in supervisor_status: - group = f"{bench_name}-workers: {bench_name}-web:" + groups = [f"{bench_name}-web:", f"{bench_name}-workers:"] # backward compatibility elif f"{bench_name}-processes:" in supervisor_status: - group = f"{bench_name}-processes:" + groups = [f"{bench_name}-processes:"] # backward compatibility else: - group = "frappe:" + groups = ["frappe:"] - failure = bench.run(f"{sudo}supervisorctl restart {group}", _raise=_raise) - if failure: - log("restarting supervisor failed. Use `bench restart` to retry.", level=3) + for group in groups: + failure = bench.run(f"{sudo}supervisorctl restart {group}", _raise=_raise) + if failure: + log(f"restarting supervisor group `{group}` failed. Use `bench restart` to retry.", level=3) def restart_systemd_processes(bench_path=".", web_workers=False, _raise=True):