fix: local-dev-2.sh reset order — stop container before port check

The round-7 port pre-flight ran BEFORE , so a
healthy postgres container from a previous run (which owns host port 5432) was
mistaken for a squatter and the script exited. Down the container first, then
check for any remaining non-Docker process on 5432 and fail loudly with the
offending pid.
This commit is contained in:
2026-08-22 00:34:49 +01:00
parent 5cc5a7f6d2
commit 3894f53778
+13 -10
View File
@@ -44,20 +44,23 @@ fi
# --- 3. Database Reset --- # --- 3. Database Reset ---
log_step "Resetting PostgreSQL..." log_step "Resetting PostgreSQL..."
# Host port 5432 must be free: the container maps 5432:5432, so a squatter # Order matters: `down` runs FIRST so the previous postgres container (which
# (e.g. a leftover manual postgres) makes the port bind fail. Under ERR_EXIT # owns host port 5432 after a prior successful run) is stopped and its port
# with hidden output that failure used to kill the script silently. # released. Only THEN do we check for a remaining squatter — any process still
if command -v ss > /dev/null 2>&1 && ss -tln 2>/dev/null | grep -q ":5432 "; then # on 5432 after the down must be a non-Docker postgres (e.g. a manually
log_error "Port 5432 is already in use. The postgres container cannot bind it." # started one), which the container cannot bind against. Under ERR_EXIT with
log_error "Something else is listening on 5432:" # hidden output the original script died silently on this failure.
ss -tlnp 2>/dev/null | grep ":5432 "
log_error "Stop the process holding 5432 (e.g. a manually-started postgres), then re-run."
exit 1
fi
if ! docker compose down -v postgres > /tmp/opencode/pg-down.log 2>&1; then if ! docker compose down -v postgres > /tmp/opencode/pg-down.log 2>&1; then
log_error "Failed to stop old postgres container. See /tmp/opencode/pg-down.log" log_error "Failed to stop old postgres container. See /tmp/opencode/pg-down.log"
exit 1 exit 1
fi fi
if command -v ss > /dev/null 2>&1 && ss -tln 2>/dev/null | grep -q ":5432 "; then
log_error "Port 5432 is still in use after stopping the postgres container."
log_error "Something else is listening on 5432:"
ss -tlnp 2>/dev/null | grep ":5432 "
log_error "Stop the non-Docker process holding 5432 (e.g. a manually-started postgres), then re-run."
exit 1
fi
if ! docker compose up postgres -d > /tmp/opencode/pg-up.log 2>&1; then if ! docker compose up postgres -d > /tmp/opencode/pg-up.log 2>&1; then
log_error "Failed to start postgres container. See /tmp/opencode/pg-up.log" log_error "Failed to start postgres container. See /tmp/opencode/pg-up.log"
exit 1 exit 1