From f905ca87165b5da25a46ff4e9252fdd94ef45e8c Mon Sep 17 00:00:00 2001 From: sarumpaet Date: Thu, 23 Sep 2021 14:53:59 +0200 Subject: [PATCH] fix detecting used ports in Docker Processes blocking ports that run on the host are not visible within a Docker container. This was misdetected as the port being available. Print an error and abort instead. --- scripts/setup_checks.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/setup_checks.sh b/scripts/setup_checks.sh index f806274..9146b89 100755 --- a/scripts/setup_checks.sh +++ b/scripts/setup_checks.sh @@ -67,7 +67,8 @@ check_port () { port="$2" reason="$3" echo -n "Checking ${protocol^^} port $port... " - process_pid=$(sudo ss -lnp -A "$protocol" "sport = :$port" | grep -Po "(?<=pid=)(\d+)" | head -n1) + ss_output=$(sudo ss -lnp -A "$protocol" "sport = :$port") + process_pid=$(echo "$ss_output" | grep -Po "(?<=pid=)(\d+)" | head -n1) if [ -n "$process_pid" ]; then process_name=$(ps -p "$process_pid" -o comm=) echo "Occupied by $process_name with PID $process_pid." @@ -98,6 +99,12 @@ check_port () { sleep 1 fi else + if [ $(echo "$ss_output" | wc -l) -gt 1 ]; then + echo "Occupied by unknown process." + echo "Port $port is needed to $reason" + echo "Aborting due to occupied port" + exit 1 + fi echo "Available." fi }