fix: update the for loop

pull/1933/head
luhaoling 2 years ago
parent d670230a11
commit 5724158c6e

@ -1854,24 +1854,21 @@ openim::util::stop_services_on_ports() {
local stopped=()
openim::log::info "Stopping services on ports: $*"
# Iterate over each given port.
for port in "$@"; do
# Use the `lsof` command to find process information related to the given port.
info=$(lsof -i :$port -n -P | grep LISTEN || true)
# If there's process information, it means the process associated with the port is running.
local info=$(lsof -i :$port -n -P | grep LISTEN || true)
if [[ -n $info ]]; then
# Extract the Process ID.
local stopped_this_port=false
while read -r line; do
local pid=$(echo $line | awk '{print $2}')
# Try to stop the service by killing its process.
if kill -10 $pid; then
stopped+=($port)
else
not_stopped+=($port)
if kill -15 "$pid" &> /dev/null; then
stopped+=("$port")
stopped_this_port=true
break # Jumping out of cycle m after successfully sending SIGTERM
fi
done <<< "$info"
if ! $stopped_this_port; then
not_stopped+=("$port")
fi
fi
done

Loading…
Cancel
Save