Skip to content

Commit

Permalink
merge: merged develop into dependency-resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Aradhya-Tripathi committed Mar 21, 2022
2 parents dd97c43 + 8abdbf2 commit d514f84
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def get_app(
or overwrite
or click.confirm("Do you want to reinstall the existing application?")
):
app.install(verbose=verbose, skip_assets=skip_assets)
app.install(verbose=verbose, skip_assets=skip_assets, restart_bench=restart_bench)


def install_resolved_deps(
Expand Down
4 changes: 2 additions & 2 deletions bench/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def reload(self, web=False, supervisor=True, systemd=True):

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

def get_installed_apps(self) -> List:
Expand Down
9 changes: 7 additions & 2 deletions bench/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import click

# imports - module imports
from bench.utils import exec_cmd, run_playbook
from bench.utils import exec_cmd, run_playbook, which


@click.group(help="Setup command group for enabling setting up a Frappe environment")
Expand Down Expand Up @@ -41,9 +41,14 @@ def reload_nginx():
@click.option("--yes", help="Yes to regeneration of supervisor config", is_flag=True, default=False)
@click.option("--skip-redis", help="Skip redis configuration", is_flag=True, default=False)
def setup_supervisor(user=None, yes=False, skip_redis=False):
from bench.utils import get_cmd_output
from bench.config.supervisor import update_supervisord_config, generate_supervisor_config

update_supervisord_config(user=user, yes=yes)
which("supervisorctl", raise_err=True)

if "Permission denied" in get_cmd_output("supervisorctl status"):
update_supervisord_config(user=user, yes=yes)

generate_supervisor_config(bench_path=".", user=user, yes=yes, skip_redis=skip_redis)


Expand Down
3 changes: 3 additions & 0 deletions bench/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ 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
if not systemd and not web:
supervisor = True

Bench(".").reload(web, supervisor, systemd)


Expand Down
4 changes: 3 additions & 1 deletion bench/config/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ def update_supervisord_config(user=None, yes=False):
supervisord_conf_changes += '\n' + action

if not supervisord_conf_changes:
logger.log("supervisord.conf not updated")
logger.error("supervisord.conf not updated")
contents = "\n".join(f"{x}={y}" for x, y in updated_values.items())
print(f"Update your {supervisord_conf} with the following values:\n[{section}]\n{contents}")
return

if not yes:
Expand Down
10 changes: 8 additions & 2 deletions bench/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def which(executable: str, raise_err: bool = False) -> str:
exec_ = which(executable)

if not exec_ and raise_err:
raise ValueError(f"{executable} not found.")
raise FileNotFoundError(f"{executable} not found in PATH")

return exec_

Expand Down Expand Up @@ -342,7 +342,13 @@ def find_benches(directory: str = None) -> List:
return

benches = []
for sub in os.listdir(directory):

try:
sub_directories = os.listdir(directory)
except PermissionError:
return benches

for sub in sub_directories:
sub = os.path.join(directory, sub)
if os.path.isdir(sub) and not os.path.islink(sub):
if is_bench_directory(sub):
Expand Down
12 changes: 10 additions & 2 deletions bench/utils/bench.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,15 @@ def restart_supervisor_processes(bench_path=".", web_workers=False):
bench.run(cmd)

else:
supervisor_status = get_cmd_output("supervisorctl status", cwd=bench_path)
sudo = ""
try:
supervisor_status = get_cmd_output("supervisorctl status", cwd=bench_path)
except Exception as e:
if e.returncode == 127:
log("restart failed: Couldn't find supervisorctl in PATH", level=3)
return
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"
Expand All @@ -269,7 +277,7 @@ def restart_supervisor_processes(bench_path=".", web_workers=False):
else:
group = "frappe:"

bench.run(f"supervisorctl restart {group}")
bench.run(f"{sudo}supervisorctl restart {group}")


def restart_systemd_processes(bench_path=".", web_workers=False):
Expand Down

0 comments on commit d514f84

Please sign in to comment.