Fix: Add timeout and fallback for SSL certificate check

- Added 30-second timeout to certificate check to prevent hanging
- Added fallback to HTTP-only configuration if SSL setup fails
- Script now continues even if certificate verification fails
- This prevents the script from hanging indefinitely
This commit is contained in:
2025-10-01 23:18:01 +02:00
parent e29f4374c0
commit b3272d565b

View File

@@ -96,11 +96,17 @@ ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml up -d nginx
echo -e "${YELLOW}⏳ Warte auf Nginx...${NC}"
sleep 10
# Prüfe ob SSL-Zertifikat bereits existiert
# Prüfe ob SSL-Zertifikat bereits existiert (mit Timeout)
echo -e "${YELLOW}🔍 Prüfe vorhandene SSL-Zertifikate...${NC}"
if ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certificates -d $DOMAIN | grep -q "Certificate Name: $DOMAIN"; then
CERT_EXISTS=false
if timeout 30 ${SUDO}${DOCKER_COMPOSE} -f docker-compose-prod.yml run --rm certbot certbot certificates -d $DOMAIN 2>/dev/null | grep -q "Certificate Name: $DOMAIN"; then
CERT_EXISTS=true
fi
if [ "$CERT_EXISTS" = true ]; then
echo -e "${GREEN}✅ SSL-Zertifikat für $DOMAIN bereits vorhanden!${NC}"
else
echo -e "${YELLOW}⚠️ Kein SSL-Zertifikat gefunden oder Prüfung fehlgeschlagen. Versuche Zertifikatserstellung...${NC}"
# 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 \
@@ -120,16 +126,22 @@ else
echo "- Domain ist nicht erreichbar"
echo "- Port 80 ist blockiert"
echo "- DNS-Einträge sind nicht korrekt"
exit 1
echo ""
echo -e "${YELLOW}⚠️ Fortfahren ohne SSL-Zertifikat (HTTP-only)...${NC}"
fi
fi
# Erstelle HTTPS Nginx-Konfiguration
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
mv nginx/nginx.conf.tmp nginx/nginx.conf
# Erstelle HTTPS Nginx-Konfiguration (nur wenn SSL-Zertifikat vorhanden)
if [ "$CERT_EXISTS" = true ]; then
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
mv nginx/nginx.conf.tmp nginx/nginx.conf
else
echo -e "${YELLOW}📝 Verwende HTTP-only Nginx-Konfiguration (kein SSL-Zertifikat)...${NC}"
# Bleibe bei der HTTP-only Konfiguration
fi
# Starte alle Services
echo -e "${YELLOW}🚀 Starte alle Services...${NC}"