From 14bce90f14c2b66b39f4dc4319e6b9cafc6d658e Mon Sep 17 00:00:00 2001 From: skiffer-git <44203734@qq.com> Date: Wed, 6 Mar 2024 15:30:50 +0800 Subject: [PATCH] Optimize script logs --- scripts/lib/util.sh | 49 ++++++++++++++++++++++---------------------- scripts/start-all.sh | 2 -- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 4322255bb..bf636fd45 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -402,30 +402,31 @@ openim::util::check_process_names() { local not_started=() local started=() - # 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 +# 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 | tr -d '\n') # Use `tr` to remove newline characters + + # 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 + # Print information if [[ ${#not_started[@]} -ne 0 ]]; then diff --git a/scripts/start-all.sh b/scripts/start-all.sh index 6bb41515c..89f708ffa 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -95,7 +95,6 @@ sleep 2 result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check) if [[ $? -ne 0 ]]; then - echo "+++ cat openim log file >>> ${LOG_FILE}" openim::log::error "The program may fail to start.\n $result" exit 1 fi @@ -103,7 +102,6 @@ fi result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}) if [[ $? -ne 0 ]]; then - echo "+++ cat openim log file >>> ${LOG_FILE}" openim::log::error "The program may fail to start.\n $result" exit 1 fi