From acacef95cdd704d9dfabef8ede5e01a8aba53842 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 2 Mar 2022 12:10:12 +0100 Subject: [PATCH] fix: reload proxy on ssl cert --- src/lib/letsencrypt/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/letsencrypt/index.ts b/src/lib/letsencrypt/index.ts index 43e5d8a63..a89417eb8 100644 --- a/src/lib/letsencrypt/index.ts +++ b/src/lib/letsencrypt/index.ts @@ -1,5 +1,5 @@ import { asyncExecShell, getDomain, getEngine } from '$lib/common'; -import { checkContainer } from '$lib/haproxy'; +import { checkContainer, reloadHaproxy } from '$lib/haproxy'; import * as db from '$lib/database'; import { dev } from '$app/env'; import cuid from 'cuid'; @@ -56,6 +56,7 @@ export async function letsEncrypt(domain, id = null, isCoolify = false) { await asyncExecShell( `DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "test -d /etc/letsencrypt/live/${nakedDomain}/ && cat /etc/letsencrypt/live/${nakedDomain}/fullchain.pem /etc/letsencrypt/live/${nakedDomain}/privkey.pem > /app/ssl/${nakedDomain}.pem || cat /etc/letsencrypt/live/${wwwDomain}/fullchain.pem /etc/letsencrypt/live/${wwwDomain}/privkey.pem > /app/ssl/${wwwDomain}.pem"` ); + await reloadHaproxy(host); } else { 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 ${ @@ -65,6 +66,7 @@ export async function letsEncrypt(domain, id = null, isCoolify = false) { await asyncExecShell( `DOCKER_HOST=${host} docker run --rm -v "coolify-letsencrypt:/etc/letsencrypt" -v "coolify-ssl-certs:/app/ssl" alpine:latest sh -c "cat /etc/letsencrypt/live/${domain}/fullchain.pem /etc/letsencrypt/live/${domain}/privkey.pem > /app/ssl/${domain}.pem"` ); + await reloadHaproxy(host); } } catch (error) { if (error.code !== 0) { @@ -142,9 +144,11 @@ export async function generateSSLCerts() { const isHttps = fqdn.startsWith('https://'); if (isHttps) ssls.push({ domain, id: 'coolify', isCoolify: true }); } + console.log(ssls); if (ssls.length > 0) { for (const ssl of ssls) { if (!dev) { + console.log('Generate ssl for', ssl.domain); await letsEncrypt(ssl.domain, ssl.id, ssl.isCoolify); } else { console.log('Generate ssl for', ssl.domain);