Fix: Handle existing SSL certificates in setup script
- Added check for existing SSL certificates before attempting to create new ones - Restore original HTTPS nginx.conf after certificate verification - This prevents the script from hanging when certificates already exist
This commit is contained in:
@@ -96,9 +96,14 @@ ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml up -d nginx
|
|||||||
echo -e "${YELLOW}⏳ Warte auf Nginx...${NC}"
|
echo -e "${YELLOW}⏳ Warte auf Nginx...${NC}"
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
# Erstelle SSL-Zertifikat
|
# Prüfe ob SSL-Zertifikat bereits existiert
|
||||||
echo -e "${YELLOW}🔐 Erstelle SSL-Zertifikat für $DOMAIN...${NC}"
|
echo -e "${YELLOW}🔍 Prüfe vorhandene SSL-Zertifikate...${NC}"
|
||||||
${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certonly \
|
if ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certificates -d $DOMAIN | grep -q "Certificate Name: $DOMAIN"; then
|
||||||
|
echo -e "${GREEN}✅ SSL-Zertifikat für $DOMAIN bereits vorhanden!${NC}"
|
||||||
|
else
|
||||||
|
# Erstelle SSL-Zertifikat
|
||||||
|
echo -e "${YELLOW}🔐 Erstelle SSL-Zertifikat für $DOMAIN...${NC}"
|
||||||
|
${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certonly \
|
||||||
--webroot \
|
--webroot \
|
||||||
--webroot-path=/var/www/certbot \
|
--webroot-path=/var/www/certbot \
|
||||||
--email $ADMIN_EMAIL \
|
--email $ADMIN_EMAIL \
|
||||||
@@ -107,19 +112,22 @@ ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot cer
|
|||||||
--force-renewal \
|
--force-renewal \
|
||||||
-d $DOMAIN
|
-d $DOMAIN
|
||||||
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo -e "${GREEN}✅ SSL-Zertifikat erfolgreich erstellt!${NC}"
|
echo -e "${GREEN}✅ SSL-Zertifikat erfolgreich erstellt!${NC}"
|
||||||
else
|
else
|
||||||
echo -e "${RED}❌ SSL-Zertifikat-Erstellung fehlgeschlagen!${NC}"
|
echo -e "${RED}❌ SSL-Zertifikat-Erstellung fehlgeschlagen!${NC}"
|
||||||
echo "Mögliche Ursachen:"
|
echo "Mögliche Ursachen:"
|
||||||
echo "- Domain ist nicht erreichbar"
|
echo "- Domain ist nicht erreichbar"
|
||||||
echo "- Port 80 ist blockiert"
|
echo "- Port 80 ist blockiert"
|
||||||
echo "- DNS-Einträge sind nicht korrekt"
|
echo "- DNS-Einträge sind nicht korrekt"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Erstelle HTTPS Nginx-Konfiguration
|
# Erstelle HTTPS Nginx-Konfiguration
|
||||||
echo -e "${YELLOW}📝 Erstelle HTTPS Nginx-Konfiguration...${NC}"
|
echo -e "${YELLOW}📝 Erstelle HTTPS Nginx-Konfiguration...${NC}"
|
||||||
|
# Stelle die ursprüngliche HTTPS-Konfiguration wieder her
|
||||||
|
git checkout nginx/nginx.conf
|
||||||
sed "s/\${DOMAIN}/$DOMAIN/g" nginx/nginx.conf > nginx/nginx.conf.tmp
|
sed "s/\${DOMAIN}/$DOMAIN/g" nginx/nginx.conf > nginx/nginx.conf.tmp
|
||||||
mv nginx/nginx.conf.tmp nginx/nginx.conf
|
mv nginx/nginx.conf.tmp nginx/nginx.conf
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user