diff --git a/pkg/util/genutil/genutil.go b/pkg/util/genutil/genutil.go index f8efa8825..837235f85 100644 --- a/pkg/util/genutil/genutil.go +++ b/pkg/util/genutil/genutil.go @@ -48,5 +48,5 @@ func ExitWithError(err error) { func SIGTERMExit() { progName := filepath.Base(os.Args[0]) - fmt.Printf("%s receive process terminal SIGTERM exit 0", progName) + fmt.Fprintf(os.Stderr, "Warning %s receive process terminal SIGTERM exit 0", progName) } diff --git a/scripts/check-all-by-signal.sh b/scripts/check-all-by-signal.sh index 8149392e4..8bb5c6b0d 100644 --- a/scripts/check-all-by-signal.sh +++ b/scripts/check-all-by-signal.sh @@ -42,10 +42,9 @@ trap handle_error ERR openim::util::check_ports_by_signal ${OPENIM_SERVER_PORT_LISTARIES[@]} if [[ $? -ne 0 ]]; then - openim::log::success "++++ All openim service ports stop successfully !" -else - echo "+++ cat openim log file >>> ${LOG_FILE}" openim::log::error "The service does not stop properly, there are still processes running, please check!" +else + openim::log::success "++++ All openim service ports stop successfully !" fi diff --git a/scripts/install/openim-api.sh b/scripts/install/openim-api.sh index be2a2d33b..70d5b31fa 100755 --- a/scripts/install/openim-api.sh +++ b/scripts/install/openim-api.sh @@ -82,6 +82,7 @@ function openim::api::start_service() { echo "Starting service with command: $cmd" nohup $cmd >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) & + if [ $? -ne 0 ]; then openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}." diff --git a/scripts/install/openim-msgtransfer.sh b/scripts/install/openim-msgtransfer.sh index 584d9624e..00d8303d6 100755 --- a/scripts/install/openim-msgtransfer.sh +++ b/scripts/install/openim-msgtransfer.sh @@ -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" @@ -93,7 +92,7 @@ function openim::msgtransfer::check_by_signal() { NUM_PROCESSES=$(echo "$PIDS" | wc -l | xargs) if [ "$NUM_PROCESSES" -gt 0 ]; then - openim::log::info "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 ps -p $PID -o pid,cmd @@ -109,6 +108,39 @@ function openim::msgtransfer::check_by_signal() { fi } +function openim::msgtransfer::check_by_signal() { + PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer") + if [ -z "$PIDS" ]; then + openim::log::success "All openim-msgtransfer processes have been stopped properly." + return 0 + fi + + openim::log::error "Found processes for $OPENIM_OUTPUT_HOSTBIN/openim-msgtransfer:" + for PID in $PIDS; do + if [[ "$OSTYPE" == "linux-gnu"* ]]; then + # Extract details for Linux + details=$(ps -p $PID -o pid,comm,lstart= | awk 'NR>1 {print $1, $2, $3, $4, $5, $6, $7}') + command=$(echo $details | awk '{print $2}') + start_time=$(echo $details | awk '{print $3, $4, $5, $6, $7}') + elif [[ "$OSTYPE" == "darwin"* ]]; then + # Handle details extraction for macOS + details=$(ps -p $PID -o pid,comm,start= | awk 'NR>1 {print $1, $2, $3}') + command=$(echo $details | awk '{print $2}') + start_time=$(echo $details | awk '{print $3}') + else + openim::log::error "Unsupported OS type: $OSTYPE" + return 1 + fi + + # Assuming FD and port number are not directly retrievable for msgtransfer processes + openim::log::error "PID: $PID - Command: $command, Started: $start_time" + done + + openim::log::success "Processes have not been stopped properly." + return 1 +} + + function openim::msgtransfer::check_by_signal1() { PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer") diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 194a57d6e..f3663d5fb 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -378,7 +378,6 @@ openim::util::check_ports_by_signal() { # 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 @@ -432,22 +431,21 @@ openim::util::check_ports_by_signal() { # Print information about ports whose processes are running. if [[ ${#started[@]} -ne 0 ]]; then - openim::log::info "\n### No stop ports:" + openim::log::error "\n### No stop ports:" for info in "${started[@]}"; do - openim::log::info "$info" + 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 running." - return 1 + return 0 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 + return 1 fi }