feat: add openim v3.4 and v3.5 changelog

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
pull/1745/head
Xinwei Xiong (cubxxw) 2 years ago
parent 2c323825b0
commit 2db0611173

@ -138,7 +138,7 @@ function openim::rpc::start() {
done done
done done
sleep 1 sleep 10
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]} openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]} # openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}

@ -301,29 +301,41 @@ openim::util::check_ports() {
openim::log::info "Checking ports: $*" openim::log::info "Checking ports: $*"
# Iterate over each given port. # Iterate over each given port.
for port in "$@"; do for port in "$@"; do
# Use the `ss` command to find process information related to the given port. # Initialize variables
if command -v ss > /dev/null 2>&1; then # Check the OS and use the appropriate command
info=$(ss -ltnp | grep ":$port" || true) if [[ "$OSTYPE" == "linux-gnu"* ]]; then
else if command -v ss > /dev/null 2>&1; then
info=$(netstat -ltnp | grep ":$port" || true) info=$(ss -ltnp | grep ":$port" || true)
else
info=$(netstat -ltnp | grep ":$port" || true)
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
# For macOS, use netstat
info=$(netstat -an -p tcp | grep "\.$port " || true)
fi fi
# If there's no process information, it means the process associated with the port is not running. # Check if any process is using the port
if [[ -z $info ]]; then if [[ -z $info ]]; then
not_started+=($port) not_started+=($port)
else else
# Extract relevant details: Process Name, PID, and FD. if [[ "$OSTYPE" == "linux-gnu"* ]]; then
local details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p') # Extract relevant details for Linux: Process Name, PID, and FD.
local command=$(echo $details | awk '{print $1}') details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p')
local pid=$(echo $details | awk '{print $2}') command=$(echo $details | awk '{print $1}')
local fd=$(echo $details | awk '{print $3}') pid=$(echo $details | awk '{print $2}')
fd=$(echo $details | awk '{print $3}')
elif [[ "$OSTYPE" == "darwin"* ]]; then
# Handle extraction for macOS
pid=$(echo $info | awk '{print $9}' | cut -d'/' -f1)
command=$(ps -p $pid -o comm=)
fd="N/A" # File Descriptor is not available in macOS netstat output
fi
# Get the start time of the process using the PID # Get the start time of the process using the PID
if [[ -z $pid ]]; then if [[ -z $pid ]]; then
local start_time="N/A" start_time="N/A"
else else
# Get the start time of the process using the PID start_time=$(ps -p $pid -o lstart=)
local start_time=$(ps -p $pid -o lstart=)
fi fi
started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time") started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time")
@ -355,6 +367,7 @@ openim::util::check_ports() {
return 0 return 0
fi fi
} }
# set +o errexit # set +o errexit
# Sample call for testing: # Sample call for testing:
# openim::util::check_ports 10002 1004 12345 13306 # openim::util::check_ports 10002 1004 12345 13306
@ -371,12 +384,15 @@ openim::util::check_process_names() {
# Function to get the port of a process # Function to get the port of a process
get_port() { get_port() {
local pid=$1 local pid=$1
if command -v ss > /dev/null 2>&1; then if [[ "$OSTYPE" == "linux-gnu"* ]]; then
# used ss comment # Linux
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2 ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
elif [[ "$OSTYPE" == "darwin"* ]]; then
# macOS
lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://'
else else
# used netstat comment replace ss echo "Unsupported OS"
netstat -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | sed 's/.*://' return 1
fi fi
} }
@ -496,6 +512,7 @@ openim::util::stop_services_on_ports() {
return 1 return 1
else else
openim::log::success "All specified services were stopped." openim::log::success "All specified services were stopped."
echo ""
return 0 return 0
fi fi
} }
@ -572,6 +589,7 @@ openim::util::stop_services_with_name() {
fi fi
openim::log::success "All specified services were stopped." openim::log::success "All specified services were stopped."
echo ""
} }
# sleep 333333& # sleep 333333&
# sleep 444444& # sleep 444444&

Loading…
Cancel
Save