diff --git a/RebuildBdd/Checkup/check-postgresql.sh b/RebuildBdd/Checkup/check-postgresql.sh index a6e4428..3473922 100755 --- a/RebuildBdd/Checkup/check-postgresql.sh +++ b/RebuildBdd/Checkup/check-postgresql.sh @@ -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