mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
fix: del the unuser code
This commit is contained in:
parent
92743f7c5b
commit
d02dc7c5d8
@ -40,35 +40,6 @@ handle_error() {
|
|||||||
|
|
||||||
trap handle_error ERR
|
trap handle_error ERR
|
||||||
|
|
||||||
# Assuming OPENIM_SERVER_NAME_TARGETS and OPENIM_SERVER_PORT_TARGETS are defined
|
|
||||||
# Similarly for OPENIM_DEPENDENCY_TARGETS and OPENIM_DEPENDENCY_PORT_TARGETS
|
|
||||||
|
|
||||||
# Print out services and their ports
|
|
||||||
|
|
||||||
# OpenIM check
|
|
||||||
echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
|
||||||
openim::log::info "\n## Check all dependent service ports"
|
|
||||||
echo "++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
|
|
||||||
|
|
||||||
set +e
|
|
||||||
|
|
||||||
# Later, after discarding Docker, the Docker keyword is unreliable, and Kubepods is used
|
|
||||||
if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then
|
|
||||||
openim::color::echo ${COLOR_CYAN} "Environment in the interior of the container"
|
|
||||||
else
|
|
||||||
openim::color::echo ${COLOR_CYAN} "The environment is outside the container"
|
|
||||||
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]} || return 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
openim::log::error_exit "The service does not start properly, please check the port, query variable definition!"
|
|
||||||
echo "+++ https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh +++"
|
|
||||||
else
|
|
||||||
echo "++++ Check all dependent service ports successfully !"
|
|
||||||
fi
|
|
||||||
|
|
||||||
openim::log::info "\n## Check OpenIM service name"
|
openim::log::info "\n## Check OpenIM service name"
|
||||||
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check_by_signal
|
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check_by_signal
|
||||||
|
|
||||||
|
|||||||
@ -372,60 +372,86 @@ openim::util::check_ports() {
|
|||||||
|
|
||||||
|
|
||||||
openim::util::check_ports_by_signal() {
|
openim::util::check_ports_by_signal() {
|
||||||
# An array to collect information about processes that are still running.
|
# An array to collect ports of processes that are not running.
|
||||||
local running=()
|
local not_started=()
|
||||||
|
|
||||||
# An array to collect information about processes that have been stopped.
|
# An array to collect information about processes that are running.
|
||||||
local stopped=()
|
local started=()
|
||||||
|
|
||||||
openim::log::info "Checking processes for: $*"
|
openim::log::info "Checking ports: $*"
|
||||||
# Iterate over each given process name.
|
# Iterate over each given port.
|
||||||
for name in "$@"; do
|
for port in "$@"; do
|
||||||
# Check the OS and use the appropriate command to find processes by name
|
# Initialize variables
|
||||||
|
# Check the OS and use the appropriate command
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
info=$(pgrep -fl "$name" || true)
|
if command -v ss > /dev/null 2>&1; then
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
info=$(ss -ltnp | grep ":$port" || true)
|
||||||
# For macOS, use pgrep as well, lsof for ports is not relevant here
|
else
|
||||||
info=$(pgrep -fl "$name" || true)
|
info=$(netstat -ltnp | grep ":$port" || true)
|
||||||
|
fi
|
||||||
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
|
# For macOS, use lsof
|
||||||
|
info=$(lsof -P -i:"$port" | grep "LISTEN" || true)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check if the process is still running
|
# Check if any process is using the port
|
||||||
if [[ -z $info ]]; then
|
if [[ -z $info ]]; then
|
||||||
stopped+=("$name")
|
not_started+=($port)
|
||||||
else
|
else
|
||||||
running+=("Running process for $name: $info")
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
|
# Extract relevant details for Linux: Process Name, PID, and FD.
|
||||||
|
details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p')
|
||||||
|
command=$(echo $details | awk '{print $1}')
|
||||||
|
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 $2}' | cut -d'/' -f1)
|
||||||
|
command=$(ps -p $pid -o comm= | xargs basename)
|
||||||
|
fd=$(echo $info | awk '{print $4}' | cut -d'/' -f1)
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Get the start time of the process using the PID
|
||||||
|
if [[ -z $pid ]]; then
|
||||||
|
start_time="N/A"
|
||||||
|
else
|
||||||
|
start_time=$(ps -p $pid -o lstart=)
|
||||||
|
fi
|
||||||
|
|
||||||
|
started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Print information about processes that are still running.
|
# # Print information about ports whose processes are not running.
|
||||||
if [[ ${#running[@]} -ne 0 ]]; then
|
# if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||||
openim::log::info "\n### Running processes:"
|
# openim::log::info "\n### Not started ports:"
|
||||||
for info in "${running[@]}"; do
|
# for port in "${not_started[@]}"; do
|
||||||
|
# openim::log::error "Port $port is not started."
|
||||||
|
# done
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# Print information about ports whose processes are running.
|
||||||
|
if [[ ${#started[@]} -ne 0 ]]; then
|
||||||
|
openim::log::info "\n### No stop ports:"
|
||||||
|
for info in "${started[@]}"; do
|
||||||
openim::log::info "$info"
|
openim::log::info "$info"
|
||||||
done
|
done
|
||||||
else
|
|
||||||
# If all processes have been stopped, print a success message.
|
|
||||||
openim::log::success "All specified processes have been stopped."
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Print information about processes that have been stopped, if any.
|
# If any of the processes is not running, return a status of 1.
|
||||||
if [[ ${#stopped[@]} -ne 0 ]]; then
|
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||||
openim::log::info "\n### Stopped processes:"
|
openim::color::echo $COLOR_RED " OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||||
for name in "${stopped[@]}"; do
|
openim::color::echo $COLOR_RED " OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||||
openim::log::info "Process $name has been stopped."
|
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If any of the processes is still running, return a status of 1.
|
|
||||||
if [[ ${#running[@]} -ne 0 ]]; then
|
|
||||||
return 1
|
return 1
|
||||||
else
|
else
|
||||||
|
# openim::log::success "All specified processes are running."
|
||||||
|
openim::log::success "Have processes no stop."
|
||||||
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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user