feat : preparation de postgresql (WIP)

This commit is contained in:
2026-03-17 15:55:33 +01:00
parent b3de87a452
commit 29371b6529

View File

@@ -45,6 +45,26 @@ require_cmd() {
command -v "$1" >/dev/null 2>&1
}
collect_postgres_diagnostics() {
local diagnostics=""
if "$SUDO_BIN" systemctl status "$POSTGRES_SERVICE_NAME" --no-pager >/dev/null 2>&1; then
diagnostics+="systemctl status ${POSTGRES_SERVICE_NAME}: OK; "
elif require_cmd systemctl; then
diagnostics+="systemctl status ${POSTGRES_SERVICE_NAME}: $( "$SUDO_BIN" systemctl status "$POSTGRES_SERVICE_NAME" --no-pager 2>/dev/null | tail -n 5 | tr '\n' ' ' ); "
fi
if require_cmd pg_lsclusters; then
diagnostics+="pg_lsclusters: $(pg_lsclusters --no-header 2>/dev/null | tr '\n' ' '); "
fi
if require_cmd journalctl; then
diagnostics+="journalctl: $( "$SUDO_BIN" journalctl -u "$POSTGRES_SERVICE_NAME" -n 10 --no-pager 2>/dev/null | tr '\n' ' ' ); "
fi
printf '%s' "${diagnostics% }"
}
start_postgres_service() {
if "$SUDO_BIN" systemctl start "$POSTGRES_SERVICE_NAME" >/dev/null 2>&1; then
return 0
@@ -116,7 +136,9 @@ fi
if ! "$SUDO_BIN" systemctl is-active --quiet "$POSTGRES_SERVICE_NAME"; then
log "Démarrage du service PostgreSQL..."
start_postgres_service || fail "impossible de démarrer PostgreSQL"
if ! start_postgres_service; then
fail "impossible de démarrer PostgreSQL. $(collect_postgres_diagnostics)"
fi
else
log "Service PostgreSQL déjà actif."
fi