From f62341dee9d6976aa89216ca9d89774e2e37fdc3 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Mon, 30 Apr 2018 16:07:37 +0530 Subject: [PATCH] modifications to setup production for systemd --- bench/config/production_setup.py | 31 +++++++++++++++++++++---------- bench/config/supervisor.py | 1 + bench/config/systemd.py | 1 + 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/bench/config/production_setup.py b/bench/config/production_setup.py index afde3ff8..026d78bc 100755 --- a/bench/config/production_setup.py +++ b/bench/config/production_setup.py @@ -1,10 +1,18 @@ from bench.utils import get_program, exec_cmd, get_cmd_output, fix_prod_setup_perms, get_bench_name, find_executable, CommandFailedError from bench.config.supervisor import generate_supervisor_config +from bench.config.systemd import generate_systemd_config from bench.config.nginx import make_nginx_conf +from bench.config.common_site_config import get_config import os, subprocess def setup_production(user, bench_path='.', yes=False): - generate_supervisor_config(bench_path=bench_path, user=user, yes=yes) + if get_config(bench_path).get('restart_supervisor_on_update') and get_config(bench_path).get('restart_systemd_on_update'): + raise Exception("You cannot use supervisor and systemd at the same time. Modify your common_site_config accordingly." ) + + if get_config(bench_path).get('restart_systemd_on_update'): + generate_systemd_config(bench_path=bench_path, user=user, yes=yes) + else: + generate_supervisor_config(bench_path=bench_path, user=user, yes=yes) make_nginx_conf(bench_path=bench_path, yes=yes) fix_prod_setup_perms(bench_path, frappe_user=user) remove_default_nginx_configs() @@ -12,18 +20,20 @@ def setup_production(user, bench_path='.', yes=False): bench_name = get_bench_name(bench_path) nginx_conf = '/etc/nginx/conf.d/{bench_name}.conf'.format(bench_name=bench_name) - supervisor_conf_extn = "ini" if is_centos7() else "conf" - supervisor_conf = os.path.join(get_supervisor_confdir(), '{bench_name}.{extn}'.format( - bench_name=bench_name, extn=supervisor_conf_extn)) + if get_config(bench_path).get('restart_supervisor_on_update'): + supervisor_conf_extn = "ini" if is_centos7() else "conf" + supervisor_conf = os.path.join(get_supervisor_confdir(), '{bench_name}.{extn}'.format( + bench_name=bench_name, extn=supervisor_conf_extn)) - # Check if symlink exists, If not then create it. - if not os.path.islink(supervisor_conf): - os.symlink(os.path.abspath(os.path.join(bench_path, 'config', 'supervisor.conf')), supervisor_conf) + # Check if symlink exists, If not then create it. + if not os.path.islink(supervisor_conf): + os.symlink(os.path.abspath(os.path.join(bench_path, 'config', 'supervisor.conf')), supervisor_conf) if not os.path.islink(nginx_conf): os.symlink(os.path.abspath(os.path.join(bench_path, 'config', 'nginx.conf')), nginx_conf) - reload_supervisor() + if get_config(bench_path).get('restart_supervisor_on_update'): + reload_supervisor() if os.environ.get('NO_SERVICE_RESTART'): return @@ -41,8 +51,9 @@ def disable_production(bench_path='.'): if os.path.islink(supervisor_conf): os.unlink(supervisor_conf) - exec_cmd('sudo supervisorctl reread') - exec_cmd('sudo supervisorctl update') + if get_config(bench_path).get('restart_supervisor_on_update'): + exec_cmd('sudo supervisorctl reread') + exec_cmd('sudo supervisorctl update') # nginx nginx_conf = '/etc/nginx/conf.d/{bench_name}.conf'.format(bench_name=bench_name) diff --git a/bench/config/supervisor.py b/bench/config/supervisor.py index 27396b15..60db0018 100644 --- a/bench/config/supervisor.py +++ b/bench/config/supervisor.py @@ -42,4 +42,5 @@ def generate_supervisor_config(bench_path, user=None, yes=False): f.write(config) update_config({'restart_supervisor_on_update': True}, bench_path=bench_path) + update_config({'restart_systemd_on_update': False}, bench_path=bench_path) diff --git a/bench/config/systemd.py b/bench/config/systemd.py index 856d1083..72bed1f2 100644 --- a/bench/config/systemd.py +++ b/bench/config/systemd.py @@ -70,6 +70,7 @@ def generate_systemd_config(bench_path, user=None, yes=False, setup_redis_config(bench_info, bench_path) update_config({'restart_systemd_on_update': True}, bench_path=bench_path) + update_config({'restart_supervisor_on_update': False}, bench_path=bench_path) def setup_systemd_directory(bench_path): if not os.path.exists(os.path.join(bench_path, 'config', 'systemd')):