From abd1bcd35d0a95d0e5ee5e10af2da7cf762aa996 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 10 Aug 2026 18:40:06 +0000 Subject: [PATCH] Fix wordpress.sh picking an already-occupied port MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported live: a fresh site's container failed to start with "address already in use" on its assigned port. wordpress.sh scanned for a free port by grepping `docker ps -a`'s port list — that only reflects ports Docker itself currently has bound, so it's blind to ports held by non-Docker processes or anything Docker isn't reporting cleanly at that instant. Every other service in this repo scans with find_free_port (checks actual OS-level listening sockets via ss) per CLAUDE.md's "Port collision avoidance" section; wordpress.sh was the one holdout still using its own weaker check. Switched to the shared helper, already available in this file's own standalone stub and via lib/common.sh — no new dependency, just using what was already sitting there unused. --- services/wordpress.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/services/wordpress.sh b/services/wordpress.sh index 89b4c1a..85b092b 100644 --- a/services/wordpress.sh +++ b/services/wordpress.sh @@ -316,10 +316,15 @@ install_wordpress() { [ -n "$WP_ADMIN_PASS" ] || WP_ADMIN_PASS="$(generate_password 16)" # ── Free host port (multiple sites can't all bind the same one) ───────── + # Was checking `docker ps -a` port lists — only catches ports Docker + # itself currently has bound, not ports held by non-Docker processes or + # anything else on the host. Confirmed live: this let a fresh site pick + # an already-occupied port ("address already in use" at container + # start). find_free_port checks actual OS-level listening sockets via + # ss, the same convention every other service here follows — see + # CLAUDE.md's "Port collision avoidance" section. local WEB_PORT=8090 - while docker ps -a --format '{{.Ports}}' 2>/dev/null | grep -q ":${WEB_PORT}->"; do - WEB_PORT=$((WEB_PORT + 1)) - done + find_free_port WEB_PORT "$WEB_PORT" mkdir -p "$DIR/html" "$DIR/db" "$DIR/uploads-ini.d" ensure_docker_dir_ownership "$DIR"