changes to the starting
This commit is contained in:
+15
-4
@@ -33,7 +33,7 @@ EOF
|
|||||||
}
|
}
|
||||||
|
|
||||||
ensure_mongo_app_user() {
|
ensure_mongo_app_user() {
|
||||||
"${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" exec -T mongodb mongosh --quiet \
|
if "${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" exec -T mongodb mongosh --quiet \
|
||||||
--username "$MONGO_INITDB_ROOT_USERNAME" \
|
--username "$MONGO_INITDB_ROOT_USERNAME" \
|
||||||
--password "$MONGO_INITDB_ROOT_PASSWORD" \
|
--password "$MONGO_INITDB_ROOT_PASSWORD" \
|
||||||
--authenticationDatabase admin \
|
--authenticationDatabase admin \
|
||||||
@@ -62,6 +62,12 @@ if (!appDb.getUser(appUser)) {
|
|||||||
print("updated app user");
|
print("updated app user");
|
||||||
}
|
}
|
||||||
'
|
'
|
||||||
|
then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "[WARNUNG] App-User konnte nicht synchronisiert werden; der bestehende Mongo-Volume-Stand verwendet wahrscheinlich andere Root-Credentials." >&2
|
||||||
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
wait_for_mongo_ready() {
|
wait_for_mongo_ready() {
|
||||||
@@ -69,6 +75,7 @@ wait_for_mongo_ready() {
|
|||||||
local interval=2
|
local interval=2
|
||||||
local elapsed=0
|
local elapsed=0
|
||||||
local mongo_container_id=""
|
local mongo_container_id=""
|
||||||
|
local container_state=""
|
||||||
local health_status=""
|
local health_status=""
|
||||||
|
|
||||||
mongo_container_id="$("${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" ps -q mongodb 2>/dev/null || true)"
|
mongo_container_id="$("${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" ps -q mongodb 2>/dev/null || true)"
|
||||||
@@ -78,15 +85,19 @@ wait_for_mongo_ready() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
while [ $elapsed -lt $timeout_seconds ]; do
|
while [ $elapsed -lt $timeout_seconds ]; do
|
||||||
health_status="$(${DOCKER_CMD[@]} inspect -f '{{if .State.Health}}{{.State.Health.Status}}{{else}}{{.State.Status}}{{end}}' "$mongo_container_id" 2>/dev/null || true)"
|
container_state="$(${DOCKER_CMD[@]} inspect -f '{{.State.Status}} {{if .State.Health}}{{.State.Health.Status}}{{end}}' "$mongo_container_id" 2>/dev/null || true)"
|
||||||
if [ "$health_status" = "healthy" ] || [ "$health_status" = "running" ]; then
|
health_status="${container_state#* }"
|
||||||
|
if [ "${container_state%% *}" = "running" ]; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
if [ "${container_state%% *}" = "exited" ] || [ "${container_state%% *}" = "dead" ]; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
sleep $interval
|
sleep $interval
|
||||||
elapsed=$((elapsed + interval))
|
elapsed=$((elapsed + interval))
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "[FEHLER] MongoDB wurde nicht rechtzeitig gesund. Status: ${health_status:-unbekannt}" >&2
|
echo "[FEHLER] MongoDB wurde nicht rechtzeitig gestartet. Status: ${container_state:-unbekannt}" >&2
|
||||||
"${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" ps mongodb >&2 || true
|
"${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" ps mongodb >&2 || true
|
||||||
"${DOCKER_CMD[@]}" compose --env-file "$SECRETS_FILE" logs --tail 80 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