diff --git a/Website/launch.sh b/Website/launch.sh index f7202ee..bd86e46 100755 --- a/Website/launch.sh +++ b/Website/launch.sh @@ -65,23 +65,30 @@ if (!appDb.getUser(appUser)) { } wait_for_mongo_ready() { - local timeout_seconds=60 + local timeout_seconds=180 local interval=2 local elapsed=0 + local mongo_container_id="" + local health_status="" + + mongo_container_id="$("${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" ps -q mongodb 2>/dev/null || true)" + if [ -z "$mongo_container_id" ]; then + echo "[FEHLER] MongoDB-Container wurde nicht gefunden." >&2 + return 1 + fi while [ $elapsed -lt $timeout_seconds ]; do - if "${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" exec -T mongodb mongosh --quiet \ - --username "$MONGO_INITDB_ROOT_USERNAME" \ - --password "$MONGO_INITDB_ROOT_PASSWORD" \ - --authenticationDatabase admin \ - --eval "db.adminCommand('ping').ok" >/dev/null 2>&1; then + health_status="$(${DOCKER_CMD[@]} inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$mongo_container_id" 2>/dev/null || true)" + if [ "$health_status" = "healthy" ] || [ "$health_status" = "running" ]; then return 0 fi sleep $interval elapsed=$((elapsed + interval)) done - echo "[FEHLER] MongoDB wurde nicht rechtzeitig erreichbar." >&2 + echo "[FEHLER] MongoDB wurde nicht rechtzeitig gesund. Status: ${health_status:-unbekannt}" >&2 + "${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" ps mongodb >&2 || true + "${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" logs --tail 80 mongodb >&2 || true return 1 }