mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 19:02:31 +08:00
fix: update the for loop
This commit is contained in:
parent
d670230a11
commit
5724158c6e
@ -1854,24 +1854,21 @@ 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 there's process information, it means the process associated with the port is running.
|
|
||||||
if [[ -n $info ]]; then
|
if [[ -n $info ]]; then
|
||||||
# Extract the Process ID.
|
local stopped_this_port=false
|
||||||
while read -r line; do
|
while read -r line; do
|
||||||
local pid=$(echo $line | awk '{print $2}')
|
local pid=$(echo $line | awk '{print $2}')
|
||||||
|
if kill -15 "$pid" &> /dev/null; then
|
||||||
# Try to stop the service by killing its process.
|
stopped+=("$port")
|
||||||
if kill -10 $pid; then
|
stopped_this_port=true
|
||||||
stopped+=($port)
|
break # Jumping out of cycle m after successfully sending SIGTERM
|
||||||
else
|
|
||||||
not_stopped+=($port)
|
|
||||||
fi
|
fi
|
||||||
done <<< "$info"
|
done <<< "$info"
|
||||||
|
if ! $stopped_this_port; then
|
||||||
|
not_stopped+=("$port")
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user