Skip to content

Commit

Permalink
elevate to sudo lsof and kill
Browse files Browse the repository at this point in the history
  • Loading branch information
anixon604 committed Feb 14, 2024
1 parent 030b252 commit fc13bb4
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/runner-scripts/close-ports.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fi
echo "fetch pids"
# Use || true to prevent script exit in case of command failure
echo "cmd: lsof -iTCP:$lowest_port-$highest_port -sTCP:LISTEN -t"
pids=$(lsof -iTCP:$lowest_port-$highest_port -sTCP:LISTEN -t)
pids=$(sudo lsof -iTCP:$lowest_port-$highest_port -sTCP:LISTEN -t)

# Check if the lsof command was successful
if [ -z "$pids" ] && [ $? -ne 0 ]; then
Expand All @@ -40,14 +40,14 @@ else
done
for pid in $pids; do
echo "Killing process $pid on one of the ports from $lowest_port to $highest_port"
kill $pid || echo "Failed to kill process $pid"
sudo kill $pid || echo "Failed to kill process $pid"
done
fi
echo "range done"
echo "Additional ports: ${additional_ports[@]}"
for port in "${additional_ports[@]}"; do
echo "cmd: lsof -ti TCP:$port"
pids=$(lsof -ti TCP:$port)
pids=$(sudo lsof -ti TCP:$port)

# Check if the lsof command was successful
if [ -z "$pids" ] && [ $? -ne 0 ]; then
Expand All @@ -60,7 +60,7 @@ for port in "${additional_ports[@]}"; do
else
for pid in $pids; do
echo "Killing process $pid on port $port"
kill $pid || echo "Failed to kill process $pid"
sudo kill $pid || echo "Failed to kill process $pid"
done
fi
done

0 comments on commit fc13bb4

Please sign in to comment.