mirror of
https://github.com/frappe/bench.git
synced 2024-11-16 01:57:08 +00:00
refactor: Bench restart
* Commonify reloading processes' logic * Add functionality to restart web workers in development * Use Bench.reload instead
This commit is contained in:
parent
cbf30b4e6a
commit
814bcc6320
@ -26,10 +26,7 @@ from bench.utils import (
|
||||
)
|
||||
from bench.utils.bench import (
|
||||
build_assets,
|
||||
get_env_cmd,
|
||||
install_python_dev_dependencies,
|
||||
restart_supervisor_processes,
|
||||
restart_systemd_processes,
|
||||
)
|
||||
from bench.utils.render import step
|
||||
|
||||
@ -417,10 +414,7 @@ def install_app(
|
||||
build_assets(bench_path=bench_path, app=app)
|
||||
|
||||
if restart_bench:
|
||||
if conf.get("restart_supervisor_on_update"):
|
||||
restart_supervisor_processes(bench_path=bench_path)
|
||||
if conf.get("restart_systemd_on_update"):
|
||||
restart_systemd_processes(bench_path=bench_path)
|
||||
bench.reload()
|
||||
|
||||
|
||||
def pull_apps(apps=None, bench_path=".", reset=False):
|
||||
|
@ -131,14 +131,18 @@ class Bench(Base, Validator):
|
||||
run_frappe_cmd("build", bench_path=self.name)
|
||||
|
||||
@step(title="Reloading Bench Processes", success="Bench Processes Reloaded")
|
||||
def reload(self):
|
||||
def reload(self, web=False, supervisor=True, systemd=True):
|
||||
"""If web is True, only web workers are restarted
|
||||
"""
|
||||
conf = self.conf
|
||||
if conf.get("restart_supervisor_on_update"):
|
||||
restart_supervisor_processes(bench_path=self.name)
|
||||
if conf.get("restart_systemd_on_update"):
|
||||
restart_systemd_processes(bench_path=self.name)
|
||||
|
||||
if conf.get("developer_mode"):
|
||||
restart_process_manager(bench_path=self.name)
|
||||
restart_process_manager(bench_path=self.name, web_workers=web)
|
||||
if supervisor and conf.get("restart_supervisor_on_update"):
|
||||
restart_supervisor_processes(bench_path=self.name, web_workers=web)
|
||||
if systemd and conf.get("restart_systemd_on_update"):
|
||||
restart_systemd_processes(bench_path=self.name, web_workers=web)
|
||||
|
||||
|
||||
class BenchApps(MutableSequence):
|
||||
def __init__(self, bench: Bench):
|
||||
|
@ -23,14 +23,7 @@ def start(no_dev, concurrency, procfile, no_prefix, man):
|
||||
@click.option('--systemd', is_flag=True, default=False)
|
||||
def restart(web, supervisor, systemd):
|
||||
from bench.bench import Bench
|
||||
from bench.utils.bench import restart_supervisor_processes, restart_systemd_processes
|
||||
|
||||
bench = Bench(".")
|
||||
|
||||
if bench.conf.get('restart_supervisor_on_update') or supervisor:
|
||||
restart_supervisor_processes(bench_path='.', web_workers=web)
|
||||
if bench.conf.get('restart_systemd_on_update') or systemd:
|
||||
restart_systemd_processes(bench_path='.', web_workers=web)
|
||||
Bench(".").reload(web, supervisor, systemd)
|
||||
|
||||
|
||||
@click.command('set-nginx-port', help="Set NGINX port for site")
|
||||
|
@ -279,12 +279,13 @@ def restart_systemd_processes(bench_path=".", web_workers=False):
|
||||
)
|
||||
|
||||
|
||||
def restart_process_manager(bench_path="."):
|
||||
def restart_process_manager(bench_path=".", web_workers=False):
|
||||
# only overmind has the restart feature, not sure other supported procmans do
|
||||
if which("overmind") and os.path.exists(
|
||||
os.path.join(bench_path, ".overmind.sock")
|
||||
):
|
||||
exec_cmd("overmind restart", cwd=bench_path)
|
||||
worker = "web" if web_workers else ""
|
||||
exec_cmd(f"overmind restart {worker}", cwd=bench_path)
|
||||
|
||||
|
||||
def build_assets(bench_path=".", app=None):
|
||||
@ -352,10 +353,6 @@ def update(
|
||||
|
||||
from bench.utils import clear_command_cache
|
||||
from bench.utils.app import is_version_upgrade
|
||||
from bench.utils.bench import (
|
||||
restart_supervisor_processes,
|
||||
restart_systemd_processes,
|
||||
)
|
||||
from bench.utils.system import backup_all_sites
|
||||
|
||||
bench_path = os.path.abspath(".")
|
||||
@ -414,11 +411,7 @@ def update(
|
||||
apps_dir = os.path.join(bench_path, "apps")
|
||||
compile_dir(apps_dir, quiet=1, rx=re.compile(".*node_modules.*"))
|
||||
|
||||
if restart_supervisor or conf.get("restart_supervisor_on_update"):
|
||||
restart_supervisor_processes(bench_path=bench_path)
|
||||
|
||||
if restart_systemd or conf.get("restart_systemd_on_update"):
|
||||
restart_systemd_processes(bench_path=bench_path)
|
||||
bench.reload(web=False, supervisor=restart_supervisor, systemd=restart_systemd)
|
||||
|
||||
conf.update({"maintenance_mode": 0, "pause_scheduler": 0})
|
||||
update_config(conf, bench_path=bench_path)
|
||||
|
Loading…
Reference in New Issue
Block a user