mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
fix: del the unuse func
This commit is contained in:
parent
df20f98348
commit
5888cf7015
@ -38,7 +38,7 @@ handle_error() {
|
|||||||
trap handle_error ERR
|
trap handle_error ERR
|
||||||
|
|
||||||
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check_by_signal
|
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check_by_signal
|
||||||
|
echo "Check ports:"
|
||||||
openim::util::check_ports_by_signal ${OPENIM_SERVER_PORT_LISTARIES[@]}
|
openim::util::check_ports_by_signal ${OPENIM_SERVER_PORT_LISTARIES[@]}
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
openim::log::error "The service does not stop properly, there are still processes running, please check!"
|
openim::log::error "The service does not stop properly, there are still processes running, please check!"
|
||||||
|
|||||||
@ -1,106 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
# This script is check openim service is running normally
|
|
||||||
#
|
|
||||||
# Usage: `scripts/check-all.sh`.
|
|
||||||
# Encapsulated as: `make check`.
|
|
||||||
# READ: https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
|
||||||
|
|
||||||
OPENIM_VERBOSE=4
|
|
||||||
|
|
||||||
openim::log::info "\n# Begin to check all openim service"
|
|
||||||
|
|
||||||
openim::log::status "Check all dependent service ports"
|
|
||||||
# Elegant printing function
|
|
||||||
# Elegant printing function
|
|
||||||
print_services_and_ports() {
|
|
||||||
local service_names=("$@")
|
|
||||||
local half_length=$((${#service_names[@]} / 2))
|
|
||||||
local service_ports=("${service_names[@]:half_length}")
|
|
||||||
|
|
||||||
echo "+-------------------------+----------+"
|
|
||||||
echo "| Service Name | Port |"
|
|
||||||
echo "+-------------------------+----------+"
|
|
||||||
|
|
||||||
for ((index=0; index < half_length; index++)); do
|
|
||||||
printf "| %-23s | %-8s |\n" "${service_names[$index]}" "${service_ports[$index]}"
|
|
||||||
done
|
|
||||||
|
|
||||||
echo "+-------------------------+----------+"
|
|
||||||
}
|
|
||||||
|
|
||||||
handle_error() {
|
|
||||||
echo "An error occurred. Printing ${STDERR_LOG_FILE} contents:"
|
|
||||||
cat "${STDERR_LOG_FILE}"
|
|
||||||
exit 1
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
print_services_and_ports "${OPENIM_SERVER_NAME_TARGETS[@]}" "${OPENIM_SERVER_PORT_TARGETS[@]}"
|
|
||||||
|
|
||||||
# Print out dependencies and their ports
|
|
||||||
print_services_and_ports "${OPENIM_DEPENDENCY_TARGETS[@]}" "${OPENIM_DEPENDENCY_PORT_TARGETS[@]}"
|
|
||||||
|
|
||||||
# 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"
|
|
||||||
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check_by_signal1
|
|
||||||
|
|
||||||
openim::log::info "\n## Check all OpenIM service ports"
|
|
||||||
echo "+++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
|
||||||
openim::util::check_ports_by_signal1 ${OPENIM_SERVER_PORT_LISTARIES[@]}
|
|
||||||
if [[ $? -ne 0 ]]; then
|
|
||||||
echo "++++ All openim service ports stop successfully !"
|
|
||||||
else
|
|
||||||
echo "+++ cat openim log file >>> ${LOG_FILE}"
|
|
||||||
openim::log::error_exit "The service does not stop properly, please check!"
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
trap - ERR
|
|
||||||
@ -93,34 +93,10 @@ function openim::msgtransfer::check_by_signal() {
|
|||||||
|
|
||||||
if [ "$NUM_PROCESSES" -gt 0 ]; then
|
if [ "$NUM_PROCESSES" -gt 0 ]; then
|
||||||
openim::log::error "Found $NUM_PROCESSES processes for $OPENIM_OUTPUT_HOSTBIN/openim-msgtransfer"
|
openim::log::error "Found $NUM_PROCESSES processes for $OPENIM_OUTPUT_HOSTBIN/openim-msgtransfer"
|
||||||
for PID in $PIDS; do
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
||||||
openim::log::error "$(ps -p $PID -o pid=,cmd= | awk '{print "PID: " $1 ", CMD: " $2}')"
|
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
||||||
# 优化后的命令
|
|
||||||
openim::log::error "$(ps -p $PID -o pid=,cmd= | awk '{print "PID: " $1 ", CMD: " $2}')"
|
|
||||||
else
|
|
||||||
openim::log::error "Unsupported OS type: $OSTYPE"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
openim::log::error "Processes have not been stopped properly."
|
|
||||||
else
|
|
||||||
openim::log::success "All openim-msgtransfer processes have been stopped properly."
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function openim::msgtransfer::check_by_signal1() {
|
|
||||||
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer")
|
|
||||||
|
|
||||||
NUM_PROCESSES=$(echo "$PIDS" | wc -l)
|
|
||||||
|
|
||||||
if [ "$NUM_PROCESSES" -eq "$OPENIM_MSGGATEWAY_NUM" ]; then
|
|
||||||
openim::log::info "Found $OPENIM_MSGGATEWAY_NUM processes named $OPENIM_OUTPUT_HOSTBIN"
|
|
||||||
for PID in $PIDS; do
|
for PID in $PIDS; do
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||||
ps -p $PID -o pid,cmd
|
ps -p $PID -o pid,cmd
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||||
ps -p $PID -o pid,comm
|
ps -p $PID -o pid,comm
|
||||||
else
|
else
|
||||||
openim::log::error "Unsupported OS type: $OSTYPE"
|
openim::log::error "Unsupported OS type: $OSTYPE"
|
||||||
@ -128,8 +104,7 @@ function openim::msgtransfer::check_by_signal1() {
|
|||||||
done
|
done
|
||||||
openim::log::error "Processes have not been stopped properly."
|
openim::log::error "Processes have not been stopped properly."
|
||||||
else
|
else
|
||||||
# openim::log::error_exit "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes."
|
openim::log::success "All openim-msgtransfer processes have been stopped properly."
|
||||||
openim::log::success "All openim-msgtransfer processes have been stopped properly."
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -447,87 +447,6 @@ openim::util::check_ports_by_signal() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
openim::util::check_ports_by_signal1() {
|
|
||||||
# An array to collect ports of processes that are not running.
|
|
||||||
local not_started=()
|
|
||||||
|
|
||||||
# An array to collect information about processes that are running.
|
|
||||||
local started=()
|
|
||||||
|
|
||||||
openim::log::info "Checking ports: $*"
|
|
||||||
# Iterate over each given port.
|
|
||||||
for port in "$@"; do
|
|
||||||
# Initialize variables
|
|
||||||
# Check the OS and use the appropriate command
|
|
||||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
|
||||||
if command -v ss > /dev/null 2>&1; then
|
|
||||||
info=$(ss -ltnp | grep ":$port" || true)
|
|
||||||
else
|
|
||||||
info=$(netstat -ltnp | grep ":$port" || true)
|
|
||||||
fi
|
|
||||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
|
||||||
# For macOS, use lsof
|
|
||||||
info=$(lsof -P -i:"$port" | grep "LISTEN" || true)
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Check if any process is using the port
|
|
||||||
if [[ -z $info ]]; then
|
|
||||||
not_started+=($port)
|
|
||||||
else
|
|
||||||
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
|
|
||||||
done
|
|
||||||
|
|
||||||
# Print information about ports whose processes are not running.
|
|
||||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
|
||||||
openim::log::info "\n### Not started ports:"
|
|
||||||
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### Started ports:"
|
|
||||||
for info in "${started[@]}"; do
|
|
||||||
openim::log::info "$info"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
# If any of the processes is not running, return a status of 1.
|
|
||||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
|
||||||
openim::log::success "All specified processes are stop."
|
|
||||||
return 1
|
|
||||||
else
|
|
||||||
openim::color::echo $COLOR_RED " OpenIM Stdout Log >> cat ${LOG_FILE}"
|
|
||||||
openim::color::echo $COLOR_RED " OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
|
||||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
|
||||||
openim::log::error "Have processes no stop."
|
|
||||||
return 0
|
|
||||||
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
|
||||||
@ -634,24 +553,22 @@ openim::util::stop_services_on_ports() {
|
|||||||
openim::log::info "Stopping services on ports: $*"
|
openim::log::info "Stopping services on 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.
|
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 -15 $pid; then
|
stopped_this_port=true
|
||||||
stopped+=($port)
|
break # Jump out of loop after successfully sending SIGTERM
|
||||||
else
|
|
||||||
not_stopped+=($port)
|
|
||||||
fi
|
fi
|
||||||
done <<< "$info"
|
done <<< "$info"
|
||||||
fi
|
if ! $stopped_this_port; then
|
||||||
done
|
not_stopped+=("$port")
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
# Print information about ports whose processes couldn't be stopped.
|
# Print information about ports whose processes couldn't be stopped.
|
||||||
if [[ ${#not_stopped[@]} -ne 0 ]]; then
|
if [[ ${#not_stopped[@]} -ne 0 ]]; then
|
||||||
|
|||||||
@ -1,39 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
# Copyright © 2023 OpenIM. All rights reserved.
|
|
||||||
#
|
|
||||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
# you may not use this file except in compliance with the License.
|
|
||||||
# You may obtain a copy of the License at
|
|
||||||
#
|
|
||||||
# http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
#
|
|
||||||
# Unless required by applicable law or agreed to in writing, software
|
|
||||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
# See the License for the specific language governing permissions and
|
|
||||||
# limitations under the License.
|
|
||||||
|
|
||||||
# This script is stop all openim service
|
|
||||||
#
|
|
||||||
# Usage: `scripts/stop.sh`.
|
|
||||||
# Encapsulated as: `make stop`.
|
|
||||||
|
|
||||||
set -o errexit
|
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|
||||||
|
|
||||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
|
||||||
|
|
||||||
openim::log::info "\n# Begin to stop all openim service"
|
|
||||||
|
|
||||||
echo "++ Ready to stop port: ${OPNIM_SERVER_PORT_LISTARIES[@]}"
|
|
||||||
|
|
||||||
openim::util::stop_services_on_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
|
|
||||||
|
|
||||||
openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}"
|
|
||||||
|
|
||||||
echo "++ Check if the services have been stopped"
|
|
||||||
|
|
||||||
openim::log::success "✨ All processes to be killed"
|
|
||||||
Loading…
x
Reference in New Issue
Block a user