diff --git a/bench/commands/setup.py b/bench/commands/setup.py index bc663777..ba31ea7c 100755 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -258,10 +258,11 @@ def setup_nginx_proxy_jail(**kwargs): @click.command('systemd') @click.option('--user') @click.option('--yes', help='Yes to regeneration of systemd config files', is_flag=True, default=False) -def setup_systemd(user=None, yes=False): +@click.option('--stop', help='Stop bench services', is_flag=True, default=False) +def setup_systemd(user=None, yes=False, stop=False): "generate configs for systemd with an optional user argument" from bench.config.systemd import generate_systemd_config - generate_systemd_config(bench_path=".", user=user, yes=yes) + generate_systemd_config(bench_path=".", user=user, yes=yes, stop=stop) setup.add_command(setup_sudoers) setup.add_command(setup_nginx) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index 9445def6..c10fca08 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -13,13 +13,15 @@ def start(no_dev, concurrency): @click.command('restart') @click.option('--web', is_flag=True, default=False) -def restart(web): +@click.option('--supervisor', is_flag=True, default=False) +@click.option('--systemd', is_flag=True, default=False) +def restart(web, supervisor, systemd): "Restart supervisor processes or systemd units" from bench.utils import restart_supervisor_processes, restart_systemd_processes from bench.config.common_site_config import get_config - if get_config('.').get('restart_supervisor_on_update') == True: + if get_config('.').get('restart_supervisor_on_update') or supervisor: restart_supervisor_processes(bench_path='.', web_workers=web) - if get_config('.').get('restart_systemd_on_update'): + if get_config('.').get('restart_systemd_on_update') or systemd: restart_systemd_processes(bench_path='.', web_workers=web) @click.command('set-nginx-port') diff --git a/bench/config/systemd.py b/bench/config/systemd.py index 0ba80e52..9686ad56 100644 --- a/bench/config/systemd.py +++ b/bench/config/systemd.py @@ -1,7 +1,7 @@ import os, getpass, click import bench -def generate_systemd_config(bench_path, user=None, yes=False): +def generate_systemd_config(bench_path, user=None, yes=False, stop=False): from bench.app import get_current_frappe_version, use_rq from bench.utils import get_bench_name, find_executable from bench.config.common_site_config import get_config, update_config, get_gunicorn_workers @@ -14,6 +14,11 @@ def generate_systemd_config(bench_path, user=None, yes=False): bench_dir = os.path.abspath(bench_path) bench_name = get_bench_name(bench_path) + if stop: + from bench.utils import exec_cmd + exec_cmd('sudo systemctl stop -- $(systemctl show -p Requires {bench_name}.target | cut -d= -f2)'.format(bench_name=bench_name)) + return + bench_info = { "bench_dir": bench_dir, "sites_dir": os.path.join(bench_dir, 'sites'), diff --git a/bench/utils.py b/bench/utils.py index 88cd1768..8c55171f 100755 --- a/bench/utils.py +++ b/bench/utils.py @@ -398,34 +398,11 @@ def restart_supervisor_processes(bench_path='.', web_workers=False): exec_cmd('sudo supervisorctl restart {group}'.format(group=group), cwd=bench_path) def restart_systemd_processes(bench_path='.', web_workers=False): - print("Restarting . . .") - # from .config.common_site_config import get_config - # conf = get_config(bench_path=bench_path) - # bench_name = get_bench_name(bench_path) - - # cmd = conf.get('systemd_restart_cmd') - # if cmd: - # exec_cmd(cmd, cwd=bench_path) - - # else: - # systemd_status = subprocess.check_output(['sudo', 'systemctl', 'status'], cwd=bench_path) - # systemd_status = safe_decode(supervisor_status) - - # if web_workers and '{bench_name}-web:'.format(bench_name=bench_name) in systemd_status: - # group = '{bench_name}-web: '.format(bench_name=bench_name) - - # elif '{bench_name}-workers:'.format(bench_name=bench_name) in systemd_status: - # group = '{bench_name}-workers: {bench_name}-web:'.format(bench_name=bench_name) - - # # backward compatibility - # elif '{bench_name}-processes:'.format(bench_name=bench_name) in systemd_status: - # group = '{bench_name}-processes:'.format(bench_name=bench_name) - - # # backward compatibility - # else: - # group = 'frappe:' - - # exec_cmd('sudo systemctl restart {group}'.format(group=group), cwd=bench_path) + from .config.common_site_config import get_config + conf = get_config(bench_path=bench_path) + bench_name = get_bench_name(bench_path) + exec_cmd('sudo systemctl stop -- $(systemctl show -p Requires {bench_name}.target | cut -d= -f2)'.format(bench_name=bench_name)) + exec_cmd('sudo systemctl start {bench_name}.target'.format(bench_name=bench_name)) def set_default_site(site, bench_path='.'): if not site in get_sites(bench_path=bench_path):