|
|
@ -267,22 +267,26 @@ 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 `lsof` command to find process information related to the given port.
|
|
|
|
# Use the `ss` command to find process information related to the given port.
|
|
|
|
local info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
|
|
|
local info=$(ss -ltnp | grep -w ":$port" || true)
|
|
|
|
|
|
|
|
|
|
|
|
# If there's no process information, it means the process associated with the port is not running.
|
|
|
|
# If there's no process information, it means the process associated with the port is not running.
|
|
|
|
if [[ -z $info ]]; then
|
|
|
|
if [[ -z $info ]]; then
|
|
|
|
not_started+=($port)
|
|
|
|
not_started+=($port)
|
|
|
|
else
|
|
|
|
else
|
|
|
|
# If there's process information, extract relevant details:
|
|
|
|
# Extract relevant details: Process Name, PID, and FD.
|
|
|
|
# Process ID, Command Name, and Start Time.
|
|
|
|
local details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p')
|
|
|
|
local pid=$(echo $info | awk '{print $2}')
|
|
|
|
local command=$(echo $details | awk '{print $1}')
|
|
|
|
local command=$(echo $info | awk '{print $1}')
|
|
|
|
local pid=$(echo $details | awk '{print $2}')
|
|
|
|
local start_time=$(ps -o lstart= -p $pid)
|
|
|
|
local fd=$(echo $details | awk '{print $3}')
|
|
|
|
started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time")
|
|
|
|
|
|
|
|
|
|
|
|
# Get the start time of the process using the PID
|
|
|
|
|
|
|
|
local start_time=$(ps -p $pid -o lstart=)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time")
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
echo
|
|
|
|
|
|
|
|
# Print information about ports whose processes are not running.
|
|
|
|
# Print information about ports whose processes are not running.
|
|
|
|
if [[ ${#not_started[@]} -ne 0 ]]; then
|
|
|
|
if [[ ${#not_started[@]} -ne 0 ]]; then
|
|
|
|
openim::log::info "### Not started ports:"
|
|
|
|
openim::log::info "### Not started ports:"
|
|
|
@ -293,7 +297,6 @@ openim::util::check_ports() {
|
|
|
|
|
|
|
|
|
|
|
|
# Print information about ports whose processes are running.
|
|
|
|
# Print information about ports whose processes are running.
|
|
|
|
if [[ ${#started[@]} -ne 0 ]]; then
|
|
|
|
if [[ ${#started[@]} -ne 0 ]]; then
|
|
|
|
echo
|
|
|
|
|
|
|
|
openim::log::info "### Started ports:"
|
|
|
|
openim::log::info "### Started ports:"
|
|
|
|
for info in "${started[@]}"; do
|
|
|
|
for info in "${started[@]}"; do
|
|
|
|
openim::log::info "$info"
|
|
|
|
openim::log::info "$info"
|
|
|
@ -305,11 +308,14 @@ openim::util::check_ports() {
|
|
|
|
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
|
|
|
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
|
|
|
return 1
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
else
|
|
|
|
openim::log::success "started[@] processes are running."
|
|
|
|
openim::log::success "All specified processes are running."
|
|
|
|
return 0
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# openim::util::check_ports 10002 1004
|
|
|
|
# set +o errexit
|
|
|
|
|
|
|
|
# Sample call for testing:
|
|
|
|
|
|
|
|
# openim::util::check_ports 10002 1004 12345 13306
|
|
|
|
|
|
|
|
# set -o errexit
|
|
|
|
|
|
|
|
|
|
|
|
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
|
|
|
|
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
|
|
|
|
# It accepts multiple process names as arguments and prints:
|
|
|
|
# It accepts multiple process names as arguments and prints:
|
|
|
|