diff --git a/scripts/install/openim-tools.sh b/scripts/install/openim-tools.sh index 4eb722c6e..003264221 100755 --- a/scripts/install/openim-tools.sh +++ b/scripts/install/openim-tools.sh @@ -101,7 +101,16 @@ function openim::tools::start_service() { cmd="${cmd} --prometheus_port ${prometheus_port}" fi openim::log::status "Starting binary ${binary_name}..." - ${cmd} | tee -a "${LOG_FILE}" + ${cmd} >>"${LOG_FILE}" 2> >(tee -a "${LOG_FILE}" >&2) + local status=$? + + if [ $status -eq 0 ]; then + openim::log::info "Service ${binary_name} started successfully." + return 0 + else + openim::log::error "Failed to start service ${binary_name}." + return 1 + fi } function openim::tools::start() { @@ -115,11 +124,15 @@ function openim::tools::start() { function openim::tools::pre-start() { - openim::log::info "Preparing to start OpenIM Tools..." - for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do - openim::log::info "Starting tool ${tool}..." - openim::tools::start_service ${tool} ${OPNEIM_CONFIG} - done + openim::log::info "Preparing to start OpenIM Tools..." + for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do + openim::log::info "Starting tool ${tool}..." + if ! openim::tools::start_service ${tool} ${OPNEIM_CONFIG}; then + openim::log::error "Failed to start ${tool}, aborting..." + return 1 + fi + done + openim::log::info "All tools started successfully." } function openim::tools::post-start() { diff --git a/scripts/start-all.sh b/scripts/start-all.sh index 419c16628..aac4b1837 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -83,10 +83,18 @@ fi # TODO Prelaunch tools, simple for now, can abstract functions later TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh -openim::log::status "\n## Pre Starting OpenIM services" -${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start +openim::log::print_blue "\n## Pre Starting OpenIM services" + +if ! ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start; then + openim::log::error "Pre Starting OpenIM services failed, aborting..." + exit 1 +fi + + +openim::log::print_blue "Pre Starting OpenIM services processed successfully" + result=$("${OPENIM_ROOT}"/scripts/stop-all.sh) if [[ $? -ne 0 ]]; then openim::log::error "View the error logs from this startup. ${LOG_FILE} \n" diff --git a/tools/component/component.go b/tools/component/component.go index 34d3dff6b..e3b5b1956 100644 --- a/tools/component/component.go +++ b/tools/component/component.go @@ -102,7 +102,14 @@ func main() { if !check.flag { err = check.function(check.config) if err != nil { - allSuccess = false + if errors.Is(err, errMinioNotEnabled) { + fmt.Println(err.Error()) + checks[index].flag = true + } + if errors.Is(err, errSignEndPoint) { + fmt.Fprintf(os.Stderr, err.Error()) + checks[index].flag = true + } component.ErrorPrint(fmt.Sprintf("Starting %s failed:%v.", check.name, errs.Unwrap(err).Error())) if !strings.Contains(errs.Unwrap(err).Error(), "connection refused") && !strings.Contains(errs.Unwrap(err).Error(), "timeout waiting") { @@ -125,6 +132,11 @@ func main() { os.Exit(-1) } +var errMinioNotEnabled = errors.New("minio.Enable is not configured to use MinIO") + +var errSignEndPoint = errors.New("minio.signEndPoint contains 127.0.0.1, causing issues with image sending") +var errApiURL = errors.New("object.apiURL contains 127.0.0.1, causing issues with image sending") + // checkMongo checks the MongoDB connection without retries func checkMongo(config *config.GlobalConfig) error { mongoStu := &component.Mongo{ @@ -153,10 +165,16 @@ func checkRedis(config *config.GlobalConfig) error { // checkMinio checks the MinIO connection func checkMinio(config *config.GlobalConfig) error { - // Check if MinIO is enabled + if strings.Contains(config.Object.ApiURL, "127.0.0.1") { + return errs.Wrap(errApiURL, "config.Object.ApiURL: "+config.Object.ApiURL) + } if config.Object.Enable != "minio" { - return errs.Wrap(errors.New("minio.Enable is empty")) + return errs.Wrap(errMinioNotEnabled, "config.Object.Enable: "+config.Object.Enable) + } + if strings.Contains(config.Object.Minio.Endpoint, "127.0.0.1") { + return errs.Wrap(errSignEndPoint, "config.Object.Minio.Endpoint: "+config.Object.Minio.Endpoint) } + minio := &component.Minio{ ApiURL: config.Object.ApiURL, Endpoint: config.Object.Minio.Endpoint,