Add entrypoint.sh: wait for MariaDB before starting Flask

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Nirodan
2026-05-06 09:37:01 +02:00
parent 75062dbf5e
commit dedde400e1
2 changed files with 40 additions and 1 deletions
+35
View File
@@ -0,0 +1,35 @@
#!/bin/sh
set -e
RETRY_INTERVAL=3
# If no db_config.json exists yet, skip the wait (first-run setup mode).
python - <<'EOF'
import sys, os
config_path = os.environ.get("DB_CONFIG_PATH", "/config/db_config.json")
if not os.path.exists(config_path):
sys.exit(1)
EOF
DB_CONFIGURED=$?
if [ "$DB_CONFIGURED" -eq 1 ]; then
echo "[entrypoint] Keine DB-Konfiguration gefunden starte im Setup-Modus."
else
echo "[entrypoint] DB-Konfiguration gefunden warte auf MariaDB..."
while true; do
python - <<'EOF'
import sys
from util.db_config import load_config, test_connection
config = load_config()
sys.exit(0 if config and test_connection(config) else 1)
EOF
if [ $? -eq 0 ]; then
echo "[entrypoint] MariaDB erreichbar starte Flask."
break
fi
echo "[entrypoint] MariaDB noch nicht bereit neuer Versuch in ${RETRY_INTERVAL}s..."
sleep "$RETRY_INTERVAL"
done
fi
exec python app.py