fix find_free_port: single ss call, grep for :PORT pattern
This commit is contained in:
@@ -18,12 +18,12 @@ step() { echo -e "\n${CYAN}━━━ $1 ━━━${NC}"; }
|
||||
mark_done() { echo "$1" >> "$PROGRESS_FILE"; }
|
||||
is_done() { grep -qx "$1" "$PROGRESS_FILE" 2>/dev/null; }
|
||||
|
||||
# ─── Find free port (check + increment until free) ──────────────
|
||||
# ─── Find free port (check via ss, single pass) ────────────────
|
||||
find_free_port() {
|
||||
local port=$1 max=$2
|
||||
max="${max:-65535}"
|
||||
while [ "$port" -le "$max" ]; do
|
||||
if ! ss -tlnp "sport = :$port" 2>/dev/null | grep -q .; then
|
||||
if ! ss -tlnp 2>/dev/null | grep -q ":$port "; then
|
||||
echo "$port"
|
||||
return 0
|
||||
fi
|
||||
@@ -213,7 +213,7 @@ for pair in "POSTGRES_PORT:5432" "REDIS_PORT:6379" "RABBITMQ_PORT:5672" "RABBITM
|
||||
current=$(grep "^${var}=" "$INSTALL_DIR/.env" 2>/dev/null | cut -d= -f2) || true
|
||||
current="${current:-$default}"
|
||||
|
||||
if ss -tlnp "sport = :$current" 2>/dev/null | grep -q .; then
|
||||
if ss -tlnp 2>/dev/null | grep -q ":$current "; then
|
||||
warn "Port $current ($var) is busy — finding free port..."
|
||||
new_port=$(find_free_port "$((current + 1))" 2>/dev/null) || new_port=$((current + 100))
|
||||
set_env "$var" "$new_port"
|
||||
|
||||
Reference in New Issue
Block a user