diff --git a/bench/commands/__init__.py b/bench/commands/__init__.py index 9baf4bb7..4326ba42 100644 --- a/bench/commands/__init__.py +++ b/bench/commands/__init__.py @@ -45,8 +45,9 @@ bench_command.add_command(backup_all_sites) bench_command.add_command(release) bench_command.add_command(renew_lets_encrypt) -from bench.commands.setup import setup +from bench.commands.setup import setup, disable_production bench_command.add_command(setup) +bench_command.add_command(disable_production) from bench.commands.config import config bench_command.add_command(config) diff --git a/bench/commands/setup.py b/bench/commands/setup.py index 93676b15..9e547c7a 100644 --- a/bench/commands/setup.py +++ b/bench/commands/setup.py @@ -93,6 +93,11 @@ def setup_config(): from bench.config.common_site_config import make_config make_config('.') +@click.command('disable-production') +def disable_production(): + """Disable production environment for the bench""" + from bench.config.production_setup import disbable_production + disable_production('.') setup.add_command(setup_sudoers) setup.add_command(setup_nginx) diff --git a/bench/config/production_setup.py b/bench/config/production_setup.py index b4ab3bc1..c77608bb 100755 --- a/bench/config/production_setup.py +++ b/bench/config/production_setup.py @@ -29,6 +29,30 @@ def setup_production(user, bench_path='.'): service('nginx', 'restart') +def disable_production(bench_path='.'): + bench_name = get_bench_name(bench_path) + + # supervisorctl + 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 os.path.islink(supervisor_conf): + os.unlink(supervisor_conf) + + exec_cmd('supervisorctl reread') + exec_cmd('supervisorctl reload') + + # nginx + nginx_conf = '/etc/nginx/conf.f/{bench_name}.conf'.format(bench_name=bench_name) + if os.path.islink(nginx_conf): + os.unlink(nginx_conf) + + service('nginx', 'reload') + if os.environ.get('NO_SERVICE_RESTART'): + return + + service('nginx', 'restart') def service(service, option): if os.path.basename(get_program(['systemctl']) or '') == 'systemctl' and is_running_systemd():