From 0926d40247c00a9b1318a9a6c92b3dbba0a3d492 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 2 Mar 2022 20:43:16 +0100 Subject: [PATCH] fix: Reload haproxy if new cert is added --- src/lib/letsencrypt/index.ts | 21 +++++++++++++++++++++ src/lib/queues/index.ts | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/lib/letsencrypt/index.ts b/src/lib/letsencrypt/index.ts index 456c5bc6d..61a8c0c37 100644 --- a/src/lib/letsencrypt/index.ts +++ b/src/lib/letsencrypt/index.ts @@ -48,6 +48,17 @@ export async function letsEncrypt(domain, id = null, isCoolify = false) { } } if (dualCerts) { + let found = false; + try { + await asyncExecShell( + `DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "ls -1 /app/ssl/${wwwDomain}.pem"` + ); + found = true; + } catch (error) { + // + } + if (found) return; + await asyncExecShell( `DOCKER_HOST=${host} docker run --rm --name certbot-${randomCuid} -p 9080:${randomPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${randomPort} -d ${nakedDomain} -d ${wwwDomain} --expand --agree-tos --non-interactive --register-unsafely-without-email ${ dev ? '--test-cert' : '' @@ -58,6 +69,16 @@ export async function letsEncrypt(domain, id = null, isCoolify = false) { ); await reloadHaproxy(host); } else { + let found = false; + try { + await asyncExecShell( + `DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "ls -1 /app/ssl/${domain}.pem"` + ); + found = true; + } catch (error) { + // + } + if (found) return; await asyncExecShell( `DOCKER_HOST=${host} docker run --rm --name certbot-${randomCuid} -p 9080:${randomPort} -v "coolify-letsencrypt:/etc/letsencrypt" certbot/certbot --logs-dir /etc/letsencrypt/logs certonly --standalone --preferred-challenges http --http-01-address 0.0.0.0 --http-01-port ${randomPort} -d ${domain} --expand --agree-tos --non-interactive --register-unsafely-without-email ${ dev ? '--test-cert' : '' diff --git a/src/lib/queues/index.ts b/src/lib/queues/index.ts index f002547e8..f2ea96347 100644 --- a/src/lib/queues/index.ts +++ b/src/lib/queues/index.ts @@ -86,7 +86,7 @@ const cron = async () => { ); await queue.proxy.add('proxy', {}, { repeat: { every: 10000 } }); - await queue.ssl.add('ssl', {}, { repeat: { every: 60000 } }); + await queue.ssl.add('ssl', {}, { repeat: { every: dev ? 10000 : 60000 } }); await queue.cleanup.add('cleanup', {}, { repeat: { every: 300000 } }); await queue.sslRenew.add('sslRenew', {}, { repeat: { every: 1800000 } });