Skip to content

Commit

Permalink
fix: ignore supervisor restart failures where possible
Browse files Browse the repository at this point in the history
Ignores proc manager restart failure during:
- App install
- App uninstall

Reason:
- You might not have setup prod yet
- This is useful during docker image building where proc manager wont be
  running **yet**.
  • Loading branch information
ankush committed Dec 12, 2022
1 parent 2d0ba72 commit 47d0128
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
4 changes: 3 additions & 1 deletion bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,9 @@ def install_app(
build_assets(bench_path=bench_path, app=app)

if restart_bench:
bench.reload()
# Avoiding exceptions here as production might not be set-up
# OR we might just be generating docker images.
bench.reload(_raise=False)


def pull_apps(apps=None, bench_path=".", reset=False):
Expand Down
12 changes: 6 additions & 6 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@


class Base:
def run(self, cmd, cwd=None):
return exec_cmd(cmd, cwd=cwd or self.cwd)
def run(self, cmd, cwd=None, _raise=True):
return exec_cmd(cmd, cwd=cwd or self.cwd, _raise=_raise)


class Validator:
Expand Down Expand Up @@ -133,24 +133,24 @@ def uninstall(self, app, no_backup=False, force=False):
raise
self.apps.sync()
# self.build() - removed because it seems unnecessary
self.reload()
self.reload(_raise=False)

@step(title="Building Bench Assets", success="Bench Assets Built")
def build(self):
# build assets & stuff
run_frappe_cmd("build", bench_path=self.name)

@step(title="Reloading Bench Processes", success="Bench Processes Reloaded")
def reload(self, web=False, supervisor=True, systemd=True):
def reload(self, web=False, supervisor=True, systemd=True, _raise=True):
"""If web is True, only web workers are restarted"""
conf = self.conf

if conf.get("developer_mode"):
restart_process_manager(bench_path=self.name, web_workers=web)
if supervisor or conf.get("restart_supervisor_on_update"):
restart_supervisor_processes(bench_path=self.name, web_workers=web)
restart_supervisor_processes(bench_path=self.name, web_workers=web, _raise=_raise)
if systemd and conf.get("restart_systemd_on_update"):
restart_systemd_processes(bench_path=self.name, web_workers=web)
restart_systemd_processes(bench_path=self.name, web_workers=web, _raise=_raise)

def get_installed_apps(self) -> List:
"""Returns list of installed apps on bench, not in excluded_apps.txt"""
Expand Down
16 changes: 10 additions & 6 deletions bench/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def patch_sites(bench_path="."):
raise PatchError


def restart_supervisor_processes(bench_path=".", web_workers=False):
def restart_supervisor_processes(bench_path=".", web_workers=False, _raise=False):
from bench.bench import Bench

bench = Bench(bench_path)
Expand All @@ -285,7 +285,7 @@ def restart_supervisor_processes(bench_path=".", web_workers=False):
bench_name = get_bench_name(bench_path)

if cmd:
bench.run(cmd)
bench.run(cmd, _raise=_raise)

else:
sudo = ""
Expand All @@ -312,18 +312,22 @@ def restart_supervisor_processes(bench_path=".", web_workers=False):
else:
group = "frappe:"

bench.run(f"{sudo}supervisorctl restart {group}")
success = bench.run(f"{sudo}supervisorctl restart {group}", _raise=_raise)
if not success:
log("restarting supervisor failed. Use `bench restart` to retry.", level=3)


def restart_systemd_processes(bench_path=".", web_workers=False):
def restart_systemd_processes(bench_path=".", web_workers=False, _raise=True):
bench_name = get_bench_name(bench_path)
exec_cmd(
f"sudo systemctl stop -- $(systemctl show -p Requires {bench_name}.target | cut"
" -d= -f2)"
" -d= -f2)",
_raise=_raise,
)
exec_cmd(
f"sudo systemctl start -- $(systemctl show -p Requires {bench_name}.target |"
" cut -d= -f2)"
" cut -d= -f2)",
_raise=_raise,
)


Expand Down

0 comments on commit 47d0128

Please sign in to comment.