mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 11:52:10 +08:00
Optimizing scripts
This commit is contained in:
parent
90fd2fe84d
commit
4f8d6d21b3
@ -2846,32 +2846,31 @@ function openim::util::check_process_names_for_stop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function openim::util::find_process_ports() {
|
function openim::util::find_process_ports2() {
|
||||||
local process_path="$1"
|
local process_path="$1"
|
||||||
if [[ -z "$process_path" ]]; then
|
if [[ -z "$process_path" ]]; then
|
||||||
echo "Usage: find_process_ports /path/to/process"
|
echo "Usage: find_process_ports /path/to/process"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local pids=$(pgrep -f "$process_path")
|
|
||||||
if [[ -z "$pids" ]]; then
|
|
||||||
echo "No running process found for $process_path."
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
local ports_info=""
|
lsof -nP -iTCP -iUDP | grep LISTEN | grep "$(pgrep -f $process_path)" | awk '{print $9, $8}' | while read line; do
|
||||||
|
|
||||||
while read -r line; do
|
|
||||||
local port_protocol=($line)
|
local port_protocol=($line)
|
||||||
local port=${port_protocol[0]##*:}
|
local port=${port_protocol[0]##*:}
|
||||||
local protocol=${port_protocol[1]}
|
local protocol=${port_protocol[1]}
|
||||||
ports_info+="$port($protocol) "
|
echo "Process $process_path is listening on port $port with protocol $protocol"
|
||||||
done < <(lsof -nP -iTCP -iUDP | grep LISTEN | grep -E "$(echo $pids | sed 's/ /\\|/g')")
|
done
|
||||||
|
}
|
||||||
|
|
||||||
if [[ -n "$ports_info" ]]; then
|
function openim::util::find_process_ports() {
|
||||||
echo "Process $process_path is listening on ports: $ports_info"
|
local process_path="$1"
|
||||||
|
|
||||||
|
local ports=$(lsof -Fn -iTCP -iUDP | grep -i listen | grep "$process_path" | awk -F'[>:]' '{print $(NF-1) " " $NF}' | sort -u | tr '\n' ' ')
|
||||||
|
|
||||||
|
if [ -z "$ports" ]; then
|
||||||
|
echo "No listening ports found for the process."
|
||||||
else
|
else
|
||||||
echo "No ports found for process $process_path."
|
echo "Listening on ports: $ports"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user