mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
fix: update the for loop
This commit is contained in:
parent
d670230a11
commit
5724158c6e
@ -1854,25 +1854,22 @@ openim::util::stop_services_on_ports() {
|
|||||||
local stopped=()
|
local stopped=()
|
||||||
|
|
||||||
openim::log::info "Stopping services on ports: $*"
|
openim::log::info "Stopping services on ports: $*"
|
||||||
# Iterate over each given port.
|
|
||||||
for port in "$@"; do
|
for port in "$@"; do
|
||||||
# Use the `lsof` command to find process information related to the given port.
|
local info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
||||||
info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
if [[ -n $info ]]; then
|
||||||
|
local stopped_this_port=false
|
||||||
# If there's process information, it means the process associated with the port is running.
|
while read -r line; do
|
||||||
if [[ -n $info ]]; then
|
local pid=$(echo $line | awk '{print $2}')
|
||||||
# Extract the Process ID.
|
if kill -15 "$pid" &> /dev/null; then
|
||||||
while read -r line; do
|
stopped+=("$port")
|
||||||
local pid=$(echo $line | awk '{print $2}')
|
stopped_this_port=true
|
||||||
|
break # Jumping out of cycle m after successfully sending SIGTERM
|
||||||
# Try to stop the service by killing its process.
|
fi
|
||||||
if kill -10 $pid; then
|
done <<< "$info"
|
||||||
stopped+=($port)
|
if ! $stopped_this_port; then
|
||||||
else
|
not_stopped+=("$port")
|
||||||
not_stopped+=($port)
|
|
||||||
fi
|
|
||||||
done <<< "$info"
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Print information about ports whose processes couldn't be stopped.
|
# Print information about ports whose processes couldn't be stopped.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user