From a3af905d929fd1e69e35561d9601d56951650444 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 4 Aug 2022 12:13:10 +0530 Subject: [PATCH 1/3] feat: Allow skipping supervisord config check in setup supervisor --- bench/commands/setup.py | 14 +++++++++++--- bench/config/production_setup.py | 2 +- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 4d1fa88a..6b9ead6c 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -49,7 +49,13 @@ def reload_nginx(): @click.option( "--skip-redis", help="Skip redis configuration", is_flag=True, default=False ) -def setup_supervisor(user=None, yes=False, skip_redis=False): +@click.option( + "--skip-supervisord", + help="Skip supervisord configuration", + is_flag=True, + default=False, +) +def setup_supervisor(user=None, yes=False, skip_redis=False, skip_supervisord=False): from bench.utils import get_cmd_output from bench.config.supervisor import ( update_supervisord_config, @@ -58,8 +64,10 @@ def setup_supervisor(user=None, yes=False, skip_redis=False): which("supervisorctl", raise_err=True) - if "Permission denied" in get_cmd_output("supervisorctl status"): - update_supervisord_config(user=user, yes=yes) + if not skip_supervisord and "Permission denied" in get_cmd_output( + "supervisorctl status" + ): + update_supervisord_config(user=user) generate_supervisor_config(bench_path=".", user=user, yes=yes, skip_redis=skip_redis) diff --git a/bench/config/production_setup.py b/bench/config/production_setup.py index 719f90d2..390c3a57 100755 --- a/bench/config/production_setup.py +++ b/bench/config/production_setup.py @@ -48,7 +48,7 @@ def setup_production(user, bench_path=".", yes=False): generate_systemd_config(bench_path=bench_path, user=user, yes=yes) else: print("Setting Up supervisor...") - update_supervisord_config(user=user, yes=yes) + update_supervisord_config(user=user) generate_supervisor_config(bench_path=bench_path, user=user, yes=yes) print("Setting Up NGINX...") From db13ce3732eadd0438d1f3c1e9e7b47abf8d322c Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 4 Aug 2022 12:14:07 +0530 Subject: [PATCH 2/3] fix!: Don't update supervisord conf - instead just suggest --- bench/config/supervisor.py | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/bench/config/supervisor.py b/bench/config/supervisor.py index d4d6b14e..42c7a1e3 100644 --- a/bench/config/supervisor.py +++ b/bench/config/supervisor.py @@ -79,10 +79,11 @@ def get_supervisord_conf(): return possibility -def update_supervisord_config(user=None, yes=False): +def update_supervisord_config(user=None): """From bench v5.x, we're moving to supervisor running as user""" + # i don't think bench should be responsible for this but we're way past this now... + # removed updating supervisord conf & reload in Aug 2022 - gavin@frappe.io import configparser - from bench.config.production_setup import service if not user: user = getpass.getuser() @@ -125,20 +126,3 @@ def update_supervisord_config(user=None, yes=False): print( f"Update your {supervisord_conf} with the following values:\n[{section}]\n{contents}" ) - return - - if not yes: - click.confirm( - f"{supervisord_conf} will be updated with the following values:\n{supervisord_conf_changes}\nDo you want to continue?", - abort=True, - ) - - try: - with open(supervisord_conf, "w") as f: - config.write(f) - logger.log(f"Updated supervisord.conf at '{supervisord_conf}'") - except Exception as e: - logger.log(f"Updating supervisord.conf failed due to '{e}'") - - # Reread supervisor configuration, reload supervisord and supervisorctl, restart services that were started - service("supervisor", "reload") From f734eef7a7b25023e7cd288e01eda1970d5a0192 Mon Sep 17 00:00:00 2001 From: Gavin D'souza Date: Thu, 4 Aug 2022 12:15:51 +0530 Subject: [PATCH 3/3] refactor: check_supervisord_config --- bench/commands/setup.py | 4 ++-- bench/config/production_setup.py | 4 ++-- bench/config/supervisor.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 6b9ead6c..6869d034 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -58,7 +58,7 @@ def reload_nginx(): def setup_supervisor(user=None, yes=False, skip_redis=False, skip_supervisord=False): from bench.utils import get_cmd_output from bench.config.supervisor import ( - update_supervisord_config, + check_supervisord_config, generate_supervisor_config, ) @@ -67,7 +67,7 @@ def setup_supervisor(user=None, yes=False, skip_redis=False, skip_supervisord=Fa if not skip_supervisord and "Permission denied" in get_cmd_output( "supervisorctl status" ): - update_supervisord_config(user=user) + check_supervisord_config(user=user) generate_supervisor_config(bench_path=".", user=user, yes=yes, skip_redis=skip_redis) diff --git a/bench/config/production_setup.py b/bench/config/production_setup.py index 390c3a57..d110c36c 100755 --- a/bench/config/production_setup.py +++ b/bench/config/production_setup.py @@ -9,7 +9,7 @@ import bench from bench.config.nginx import make_nginx_conf from bench.config.supervisor import ( generate_supervisor_config, - update_supervisord_config, + check_supervisord_config, ) from bench.config.systemd import generate_systemd_config from bench.bench import Bench @@ -48,7 +48,7 @@ def setup_production(user, bench_path=".", yes=False): generate_systemd_config(bench_path=bench_path, user=user, yes=yes) else: print("Setting Up supervisor...") - update_supervisord_config(user=user) + check_supervisord_config(user=user) generate_supervisor_config(bench_path=bench_path, user=user, yes=yes) print("Setting Up NGINX...") diff --git a/bench/config/supervisor.py b/bench/config/supervisor.py index 42c7a1e3..d38da668 100644 --- a/bench/config/supervisor.py +++ b/bench/config/supervisor.py @@ -79,7 +79,7 @@ def get_supervisord_conf(): return possibility -def update_supervisord_config(user=None): +def check_supervisord_config(user=None): """From bench v5.x, we're moving to supervisor running as user""" # i don't think bench should be responsible for this but we're way past this now... # removed updating supervisord conf & reload in Aug 2022 - gavin@frappe.io