changes to the startup
This commit is contained in:
+14
-7
@@ -65,23 +65,30 @@ if (!appDb.getUser(appUser)) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
wait_for_mongo_ready() {
|
wait_for_mongo_ready() {
|
||||||
local timeout_seconds=60
|
local timeout_seconds=180
|
||||||
local interval=2
|
local interval=2
|
||||||
local elapsed=0
|
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
|
while [ $elapsed -lt $timeout_seconds ]; do
|
||||||
if "${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" exec -T mongodb mongosh --quiet \
|
health_status="$(${DOCKER_CMD[@]} inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$mongo_container_id" 2>/dev/null || true)"
|
||||||
--username "$MONGO_INITDB_ROOT_USERNAME" \
|
if [ "$health_status" = "healthy" ] || [ "$health_status" = "running" ]; then
|
||||||
--password "$MONGO_INITDB_ROOT_PASSWORD" \
|
|
||||||
--authenticationDatabase admin \
|
|
||||||
--eval "db.adminCommand('ping').ok" >/dev/null 2>&1; then
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
sleep $interval
|
sleep $interval
|
||||||
elapsed=$((elapsed + interval))
|
elapsed=$((elapsed + interval))
|
||||||
done
|
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
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user