From b1a74395162b1585fa17e19106729e6694f5c857 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:00:03 +0800 Subject: [PATCH 1/9] scripts for Mac --- scripts/check-all.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check-all.sh b/scripts/check-all.sh index d41023384..052a39984 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -99,6 +99,7 @@ for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do echo "$item" done +echo "11111111111111111111111:" result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}) if [[ $? -ne 0 ]]; then echo "+++ cat openim log file >>> ${LOG_FILE}" From 27ad975359927c04fa6afe94fd6b8df4b63b9d35 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:06:52 +0800 Subject: [PATCH 2/9] scripts for Mac --- scripts/check-all.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 052a39984..865583d4b 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -100,6 +100,8 @@ for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do done echo "11111111111111111111111:" +openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]} +echo "22222222222222222222222222:" result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}) if [[ $? -ne 0 ]]; then echo "+++ cat openim log file >>> ${LOG_FILE}" From 6e2132d217e9e77a3ba6afcf9e913aeef7cb24ef Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:10:19 +0800 Subject: [PATCH 3/9] scripts for Mac --- scripts/lib/util.sh | 93 +++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 7bcfbad97..0d95acc7c 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -382,81 +382,76 @@ openim::util::check_ports() { # User: # openim::util::check_process_names nginx mysql redis # The function returns a status of 1 if any of the processes is not running. + openim::util::check_process_names() { # Function to get the port of a process get_port() { local pid=$1 - if [[ "$OSTYPE" == "linux-gnu"* ]]; then - # Linux - 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 - echo "Unsupported OS" - return 1 - fi + case "$OSTYPE" in + "linux-gnu"*) + # Linux + ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2 + ;; + "darwin"*) + # macOS + lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://' + ;; + *) + echo "Unsupported OS" + return 1 + ;; + esac } - - # Arrays to collect details of processes + + # Arrays to collect process details local not_started=() local started=() - # Iterate over each given process name + # Iterate over each given process name for process_name in "$@"; do - # Use `pgrep` to find process IDs related to the given process name - local pids=($(pgrep -f $process_name)) - - # Check if any process IDs were found - if [[ ${#pids[@]} -eq 0 ]]; then - not_started+=($process_name) - else - # If there are PIDs, loop through each one - for pid in "${pids[@]}"; do - local command=$(ps -p $pid -o cmd=) - local start_time=$(ps -p $pid -o lstart=) - local port=$(get_port $pid) - - # Check if port information was found for the PID - if [[ -z $port ]]; then - port="N/A" - fi - - started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") - done - fi - done + local pids=($(pgrep -f "$process_name")) - - # Print information + if [[ ${#pids[@]} -eq 0 ]]; then + not_started+=("$process_name") + else + for pid in "${pids[@]}"; do + local command=$(ps -p $pid -o cmd=) + local start_time=$(ps -p $pid -o lstart=) + local port=$(get_port $pid) + port=${port:-N/A} + + started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") + done + fi + done + + # Print not started processes if [[ ${#not_started[@]} -ne 0 ]]; then echo "Not started processes:" for process_name in "${not_started[@]}"; do - echo "Process $process_name is not started." + echo " - Process $process_name is not started." done fi - + + # Print started processes if [[ ${#started[@]} -ne 0 ]]; then - echo - echo "Started processes:" + echo -e "\nStarted processes:" for info in "${started[@]}"; do - echo "$info" + echo " - $info" done fi - - # Return status + + # Return status based on whether any processes have not started if [[ ${#not_started[@]} -ne 0 ]]; then - 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"}' + echo -e "\nSome processes have not started. Please check the logs for more information." return 1 else - echo "" - openim::log::success "All processes are running." + echo -e "\nAll processes are running." return 0 fi } + openim::util::check_process_names_for_stop() { # Function to get the port of a process get_port() { From 825416bbbac62cc2a287ff8b4dc47388a8448570 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:12:24 +0800 Subject: [PATCH 4/9] scripts for Mac --- scripts/lib/util.sh | 87 ++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 0d95acc7c..68a390c44 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -382,76 +382,83 @@ openim::util::check_ports() { # User: # openim::util::check_process_names nginx mysql redis # The function returns a status of 1 if any of the processes is not running. - openim::util::check_process_names() { # Function to get the port of a process get_port() { local pid=$1 - case "$OSTYPE" in - "linux-gnu"*) - # Linux - ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2 - ;; - "darwin"*) - # macOS - lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://' - ;; - *) - echo "Unsupported OS" - return 1 - ;; - esac + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Linux + 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 + echo "Unsupported OS" + return 1 + fi } - # Arrays to collect process details + # Arrays to collect details of processes local not_started=() local started=() - # Iterate over each given process name + # Iterate over each given process name for process_name in "$@"; do - local pids=($(pgrep -f "$process_name")) - - if [[ ${#pids[@]} -eq 0 ]]; then - not_started+=("$process_name") - else - for pid in "${pids[@]}"; do - local command=$(ps -p $pid -o cmd=) - local start_time=$(ps -p $pid -o lstart=) - local port=$(get_port $pid) - port=${port:-N/A} + # Use `pgrep` to find process IDs related to the given process name + local pids=($(pgrep -f $process_name)) + + # Check if any process IDs were found + if [[ ${#pids[@]} -eq 0 ]]; then + not_started+=($process_name) + else + # If there are PIDs, loop through each one + for pid in "${pids[@]}"; do + echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + local command=$(ps -p $pid -o cmd=) + local start_time=$(ps -p $pid -o lstart=) + local port=$(get_port $pid) + + # Check if port information was found for the PID + if [[ -z $port ]]; then + port="N/A" + fi + + started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") + echo bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + done + fi + done - started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") - done - fi - done - # Print not started processes + # Print information if [[ ${#not_started[@]} -ne 0 ]]; then echo "Not started processes:" for process_name in "${not_started[@]}"; do - echo " - Process $process_name is not started." + echo "Process $process_name is not started." done fi - # Print started processes if [[ ${#started[@]} -ne 0 ]]; then - echo -e "\nStarted processes:" + echo + echo "Started processes:" for info in "${started[@]}"; do - echo " - $info" + echo "$info" done fi - # Return status based on whether any processes have not started + # Return status if [[ ${#not_started[@]} -ne 0 ]]; then - echo -e "\nSome processes have not started. Please check the logs for more information." + 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"}' return 1 else - echo -e "\nAll processes are running." + echo "" + openim::log::success "All processes are running." return 0 fi } - openim::util::check_process_names_for_stop() { # Function to get the port of a process get_port() { From a64f6d108ab62115c5702fdecbc77aa9dac455bd Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:14:01 +0800 Subject: [PATCH 5/9] scripts for Mac --- scripts/lib/util.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 68a390c44..670f2090f 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -415,6 +415,8 @@ openim::util::check_process_names() { for pid in "${pids[@]}"; do echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa local command=$(ps -p $pid -o cmd=) + + echo "ps -p $pid -o cmd=" local start_time=$(ps -p $pid -o lstart=) local port=$(get_port $pid) From a338731fe9de96dedb2cb6b5c7d3f0bce2fe5a6a Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:17:05 +0800 Subject: [PATCH 6/9] scripts for Mac --- scripts/lib/util.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 670f2090f..5cbe32d8b 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -426,7 +426,7 @@ openim::util::check_process_names() { fi started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") - echo bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb + echo bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb $started done fi done From e81803a53d38d04e509fac09d2e068091fdb7bd5 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:21:01 +0800 Subject: [PATCH 7/9] scripts for Mac --- scripts/lib/util.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 5cbe32d8b..993ddcae1 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -414,9 +414,10 @@ openim::util::check_process_names() { # If there are PIDs, loop through each one for pid in "${pids[@]}"; do echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa - local command=$(ps -p $pid -o cmd=) + local command=$(ps -p $pid -o comm=) + + echo "ps -p $pid -o comm=" - echo "ps -p $pid -o cmd=" local start_time=$(ps -p $pid -o lstart=) local port=$(get_port $pid) From 0e61c3acefde88a605340b84121b47fcecab33e2 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:24:23 +0800 Subject: [PATCH 8/9] scripts for Mac --- scripts/lib/util.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 993ddcae1..dcce56c12 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -397,7 +397,7 @@ openim::util::check_process_names() { return 1 fi } - + # Arrays to collect details of processes local not_started=() local started=() @@ -413,11 +413,7 @@ openim::util::check_process_names() { else # If there are PIDs, loop through each one for pid in "${pids[@]}"; do - echo aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa local command=$(ps -p $pid -o comm=) - - echo "ps -p $pid -o comm=" - local start_time=$(ps -p $pid -o lstart=) local port=$(get_port $pid) @@ -427,12 +423,11 @@ openim::util::check_process_names() { fi started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time") - echo bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb $started done fi done - + # Print information if [[ ${#not_started[@]} -ne 0 ]]; then echo "Not started processes:" @@ -440,7 +435,7 @@ openim::util::check_process_names() { echo "Process $process_name is not started." done fi - + if [[ ${#started[@]} -ne 0 ]]; then echo echo "Started processes:" @@ -448,7 +443,7 @@ openim::util::check_process_names() { echo "$info" done fi - + # Return status if [[ ${#not_started[@]} -ne 0 ]]; then openim::color::echo $COLOR_RED "OpenIM Stdout Log >> cat ${LOG_FILE}" @@ -494,7 +489,7 @@ openim::util::check_process_names_for_stop() { else # If there are PIDs, loop through each one for pid in "${pids[@]}"; do - local command=$(ps -p $pid -o cmd=) + local command=$(ps -p $pid -o comm=) local start_time=$(ps -p $pid -o lstart=) local port=$(get_port $pid) From 66dd9f6e094c5beb4430e5af4a92c838492b7007 Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Tue, 19 Mar 2024 15:00:03 +0800 Subject: [PATCH 9/9] scripts for Mac --- scripts/check-all.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 865583d4b..d41023384 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -99,9 +99,6 @@ for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do echo "$item" done -echo "11111111111111111111111:" -openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]} -echo "22222222222222222222222222:" result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}) if [[ $? -ne 0 ]]; then echo "+++ cat openim log file >>> ${LOG_FILE}"