2
0
mirror of https://github.com/frappe/bench.git synced 2025-01-24 15:38:25 +00:00

fixed lets-encrypt non interactive mode

This commit is contained in:
Ameya Shenoy 2018-04-26 15:50:38 +00:00
parent 8de6f0dda5
commit 8e2b55887e
2 changed files with 8 additions and 6 deletions

View File

@ -121,10 +121,11 @@ def set_ssh_port(port, force=False):
@click.command('lets-encrypt') @click.command('lets-encrypt')
@click.argument('site') @click.argument('site')
@click.option('--custom-domain') @click.option('--custom-domain')
def setup_letsencrypt(site, custom_domain): @click.option('-n', '--non-interactive', default=False, is_flag=True, help="Run certbot non-interactively. Shouldn't be used on 1'st attempt")
def setup_letsencrypt(site, custom_domain, non_interactive):
"Setup lets-encrypt for site" "Setup lets-encrypt for site"
from bench.config.lets_encrypt import setup_letsencrypt from bench.config.lets_encrypt import setup_letsencrypt
setup_letsencrypt(site, custom_domain, bench_path='.') setup_letsencrypt(site, custom_domain, bench_path='.', interactive=not non_interactive)
@click.command('procfile') @click.command('procfile')

View File

@ -11,7 +11,7 @@ try:
except ImportError: except ImportError:
from urllib import urlretrieve from urllib import urlretrieve
def setup_letsencrypt(site, custom_domain, bench_path): def setup_letsencrypt(site, custom_domain, bench_path, interactive):
site_path = os.path.join(bench_path, "sites", site, "site_config.json") site_path = os.path.join(bench_path, "sites", site, "site_config.json")
if not os.path.exists(os.path.dirname(site_path)): if not os.path.exists(os.path.dirname(site_path)):
@ -38,7 +38,7 @@ def setup_letsencrypt(site, custom_domain, bench_path):
return return
create_config(site, custom_domain) create_config(site, custom_domain)
run_certbot_and_setup_ssl(site, custom_domain, bench_path) run_certbot_and_setup_ssl(site, custom_domain, bench_path, interactive)
setup_crontab() setup_crontab()
@ -51,12 +51,13 @@ def create_config(site, custom_domain):
f.write(config) f.write(config)
def run_certbot_and_setup_ssl(site, custom_domain, bench_path): def run_certbot_and_setup_ssl(site, custom_domain, bench_path, interactive=True):
service('nginx', 'stop') service('nginx', 'stop')
get_certbot() get_certbot()
try: try:
exec_cmd("{path} -n --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), site=custom_domain or site)) interactive = '' if interactive else '-n'
exec_cmd("{path} {interactive} --config /etc/letsencrypt/configs/{site}.cfg certonly".format(path=get_certbot_path(), interactive=interactive, site=custom_domain or site))
except CommandFailedError: except CommandFailedError:
service('nginx', 'start') service('nginx', 'start')
print("There was a problem trying to setup SSL for your site") print("There was a problem trying to setup SSL for your site")