Fix wordpress.sh picking an already-occupied port

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.
This commit is contained in:
Claude
2026-08-10 18:40:06 +00:00
parent 28252b97d3
commit abd1bcd35d
+8 -3
View File
@@ -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"