-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update the make stop script logic and fix the make stop don't stop all process's bug #1933
Closed
Closed
Changes from 35 commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
cc9d460
fix: del the error output
luhaoling f0aa9d3
fix: fix the make stop output format error
luhaoling 297e001
fix: fix the make stop script
luhaoling eec0a5b
fix: fix the script
luhaoling 2711029
fix: add signal Exit code
luhaoling 04ec141
fix: signal output update
luhaoling 64a3666
fix: fix the script
luhaoling 42ad29b
fix: fix the msgtranfer script
luhaoling 50dec7b
fix: fix the port check script
luhaoling 92743f7
fix: fix the script name
luhaoling d02dc7c
fix: del the unuser code
luhaoling ee30529
fix: fix the port script
luhaoling 132f3b8
fix: fix the out format
luhaoling 078ed80
fix: fix the error
luhaoling 34ffcb5
fix: add check-all-by-signal1
luhaoling 247743f
fix: add stop-all
luhaoling 6aec72a
fix: del the error judge
luhaoling 83ee01a
fix: fix the transfer output
luhaoling 5fb5a1f
fix: fix the script
luhaoling 5479c39
fix: fix the output format
luhaoling df20f98
fix: update the logs output format
luhaoling 5888cf7
fix: del the unuse func
luhaoling d670230
fix: output red
luhaoling 5724158
fix: update the for loop
luhaoling 4c7fcb3
fix: fix the output error
luhaoling 8b28fd6
fix: logs
luhaoling 9cea45b
fix: logs
luhaoling 53dbb1f
Merge branch 'openimsdk:main' into fix/make_stop
luhaoling 7fff4ae
fix: fix the scripts
luhaoling 8a45baf
fix: fix the script
luhaoling 39042e2
Merge branch 'fix/make_stop' of github.com:luhaoling/open-im-server i…
luhaoling 76c9767
fix: fix the stop script
luhaoling 8e4836f
fix: fix the make stop script
luhaoling 87c79c8
Merge branch 'openimsdk:main' into fix/make_stop
luhaoling 6c22ccd
fix: add kill by name in script
luhaoling 2ddf5d3
Merge branch 'openimsdk:main' into fix/make_stop
luhaoling 07bd7e9
Merge branch 'fix/make_stop' of github.com:luhaoling/open-im-server i…
luhaoling e5983c0
fix: del the error chat
luhaoling bbb086f
fix: update the server name
luhaoling 9c3cc64
fix: add check logic script
luhaoling 5ec08d7
fix: del the repeat func
luhaoling 6c4f914
fix: del the repeat func
luhaoling c2c8810
fix: fix the param error
luhaoling 9318322
fix: fix the error
luhaoling 93f2034
fix: fix the error
luhaoling d423fca
fix: move the check_by_signal to util
luhaoling 1a6d500
fix: fix the error output
luhaoling File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,6 @@ set -o pipefail | |
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) | ||
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh | ||
|
||
openim::util::set_max_fd 200000 | ||
|
||
SERVER_NAME="openim-msgtransfer" | ||
|
||
|
@@ -88,6 +87,32 @@ function openim::msgtransfer::check() { | |
fi | ||
} | ||
|
||
function openim::msgtransfer::check_by_signal() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please explain the purpose of adding this function? |
||
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer") || PIDS="0" | ||
if [ "$PIDS" = "0" ]; then | ||
return 0 | ||
fi | ||
|
||
NUM_PROCESSES=$(echo "$PIDS" | wc -l | xargs) | ||
|
||
if [ "$NUM_PROCESSES" -gt 0 ]; then | ||
openim::log::error "Found $NUM_PROCESSES processes for $OPENIM_OUTPUT_HOSTBIN/openim-msgtransfer" | ||
for PID in $PIDS; do | ||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||
echo -e "\033[31m$(ps -p $PID -o pid,cmd)\033[0m" | ||
elif [[ "$OSTYPE" == "darwin"* ]]; then | ||
echo -e "\033[31m$(ps -p $PID -o pid,comm)\033[0m" | ||
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 | ||
return 0 | ||
} | ||
|
||
###################################### Linux Systemd ###################################### | ||
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -370,6 +370,81 @@ openim::util::check_ports() { | |
fi | ||
} | ||
|
||
|
||
openim::util::check_ports_by_signal() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这也是this ones too |
||
# 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=() | ||
|
||
# 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::error "\n### No stop ports:" | ||
for info in "${started[@]}"; do | ||
openim::log::error "$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." | ||
else | ||
openim::log::error "Have processes no stop." | ||
fi | ||
} | ||
|
||
# set +o errexit | ||
# Sample call for testing: | ||
# openim::util::check_ports 10002 1004 12345 13306 | ||
|
@@ -476,24 +551,22 @@ openim::util::stop_services_on_ports() { | |
openim::log::info "Stopping services on ports: $*" | ||
# Iterate over each given port. | ||
for port in "$@"; do | ||
# Use the `lsof` command to find process information related to the given port. | ||
info=$(lsof -i :$port -n -P | grep LISTEN || true) | ||
|
||
# If there's process information, it means the process associated with the port is running. | ||
local info=$(lsof -i :$port -n -P | grep LISTEN || true) | ||
if [[ -n $info ]]; then | ||
# Extract the Process ID. | ||
local stopped_this_port=false | ||
while read -r line; do | ||
local pid=$(echo $line | awk '{print $2}') | ||
|
||
# Try to stop the service by killing its process. | ||
if kill -15 $pid; then | ||
stopped+=($port) | ||
else | ||
not_stopped+=($port) | ||
if kill -15 "$pid" &> /dev/null; then | ||
stopped+=("$port") | ||
stopped_this_port=true | ||
break # Jump out of loop after successfully sending SIGTERM | ||
fi | ||
done <<< "$info" | ||
fi | ||
done | ||
done <<< "$info" | ||
if ! $stopped_this_port; then | ||
not_stopped+=("$port") | ||
fi | ||
fi | ||
done | ||
|
||
# Print information about ports whose processes couldn't be stopped. | ||
if [[ ${#not_stopped[@]} -ne 0 ]]; then | ||
|
@@ -519,6 +592,35 @@ openim::util::stop_services_on_ports() { | |
return 0 | ||
fi | ||
} | ||
|
||
openim::util::stop_services_by_signal() { | ||
# An array to collect ports of processes that couldn't be stopped. | ||
local not_stopped=() | ||
|
||
# An array to collect information about processes that were stopped. | ||
local stopped=() | ||
|
||
# Iterate over each given port. | ||
for port in "$@"; do | ||
# Use the `lsof` command to find process information related to the given port. | ||
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 | ||
# Extract the Process ID. | ||
while read -r line; do | ||
local pid=$(echo $line | awk '{print $2}') | ||
|
||
# Try to stop the service by killing its process. | ||
if kill -15 $pid; then | ||
stopped+=($port) | ||
else | ||
not_stopped+=($port) | ||
fi | ||
done <<< "$info" | ||
fi | ||
done | ||
} | ||
# nc -l -p 12345 | ||
# nc -l -p 123456 | ||
# ps -ef | grep "nc -l" | ||
|
@@ -594,6 +696,48 @@ openim::util::stop_services_with_name() { | |
openim::log::success "All specified services were stopped." | ||
echo "" | ||
} | ||
|
||
openim::util::stop_services_by_name_signal() { | ||
# An array to collect names of processes that couldn't be stopped. | ||
local not_stopped=() | ||
|
||
# An array to collect information about processes that were stopped. | ||
local stopped=() | ||
|
||
# Iterate over each given service name. | ||
for server_name in "$@"; do | ||
# Use the `pgrep` command to find process IDs related to the given service name. | ||
local pids=$(pgrep -f "$server_name") | ||
|
||
# If no process was found with the name, add it to the not_stopped list | ||
if [[ -z $pids ]]; then | ||
not_stopped+=("$server_name") | ||
continue | ||
fi | ||
local stopped_this_time=false | ||
for pid in $pids; do | ||
|
||
# Exclude the PID of the current script | ||
if [[ "$pid" == "$$" ]]; then | ||
continue | ||
fi | ||
|
||
# If there's a Process ID, it means the service with the name is running. | ||
if [[ -n $pid ]]; then | ||
# Try to stop the service by killing its process. | ||
if kill -15 $pid 2>/dev/null; then | ||
stopped_this_time=true | ||
fi | ||
fi | ||
done | ||
|
||
if $stopped_this_time; then | ||
stopped+=("$server_name") | ||
else | ||
not_stopped+=("$server_name") | ||
fi | ||
done | ||
} | ||
# sleep 333333& | ||
# sleep 444444& | ||
# ps -ef | grep "sleep" | ||
|
@@ -1708,25 +1852,22 @@ openim::util::stop_services_on_ports() { | |
local stopped=() | ||
|
||
openim::log::info "Stopping services on ports: $*" | ||
# Iterate over each given port. | ||
for port in "$@"; do | ||
# Use the `lsof` command to find process information related to the given port. | ||
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 | ||
# Extract the Process ID. | ||
while read -r line; do | ||
local pid=$(echo $line | awk '{print $2}') | ||
|
||
# Try to stop the service by killing its process. | ||
if kill -10 $pid; then | ||
stopped+=($port) | ||
else | ||
not_stopped+=($port) | ||
fi | ||
done <<< "$info" | ||
local info=$(lsof -i :$port -n -P | grep LISTEN || true) | ||
if [[ -n $info ]]; then | ||
local stopped_this_port=false | ||
while read -r line; do | ||
local pid=$(echo $line | awk '{print $2}') | ||
if kill -15 "$pid" &> /dev/null; then | ||
stopped+=("$port") | ||
stopped_this_port=true | ||
break # Jumping out of cycle m after successfully sending SIGTERM | ||
fi | ||
done <<< "$info" | ||
if ! $stopped_this_port; then | ||
not_stopped+=("$port") | ||
fi | ||
fi | ||
done | ||
|
||
# Print information about ports whose processes couldn't be stopped. | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was this err not handled?
这个错误一定会发生吗,为什么不需要做处理