fix: bootstrap PostgreSQL without a working service manager (#823) - #824
fix: bootstrap PostgreSQL without a working service manager (#823)#824GG-O-BP wants to merge 1 commit into
Conversation
b3c8c3f to
1b66266
Compare
1b66266 to
e2ea586
Compare
ReviewSound fix, no blockers. Three things I'd want changed before merge, all localized to What I verified — applied the two Go files to current
Moderate1. The fallback multiplies the timeout by the number of service attempts — confirmed, not theoretical. Moving Worst case is now 20 + 20 (services) + 30 ( Fix: drop the 2. Confirmed via the initdb args: Fix: the socket directory is already 3. The The hunk inserts at line ~322; on current Fix: rebase and move the row to the end of the table. Minor
ChecklistBug-fix requirements met: symptom row added, tests accompany the fix, The Thanks for the thorough stub-test coverage — the ready/non-ready service split and the idempotency cases are exactly the right seams to pin down. 🤖 Generated with Claude Code |
e2ea586 to
79dae2b
Compare
|
Thanks for the thorough review, @ako — all seven points are addressed. Rebased onto Moderate
Minor
Each new test was proven to fail on the un-fixed code (reverted each change in a throwaway worktree and watched the matching test fail with the reported symptom). |
…endixlabs#823) `mxcli run --ensure-db` only tried `service` and Debian's `pg_ctlcluster` to start a local PostgreSQL server. On Arch neither exists, so bootstrap failed even though `initdb`, `pg_ctl`, and `psql` were available. Try a real service manager (`service postgresql start`), confirming it actually makes PostgreSQL ready with a short readiness probe. If none is present or ready, start a user-owned cluster under `~/.mxcli/postgres` with `initdb`/`pg_ctl`. Reuse an initialized data directory and leave an already-running server alone so repeated runs are safe. Provision the application role/database as the cluster's own `postgres` superuser over its private 0700 Unix socket, without requiring a `postgres` OS account or passwordless sudo. Retain the existing `sudo -u postgres psql` path for system clusters. Review hardening (thanks @ako): - Drop the `pg_ctlcluster` placeholder (its args could never start a cluster) and probe each service attempt with a short timeout, so N managers no longer multiply the overall deadline; the single long readiness wait stays in EnsureDatabase. - initdb now uses `--auth-host=scram-sha-256` (only the private socket is trust): loopback TCP is not an access control on a multi-user host, so trust there would let any local account become the postgres superuser. The superuser connection goes over the socket accordingly. - Normalise an empty `--db-host` (":5432") to loopback so the server's `-o "-h ..."` option is well-formed. - Reuse a running cluster only when its `postmaster.pid` port matches the requested port; otherwise fail fast instead of waiting on the wrong one. - Name the server log file in the start-failure error, and surface the service manager's own output when the fallback then fails. Add focused command-stub tests for the dropped `pg_ctlcluster`, the auth args, socket-preferred superuser resolution, empty-host normalisation, the running-port guard, and the log-named start error. Update the docs, changelog, and fix-issue symptom entry (appended at the table end).
79dae2b to
a99673e
Compare
What & why
Closes #823.
mxcli run --ensure-dbonly knewserviceand a non-working Debianpg_ctlclusterplaceholder. On Arch neither produced a server, so bootstrapfailed even though the portable
initdb,pg_ctl, andpsqltools wereavailable.
Fix
service postgresql startpath and confirm readiness with ashort probe. Remove the unusable
pg_ctlcluster -- startplaceholder soservice attempts no longer multiply the overall timeout.
~/.mxcli/postgreswithinitdb/pg_ctl.0700socket directory (
--auth-local=trust), while loopback TCP uses--auth-host=scram-sha-256. Provision the role/database aspostgresoverthat socket; retain
sudo -u postgres psqlfor system clusters.line 4 of
postmaster.pidconfirms the requested port; a mismatched orunreadable port fails immediately with an actionable error.
--db-host ":5432"), include the server-log path instartup failures, and preserve service-manager diagnostics when fallback
also fails.
Tests
Command-stub tests cover:
pg_ctlclusterplaceholderValidation:
go build ./...make vetgo test ./cmd/mxcli/docker -count=1serviceorpg_ctlcluster), role/database creation, repeatedEnsureDatabase, and averified
0700socket directoryDocs
Updated the run-local skill, docs-site page, CHANGELOG, and appended the
fix-issue symptom entry at the end of its table.