Skip to content

Commit

Permalink
fix: dont abort script if not overwriting scripts
Browse files Browse the repository at this point in the history
why: currently, running of `bench ` or `bench setup
production` creates nginx conf files and asks for confirmation before
overwriting them. in case user doesnt want to overwrite files,
`setup production` and `lets-encrypt` is exitted abrubtly and nginx isnt started again after
  • Loading branch information
gavindsouza committed Feb 10, 2020
1 parent 50ef739 commit ba90c9f
Showing 1 changed file with 39 additions and 39 deletions.
78 changes: 39 additions & 39 deletions bench/config/nginx.py
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
import os, json, click, random, string, hashlib
from bench.utils import get_sites, get_bench_name, exec_cmd
from six import string_types
from six.moves import input

def make_nginx_conf(bench_path, yes=False):
from bench import env
from bench.config.common_site_config import get_config

template = env.get_template('nginx.conf')
bench_path = os.path.abspath(bench_path)
sites_path = os.path.join(bench_path, "sites")

config = get_config(bench_path)
sites = prepare_sites(config, bench_path)
bench_name = get_bench_name(bench_path)

allow_rate_limiting = config.get('allow_rate_limiting', False)

template_vars = {
"sites_path": sites_path,
"http_timeout": config.get("http_timeout"),
"sites": sites,
"webserver_port": config.get('webserver_port'),
"socketio_port": config.get('socketio_port'),
"bench_name": bench_name,
"error_pages": get_error_pages(),
"allow_rate_limiting": allow_rate_limiting,
# for nginx map variable
"random_string": "".join(random.choice(string.ascii_lowercase) for i in range(7))
}

if allow_rate_limiting:
template_vars.update({
'bench_name_hash': hashlib.sha256(bench_name).hexdigest()[:16],
'limit_conn_shared_memory': get_limit_conn_shared_memory()
})

nginx_conf = template.render(**template_vars)

def make_nginx_conf(bench_path, yes=False):
conf_path = os.path.join(bench_path, "config", "nginx.conf")
if not yes and os.path.exists(conf_path):
click.confirm('nginx.conf already exists and this will overwrite it. Do you want to continue?',
abort=True)

with open(conf_path, "w") as f:
f.write(nginx_conf)
if input('nginx.conf already exists and this will overwrite it. Do you want to continue? [y/N]').lower() == 'y':
from bench import env
from bench.config.common_site_config import get_config

template = env.get_template('nginx.conf')
bench_path = os.path.abspath(bench_path)
sites_path = os.path.join(bench_path, "sites")

config = get_config(bench_path)
sites = prepare_sites(config, bench_path)
bench_name = get_bench_name(bench_path)

allow_rate_limiting = config.get('allow_rate_limiting', False)

template_vars = {
"sites_path": sites_path,
"http_timeout": config.get("http_timeout"),
"sites": sites,
"webserver_port": config.get('webserver_port'),
"socketio_port": config.get('socketio_port'),
"bench_name": bench_name,
"error_pages": get_error_pages(),
"allow_rate_limiting": allow_rate_limiting,
# for nginx map variable
"random_string": "".join(random.choice(string.ascii_lowercase) for i in range(7))
}

if allow_rate_limiting:
template_vars.update({
'bench_name_hash': hashlib.sha256(bench_name).hexdigest()[:16],
'limit_conn_shared_memory': get_limit_conn_shared_memory()
})

nginx_conf = template.render(**template_vars)

with open(conf_path, "w") as f:
f.write(nginx_conf)

def make_bench_manager_nginx_conf(bench_path, yes=False, port=23624, domain=None):
from bench import env
Expand Down

0 comments on commit ba90c9f

Please sign in to comment.