feat: Add health check and diagnostics to launch_dev.sh for improved reliability
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -135,6 +135,40 @@ Hinweis:
|
||||
- Development: [Website/launch_dev.sh](Website/launch_dev.sh)
|
||||
- Production: [Website/launch_prod.sh](Website/launch_prod.sh)
|
||||
|
||||
### Neues: Start-Health-Check im `launch_dev.sh`
|
||||
|
||||
`Website/launch_dev.sh` führt jetzt vor dem Build eine kurze Prüfung durch und wartet nach dem Start auf eine erreichbare HTTP-Antwort:
|
||||
|
||||
- Vor dem Build wird geprüft, ob `gunicorn.conf.py` im `Website/`-Verzeichnis vorhanden ist; falls nicht, bricht das Skript mit einer erklärenden Fehlermeldung ab.
|
||||
- Nach `docker compose up -d` wartet das Skript bis zu 60 Sekunden (Intervall 2s) auf einen erfolgreichen HTTP-Request (`/`) auf `127.0.0.1:4999`.
|
||||
- Schlägt der Health-Check fehl, sammelt das Skript automatisch folgende Diagnosedaten und gibt Hinweise aus:
|
||||
- `docker compose ps`
|
||||
- `docker logs --tail 200 website-website-1`
|
||||
|
||||
Dies hilft, wiederkehrende Probleme (fehlende Dateien, fehlerhafte Container-Starts, nginx-Fehlkonfiguration) schneller zu finden.
|
||||
|
||||
Empfohlene manuelle Prüfbefehle (bei Problemen):
|
||||
|
||||
```bash
|
||||
# Status aller Container (zeigt Port-Mappings)
|
||||
docker ps --format 'table {{.Names}}\t{{.Status}}\t{{.Ports}}'
|
||||
|
||||
# Prüfen, ob Host auf 4999 lauscht
|
||||
ss -ltnp | grep 4999 || true
|
||||
|
||||
# Direktes Request vom Host (verbose)
|
||||
curl -v http://127.0.0.1:4999/ --max-time 10
|
||||
|
||||
# Logs des Website-Containers (letzte 200 Zeilen)
|
||||
docker logs --tail 200 website-website-1
|
||||
|
||||
# Testen von innerhalb des Containers (falls curl nicht installiert, nutze wget)
|
||||
docker exec -it website-website-1 curl -v http://127.0.0.1:4999/ || \
|
||||
docker exec -it website-website-1 wget -qO- http://127.0.0.1:4999/
|
||||
```
|
||||
|
||||
Wenn du möchtest, passe ich das Timeout oder den Health-Endpoint (`/health`) an.
|
||||
|
||||
Beispiel Production:
|
||||
|
||||
```bash
|
||||
|
||||
@@ -36,6 +36,9 @@ RUN set -eu; \
|
||||
COPY requirements.txt ./
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# Copy application sources into the image (templates, static, main app, config)
|
||||
COPY . /app
|
||||
|
||||
EXPOSE 4999
|
||||
|
||||
CMD ["gunicorn", "-c", "gunicorn.conf.py", "main:app"]
|
||||
|
||||
@@ -15,6 +15,12 @@ echo " INSTANCE_TLS_MODE=$INSTANCE_TLS_MODE"
|
||||
echo " INSTANCE_PARENT_DOMAIN=$INSTANCE_PARENT_DOMAIN"
|
||||
echo " DEV_HOSTS_REFRESH_INTERVAL=$DEV_HOSTS_REFRESH_INTERVAL"
|
||||
|
||||
# Ensure required runtime files exist before building
|
||||
if [ ! -f "$SCRIPT_DIR/gunicorn.conf.py" ]; then
|
||||
echo "[FEHLER] gunicorn.conf.py fehlt in $SCRIPT_DIR. Bitte prüfen." >&2
|
||||
exit 2
|
||||
fi
|
||||
|
||||
docker compose build website
|
||||
docker compose up -d
|
||||
|
||||
@@ -24,6 +30,31 @@ if [[ -x "$NGINX_SCRIPT" ]]; then
|
||||
sudo "$NGINX_SCRIPT" apply || echo "Warnung: Nginx konnte nicht automatisch aktualisiert werden."
|
||||
fi
|
||||
|
||||
# Wait for website to become healthy (simple HTTP check)
|
||||
check_url="http://127.0.0.1:4999/"
|
||||
timeout_seconds=60
|
||||
interval=2
|
||||
elapsed=0
|
||||
|
||||
echo "Warte auf Website (${check_url}) bis ${timeout_seconds}s..."
|
||||
while [ $elapsed -lt $timeout_seconds ]; do
|
||||
if curl -sS --max-time 2 "$check_url" >/dev/null 2>&1; then
|
||||
echo "Website erreichbar nach ${elapsed}s"
|
||||
break
|
||||
fi
|
||||
sleep $interval
|
||||
elapsed=$((elapsed + interval))
|
||||
done
|
||||
|
||||
if [ $elapsed -ge $timeout_seconds ]; then
|
||||
echo "[FEHLER] Website nicht erreichbar nach ${timeout_seconds}s. Sammle Diagnosedaten..."
|
||||
echo "--- docker compose ps ---"
|
||||
docker compose ps || true
|
||||
echo "--- docker logs website (tail 200) ---"
|
||||
docker logs --tail 200 website-website-1 || true
|
||||
echo "Bitte prüfe Container-Logs und nginx-Konfiguration."
|
||||
fi
|
||||
|
||||
if [[ -x "$SCRIPT_DIR/sync_dev_hosts.sh" ]]; then
|
||||
"$SCRIPT_DIR/sync_dev_hosts.sh" || true
|
||||
if [[ "${DEV_HOSTS_REFRESH_INTERVAL}" != "0" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user