skip_letsencrypt implemented

This commit is contained in:
Zsolt Ero
2024-10-23 23:22:00 +02:00
parent e800123093
commit 2084f24469
2 changed files with 33 additions and 28 deletions

View File

@@ -17,6 +17,7 @@ def write_nginx_config():
domain_le = config.ofm_config['domain_le'] domain_le = config.ofm_config['domain_le']
domain_ledns = config.ofm_config['domain_ledns'] domain_ledns = config.ofm_config['domain_ledns']
skip_letsencrypt = config.ofm_config['skip_letsencrypt']
# remove old configs and certs # remove old configs and certs
for file in Path('/data/nginx/sites').glob('ofm_*.conf'): for file in Path('/data/nginx/sites').glob('ofm_*.conf'):
@@ -58,36 +59,37 @@ def write_nginx_config():
subprocess.run(['nginx', '-t'], check=True) subprocess.run(['nginx', '-t'], check=True)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True) subprocess.run(['systemctl', 'reload', 'nginx'], check=True)
subprocess.run( if not skip_letsencrypt:
[ subprocess.run(
'certbot', [
'certonly', 'certbot',
'--webroot', 'certonly',
'--webroot-path=/data/nginx/acme-challenges', '--webroot',
'--noninteractive', '--webroot-path=/data/nginx/acme-challenges',
'-m', '--noninteractive',
config.ofm_config['le_email'], '-m',
'--agree-tos', config.ofm_config['le_email'],
'--cert-name=ofm_le', '--agree-tos',
# '--staging', '--cert-name=ofm_le',
'--deploy-hook', # '--staging',
'nginx -t && service nginx reload', '--deploy-hook',
'-d', 'nginx -t && service nginx reload',
domain_le, '-d',
], domain_le,
check=True, ],
) check=True,
)
# link certs to nginx dir # link certs to nginx dir
le_cert.unlink() le_cert.unlink()
le_key.unlink() le_key.unlink()
etc_cert = Path('/etc/letsencrypt/live/ofm_le/fullchain.pem') etc_cert = Path('/etc/letsencrypt/live/ofm_le/fullchain.pem')
etc_key = Path('/etc/letsencrypt/live/ofm_le/privkey.pem') etc_key = Path('/etc/letsencrypt/live/ofm_le/privkey.pem')
assert etc_cert.is_file() assert etc_cert.is_file()
assert etc_key.is_file() assert etc_key.is_file()
le_cert.symlink_to(etc_cert) le_cert.symlink_to(etc_cert)
le_key.symlink_to(etc_key) le_key.symlink_to(etc_key)
subprocess.run(['nginx', '-t'], check=True) subprocess.run(['nginx', '-t'], check=True)
subprocess.run(['systemctl', 'reload', 'nginx'], check=True) subprocess.run(['systemctl', 'reload', 'nginx'], check=True)

View File

@@ -22,6 +22,9 @@ PLANETILER_BIN = f'{TILE_GEN_DIR}/planetiler'
HTTP_HOST_BIN = f'{OFM_DIR}/http_host/bin' HTTP_HOST_BIN = f'{OFM_DIR}/http_host/bin'
# Handling multiple .env files is supported
# or example ENV=test would use .env.test
ENV = os.getenv('ENV') ENV = os.getenv('ENV')
if ENV: if ENV:
env_file_name = f'.env.{ENV}' env_file_name = f'.env.{ENV}'