diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 60e49cf61..3fe0866c8 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -80,19 +80,25 @@ 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 -openim::log::info "\n## Check all OpenIM service ports" -echo "+++ The process being checked:" +openim::log::info "\n## Check OpenIM service name ${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer" +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 "check process failed.\n $result" +fi + + +echo "Check OpenIM service name:" for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do echo "$item" done + 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 "check process failed.\n $result" else - echo "++++ Check all openim service ports successfully !" + echo "Check all openim service ports successfully !" fi diff --git a/scripts/install/openim-api.sh b/scripts/install/openim-api.sh index 933fef2ce..8a7b8d1f1 100755 --- a/scripts/install/openim-api.sh +++ b/scripts/install/openim-api.sh @@ -48,11 +48,7 @@ function openim::api::start() { openim::log::info "Starting ${SERVER_NAME} ..." readonly OPENIM_API_SERVER_LIBRARIES="${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}" - result=$(openim::util::stop_services_with_name ${OPENIM_API_SERVER_LIBRARIES}) - if [[ $? -ne 0 ]]; then - openim::log::error "stop ${SERVER_NAME} failed" - return 1 - fi + printf "+------------------------+--------------+\n" printf "| Service Name | Port |\n" @@ -64,8 +60,6 @@ function openim::api::start() { printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" printf "+------------------------+--------------+\n" # Stop services on the specified ports before starting new ones -# openim::util::stop_services_on_ports "${OPENIM_API_PORT_LISTARIES[$i]}" -# openim::util::stop_services_on_ports "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}" openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}" # Start the service with Prometheus port if specified diff --git a/scripts/install/openim-crontask.sh b/scripts/install/openim-crontask.sh index b139cb14a..ae78a44dd 100755 --- a/scripts/install/openim-crontask.sh +++ b/scripts/install/openim-crontask.sh @@ -49,13 +49,7 @@ function openim::crontask::start() { openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}" openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}" - - result=$(openim::util::stop_services_with_name ${OPENIM_CRONTASK_BINARY}) - if [[ $? -ne 0 ]]; then - openim::log::error "stop ${SERVER_NAME} failed" - return 1 - fi - + openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}" nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) & diff --git a/scripts/install/openim-msggateway.sh b/scripts/install/openim-msggateway.sh index 79bdee222..151538101 100755 --- a/scripts/install/openim-msggateway.sh +++ b/scripts/install/openim-msggateway.sh @@ -31,12 +31,7 @@ function openim::msggateway::start() { openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}" openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}" - - result=$(openim::util::stop_services_with_name ${OPENIM_MSGGATEWAY_BINARY}) - if [[ $? -ne 0 ]]; then - openim::log::error "stop ${SERVER_NAME} failed" - return 1 - fi + # OpenIM message gateway service port OPENIM_MESSAGE_GATEWAY_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} ) diff --git a/scripts/install/openim-msgtransfer.sh b/scripts/install/openim-msgtransfer.sh index bc16bfa97..4abf9b5e2 100755 --- a/scripts/install/openim-msgtransfer.sh +++ b/scripts/install/openim-msgtransfer.sh @@ -67,11 +67,8 @@ function openim::msgtransfer::start() { function openim::msgtransfer::check() { PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer") - NUM_PROCESSES=$(echo "$PIDS" | wc -l) - echo "111111111111transfer check " "$NUM_PROCESSES" "$OPENIM_MSGGATEWAY_NUM" 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 if [[ "$OSTYPE" == "linux-gnu"* ]]; then ps -p $PID -o pid,cmd @@ -83,7 +80,9 @@ function openim::msgtransfer::check() { done else openim::log::error "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes." + return 1 fi + return 0 } function openim::msgtransfer::check_for_stop() { diff --git a/scripts/install/openim-push.sh b/scripts/install/openim-push.sh index 48a298aac..8684f185c 100755 --- a/scripts/install/openim-push.sh +++ b/scripts/install/openim-push.sh @@ -61,13 +61,7 @@ function openim::push::start() { OPENIM_PUSH_PORTS_ARRAY=$(openim::util::list-to-string ${OPENIM_PUSH_PORT} ) PUSH_PROM_PORTS_ARRAY=$(openim::util::list-to-string ${PUSH_PROM_PORT} ) - - result=$(openim::util::stop_services_with_name ${OPENIM_PUSH_BINARY}) - if [[ $? -ne 0 ]]; then - openim::log::error "stop ${OPENIM_PUSH_BINARY} failed \n " "${result}" - return 1 - fi - + openim::log::status "push port list: ${OPENIM_PUSH_PORTS_ARRAY[@]}" openim::log::status "prometheus port list: ${PUSH_PROM_PORTS_ARRAY[@]}" diff --git a/scripts/install/openim-rpc.sh b/scripts/install/openim-rpc.sh index 3d5350131..023cb6594 100755 --- a/scripts/install/openim-rpc.sh +++ b/scripts/install/openim-rpc.sh @@ -131,11 +131,7 @@ function openim::rpc::start() { printf "+------------------------+-------+-----------------+\n" done - result=$(openim::util::stop_services_with_name ${OPENIM_ALL_RPC_FULL_PATH[@]}) - if [[ $? -ne 0 ]]; then - openim::log::error "stop ${SERVER_NAME} failed" "$result" - fi - sleep 5 + # start all rpc services for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do diff --git a/scripts/start-all.sh b/scripts/start-all.sh index ef6b7c154..e1c9ea238 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -24,7 +24,7 @@ source "${OPENIM_ROOT}/scripts/install/common.sh" # Function to execute the scripts. -function execute_scripts() { +function execute_start_scripts() { for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do # Extract the script name without extension for argument generation. script_name_with_prefix=$(basename "$script_path" .sh) @@ -79,26 +79,36 @@ openim::log::info "\n## Pre Starting OpenIM services" ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start -"${OPENIM_ROOT}"/scripts/stop-all.sh +result=$("${OPENIM_ROOT}"/scripts/stop-all.sh) +if [[ $? -ne 0 ]]; then + echo "+++ cat openim log file >>> ${LOG_FILE}" + openim::log::error "Some programs have not exited; the start process is aborted .\n $result" + exit 1 +fi -sleep 10 openim::log::info "\n## Starting OpenIM services" -execute_scripts +execute_start_scripts -sleep 2 -openim::log::info "\n## Check OpenIM service name" -. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check +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 -echo "+++ The process being checked:" -for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do - echo "$item" -done 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 + openim::log::info "\n## Post Starting OpenIM services" ${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start diff --git a/scripts/stop-all.sh b/scripts/stop-all.sh index f3457f599..b0070ae68 100755 --- a/scripts/stop-all.sh +++ b/scripts/stop-all.sh @@ -34,14 +34,24 @@ openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}" # todo OPENIM_ALL_SERVICE_LIBRARIES - -sleep 5 - -result=$(openim::util::check_process_names_for_stop) -if [[ $? -ne 0 ]]; then - echo "+++ cat openim log file >>> ${LOG_FILE}" - openim::log::error "stop process failed.\n" "${result}" -else - openim::log::success "✨ All processes to be stopped" -fi - +max_retries=15 +attempt=0 + +while [[ $attempt -lt $max_retries ]] +do + result=$(openim::util::check_process_names_for_stop) + + if [[ $? -ne 0 ]]; then + echo "+++ cat openim log file >>> ${LOG_FILE}" + openim::log::error "stop process failed. continue waiting\n" "${result}" + sleep 1 + ((attempt++)) + + else + openim::log::success "✨ All processes to be stopped" + exit 0 + fi +done + +openim::log::error "✨ openim processes stopped failed" +exit 1