diff --git a/bench/app.py b/bench/app.py index 443156f3..436700c3 100755 --- a/bench/app.py +++ b/bench/app.py @@ -1,6 +1,7 @@ import os from .utils import (exec_cmd, get_frappe, check_git_for_shallow_clone, build_assets, - restart_supervisor_processes, get_cmd_output, run_frappe_cmd, CommandFailedError) + restart_supervisor_processes, get_cmd_output, run_frappe_cmd, CommandFailedError, + restart_systemd_processes) from .config.common_site_config import get_config import logging @@ -110,6 +111,8 @@ def get_app(git_url, branch=None, bench_path='.', build_asset_files=True, verbos conf = get_config(bench_path=bench_path) 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) def new_app(app, bench_path='.'): # For backwards compatibility @@ -160,7 +163,8 @@ def remove_app(app, bench_path='.'): run_frappe_cmd("build", bench_path=bench_path) if get_config(bench_path).get('restart_supervisor_on_update'): restart_supervisor_processes(bench_path=bench_path) - + if get_config(bench_path).get('restart_systemd_on_update'): + restart_systemd_processes(bench_path=bench_path) def pull_all_apps(bench_path='.', reset=False): '''Check all apps if there no local changes, pull''' diff --git a/bench/commands/config.py b/bench/commands/config.py index cd94985a..a7a0f3ec 100644 --- a/bench/commands/config.py +++ b/bench/commands/config.py @@ -23,6 +23,12 @@ def config_restart_supervisor_on_update(state): state = True if state == 'on' else False update_config({'restart_supervisor_on_update': state}) +@click.command('restart_systemd_on_update') +@click.argument('state', type=click.Choice(['on', 'off'])) +def config_restart_systemd_on_update(state): + "Enable/Disable auto restart of systemd units" + state = True if state == 'on' else False + update_config({'restart_systemd_on_update': state}) @click.command('update_bench_on_update') @click.argument('state', type=click.Choice(['on', 'off'])) @@ -112,6 +118,7 @@ def remove_common_config(keys): config.add_command(config_auto_update) config.add_command(config_update_bench_on_update) config.add_command(config_restart_supervisor_on_update) +config.add_command(config_restart_systemd_on_update) config.add_command(config_dns_multitenant) config.add_command(config_serve_default_site) config.add_command(config_http_timeout) diff --git a/bench/commands/utils.py b/bench/commands/utils.py index 3a3202c4..9445def6 100644 --- a/bench/commands/utils.py +++ b/bench/commands/utils.py @@ -14,10 +14,13 @@ def start(no_dev, concurrency): @click.command('restart') @click.option('--web', is_flag=True, default=False) def restart(web): - "Restart supervisor processes" - from bench.utils import restart_supervisor_processes - restart_supervisor_processes(bench_path='.', web_workers=web) - + "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: + restart_supervisor_processes(bench_path='.', web_workers=web) + if get_config('.').get('restart_systemd_on_update'): + restart_systemd_processes(bench_path='.', web_workers=web) @click.command('set-nginx-port') @click.argument('site') diff --git a/bench/config/common_site_config.py b/bench/config/common_site_config.py index f99b07cb..d0cbddb2 100644 --- a/bench/config/common_site_config.py +++ b/bench/config/common_site_config.py @@ -7,6 +7,7 @@ except ImportError: default_config = { 'restart_supervisor_on_update': False, + 'restart_systemd_on_update': False, 'auto_update': False, 'serve_default_site': True, 'rebase_on_pull': False,