mirror of
				https://github.com/openimsdk/open-im-server.git
				synced 2025-11-01 00:42:13 +08:00 
			
		
		
		
	feat: add config path
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
		
							parent
							
								
									859063ddba
								
							
						
					
					
						commit
						7f4de7fda7
					
				| @ -34,17 +34,18 @@ print_services_and_ports() { | |||||||
|     local -n service_names=$1 |     local -n service_names=$1 | ||||||
|     local -n service_ports=$2 |     local -n service_ports=$2 | ||||||
| 
 | 
 | ||||||
|     echo "+-------------------+-------+" |     echo "+-------------------------+----------+" | ||||||
|     echo "| Service Name            | Port     |" |     echo "| Service Name            | Port     |" | ||||||
|     echo "+-------------------+-------+" |     echo "+-------------------------+----------+" | ||||||
| 
 | 
 | ||||||
|     for index in "${!service_names[@]}"; do |     for index in "${!service_names[@]}"; do | ||||||
|         printf "| %-17s | %-5s |\n" "${service_names[$index]}" "${service_ports[$index]}" |         printf "| %-23s | %-8s |\n" "${service_names[$index]}" "${service_ports[$index]}" | ||||||
|     done |     done | ||||||
| 
 | 
 | ||||||
|     echo "+-------------------+-------+" |     echo "+-------------------------+----------+" | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| # Print out services and their ports | # Print out services and their ports | ||||||
| print_services_and_ports OPENIM_SERVER_NAME_TARGETS OPENIM_SERVER_PORT_TARGETS | print_services_and_ports OPENIM_SERVER_NAME_TARGETS OPENIM_SERVER_PORT_TARGETS | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -27,8 +27,6 @@ source "${OPENIM_ROOT}/scripts/lib/init.sh" | |||||||
| # Make sure the environment is only called via common to avoid too much nesting | # Make sure the environment is only called via common to avoid too much nesting | ||||||
| source "${OPENIM_ROOT}/scripts/install/environment.sh" | source "${OPENIM_ROOT}/scripts/install/environment.sh" | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| # This function returns a list of Prometheus ports for various services | # This function returns a list of Prometheus ports for various services | ||||||
| # based on the provided configuration. Each service has its own dedicated | # based on the provided configuration. Each service has its own dedicated | ||||||
| # port for monitoring purposes. | # port for monitoring purposes. | ||||||
|  | |||||||
							
								
								
									
										0
									
								
								scripts/install/install-protobuf.sh
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								scripts/install/install-protobuf.sh
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @ -56,8 +56,9 @@ source ${OPENIM_ROOT}/scripts/install/openim-push.sh | |||||||
| source ${OPENIM_ROOT}/scripts/install/openim-rpc.sh | source ${OPENIM_ROOT}/scripts/install/openim-rpc.sh | ||||||
| source ${OPENIM_ROOT}/scripts/install/openim-crontask.sh | source ${OPENIM_ROOT}/scripts/install/openim-crontask.sh | ||||||
| source ${OPENIM_ROOT}/scripts/install/openim-api.sh | source ${OPENIM_ROOT}/scripts/install/openim-api.sh | ||||||
|  | source ${OPENIM_ROOT}/scripts/install/openim-man.sh | ||||||
|  | source ${OPENIM_ROOT}/scripts/install/openim-tools.sh | ||||||
| source ${OPENIM_ROOT}/scripts/install/test.sh | source ${OPENIM_ROOT}/scripts/install/test.sh | ||||||
| source ${OPENIM_ROOT}/scripts/install/man.sh |  | ||||||
| 
 | 
 | ||||||
| # Detailed help function | # Detailed help function | ||||||
| function openim::install::show_help() { | function openim::install::show_help() { | ||||||
|  | |||||||
| @ -29,7 +29,7 @@ | |||||||
| # Usage: | # Usage: | ||||||
| # 1. Direct Script Execution: | # 1. Direct Script Execution: | ||||||
| #    This will start the OpenIM CronTask directly through a background process. | #    This will start the OpenIM CronTask directly through a background process. | ||||||
| #    Example: ./openim-crontask.sh | #    Example: ./openim-crontask.sh openim::crontask::start | ||||||
| #  | #  | ||||||
| # 2. Controlling through Functions for systemctl operations: | # 2. Controlling through Functions for systemctl operations: | ||||||
| #    Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script. | #    Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script. | ||||||
| @ -38,7 +38,6 @@ | |||||||
| # Note: Ensure that the appropriate permissions and environmental variables are set prior to script execution. | # Note: Ensure that the appropriate permissions and environmental variables are set prior to script execution. | ||||||
| #  | #  | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) | OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) | ||||||
| [[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh | [[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -13,6 +13,31 @@ | |||||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
| # See the License for the specific language governing permissions and | # See the License for the specific language governing permissions and | ||||||
| # limitations under the License. | # limitations under the License. | ||||||
|  | # | ||||||
|  | # OpenIM RPC Service Control Script | ||||||
|  | #  | ||||||
|  | # Description: | ||||||
|  | # This script provides a control interface for the OpenIM RPC service within a Linux environment. It offers functionalities to start multiple RPC services, each denoted by their respective names under openim::rpc::service_name. | ||||||
|  | #  | ||||||
|  | # Features: | ||||||
|  | # 1. Robust error handling using Bash built-ins like 'errexit', 'nounset', and 'pipefail'. | ||||||
|  | # 2. The capability to source common utility functions and configurations to ensure uniform environmental settings. | ||||||
|  | # 3. Comprehensive logging functionalities, providing a detailed understanding of operational processes. | ||||||
|  | # 4. Provision for declaring and managing a set of RPC services, each associated with its unique name and corresponding ports. | ||||||
|  | # 5. The ability to define and associate Prometheus ports for service monitoring purposes. | ||||||
|  | # 6. Functionalities to start each RPC service, along with its designated ports, in a sequence. | ||||||
|  | # | ||||||
|  | # Usage: | ||||||
|  | # 1. Direct Script Execution: | ||||||
|  | #    This initiates all the RPC services declared under the function openim::rpc::service_name. | ||||||
|  | #    Example: ./openim-rpc-{rpc-name}.sh  openim::rpc::start | ||||||
|  | # 2. Controlling through Functions for systemctl operations: | ||||||
|  | #    Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script. | ||||||
|  | #    Example: ./openim-rpc-{rpc-name}.sh openim::rpc::install | ||||||
|  | # | ||||||
|  | # Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set. | ||||||
|  | # | ||||||
|  | 
 | ||||||
| 
 | 
 | ||||||
| set -o errexit | set -o errexit | ||||||
| set +o nounset | set +o nounset | ||||||
| @ -77,8 +102,7 @@ IFS=" " read -ra OPENIM_RPC_PROM_PORT_TARGETS <<< "$(openim::rpc::prometheus_por | |||||||
| readonly OPENIM_RPC_PROM_PORT_TARGETS | readonly OPENIM_RPC_PROM_PORT_TARGETS | ||||||
| readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}") | readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}") | ||||||
| 
 | 
 | ||||||
| function openim::rpc::start() | function openim::rpc::start() { | ||||||
| { |  | ||||||
|     echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}" |     echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}" | ||||||
|     echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}" |     echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}" | ||||||
|     echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}" |     echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}" | ||||||
|  | |||||||
							
								
								
									
										166
									
								
								scripts/install/openim-tools.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										166
									
								
								scripts/install/openim-tools.sh
									
									
									
									
									
										Executable file
									
								
							| @ -0,0 +1,166 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | 
 | ||||||
|  | # Copyright © 2023 OpenIM. All rights reserved. | ||||||
|  | # | ||||||
|  | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  | # you may not use this file except in compliance with the License. | ||||||
|  | # You may obtain a copy of the License at | ||||||
|  | # | ||||||
|  | #     http://www.apache.org/licenses/LICENSE-2.0 | ||||||
|  | # | ||||||
|  | # Unless required by applicable law or agreed to in writing, software | ||||||
|  | # distributed under the License is distributed on an "AS IS" BASIS, | ||||||
|  | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||
|  | # See the License for the specific language governing permissions and | ||||||
|  | # limitations under the License. | ||||||
|  | # | ||||||
|  | # OpenIM Tools Control Script | ||||||
|  | # | ||||||
|  | # Description: | ||||||
|  | #  This script is responsible for managing the lifecycle of OpenIM tools, which include starting, stopping, | ||||||
|  | #  and handling pre and post operations. It's designed to be modular and extensible, ensuring that the  | ||||||
|  | #  individual operations can be managed separately, and integrated seamlessly with Linux systemd. | ||||||
|  | #  | ||||||
|  | # Features: | ||||||
|  | # 1. Robust error handling using Bash built-ins like 'errexit', 'nounset', and 'pipefail'. | ||||||
|  | # 2. The capability to source common utility functions and configurations to ensure uniform environmental settings. | ||||||
|  | # 3. Comprehensive logging functionalities, providing a detailed understanding of operational processes. | ||||||
|  | # 4. Provision for declaring and managing a set of OpenIM tools, each associated with its unique name and corresponding ports. | ||||||
|  | # 5. The ability to define and associate Prometheus ports for service monitoring purposes. | ||||||
|  | # 6. Functionalities to start each OpenIM tool, along with its designated ports, in a sequence. | ||||||
|  | # | ||||||
|  | # Usage: | ||||||
|  | # 1. Direct Script Execution: | ||||||
|  | #    This initiates all the OpenIM tools declared under the function openim::tools::service_name. | ||||||
|  | #    Example: ./openim-tools.sh  openim::tools::start | ||||||
|  | # 2. Controlling through Functions for systemctl operations: | ||||||
|  | #    Specific operations like installation, uninstallation, and status check can be executed by passing the respective function name as an argument to the script. | ||||||
|  | #    Example: ./openim-tools.sh openim::tools::install | ||||||
|  | # | ||||||
|  | 
 | ||||||
|  | set -o errexit | ||||||
|  | set +o nounset | ||||||
|  | set -o pipefail | ||||||
|  | 
 | ||||||
|  | OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P) | ||||||
|  | [[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh | ||||||
|  | 
 | ||||||
|  | SERVER_NAME="openim-tools" | ||||||
|  | 
 | ||||||
|  | openim::tools::start_name() { | ||||||
|  |   local targets=( | ||||||
|  |     imctl | ||||||
|  |   ) | ||||||
|  |   echo "${targets[@]}" | ||||||
|  | } | ||||||
|  | IFS=" " read -ra OPENIM_TOOLS_NAME_TARGETS <<< "$(openim::tools::start_name)" | ||||||
|  | readonly OPENIM_TOOLS_NAME_TARGETS | ||||||
|  | readonly OPENIM_TOOLS_NAME_LISTARIES=("${OPENIM_TOOLS_NAME_TARGETS[@]##*/}") | ||||||
|  | 
 | ||||||
|  | openim::tools::pre_start_name() { | ||||||
|  |   local targets=( | ||||||
|  |     ncpu | ||||||
|  |     component | ||||||
|  |   ) | ||||||
|  |   echo "${targets[@]}" | ||||||
|  | } | ||||||
|  | IFS=" " read -ra OPENIM_TOOLS_PRE_START_NAME_TARGETS <<< "$(openim::tools::pre_start_name)" | ||||||
|  | readonly OPENIM_TOOLS_PRE_START_NAME_TARGETS | ||||||
|  | readonly OPENIM_TOOLS_PRE_START_NAME_LISTARIES=("${OPENIM_TOOLS_PRE_START_NAME_TARGETS[@]##*/}") | ||||||
|  | 
 | ||||||
|  | openim::tools::post_start_name() { | ||||||
|  |   local targets=( | ||||||
|  |     infra | ||||||
|  |   ) | ||||||
|  |   echo "${targets[@]}" | ||||||
|  | } | ||||||
|  | IFS=" " read -ra OPENIM_TOOLS_POST_START_NAME_TARGETS <<< "$(openim::tools::post_start_name)" | ||||||
|  | readonly OPENIM_TOOLS_POST_START_NAME_TARGETS | ||||||
|  | readonly OPENIM_TOOLS_POST_START_NAME_LISTARIES=("${OPENIM_TOOLS_POST_START_NAME_TARGETS[@]##*/}") | ||||||
|  | 
 | ||||||
|  | function openim::tools::start_service() { | ||||||
|  |   local binary_name="$1" | ||||||
|  |   local config="$2" | ||||||
|  |   local service_port="$3" | ||||||
|  |   local prometheus_port="$4" | ||||||
|  | 
 | ||||||
|  |   local cmd="${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${binary_name}" | ||||||
|  |   openim::log::info "Starting PATH: ${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${binary_name}..." | ||||||
|  | 
 | ||||||
|  |   if [ -n "${config}" ]; then | ||||||
|  |     printf "Specifying config: %s\n" "${config}" | ||||||
|  |     cmd="${cmd} -c ${config}/config.yaml" | ||||||
|  |   fi | ||||||
|  | 
 | ||||||
|  |   if [ -n "${service_port}" ]; then | ||||||
|  |     printf "Specifying service port: %s\n" "${service_port}" | ||||||
|  |     cmd="${cmd} --port ${service_port}" | ||||||
|  |   fi | ||||||
|  | 
 | ||||||
|  |   if [ -n "${prometheus_port}" ]; then | ||||||
|  |     printf "Specifying prometheus port: %s\n" "${prometheus_port}" | ||||||
|  |     cmd="${cmd} --prometheus_port ${prometheus_port}" | ||||||
|  |   fi | ||||||
|  |   openim::log::info "Starting ${binary_name}..." | ||||||
|  |   ${cmd} | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function openim::tools::start() { | ||||||
|  |     openim::log::info "Starting OpenIM Tools..." | ||||||
|  |     for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do | ||||||
|  |         openim::log::info "Starting ${tool}..." | ||||||
|  |         # openim::tools::start_service ${tool} | ||||||
|  |         sleep 0.2 | ||||||
|  |     done | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | 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}..." | ||||||
|  |         openim::tools::start_service ${tool} ${OPNEIM_CONFIG} | ||||||
|  |         sleep 0.2 | ||||||
|  |     done | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function openim::tools::post-start() { | ||||||
|  |     openim::log::info "Post-start actions for OpenIM Tools..." | ||||||
|  |     for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do | ||||||
|  |         openim::log::info "Starting ${tool}..." | ||||||
|  |         # openim::tools::start_service ${tool} | ||||||
|  |         sleep 0.2 | ||||||
|  |     done | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function openim::tools::stop() { | ||||||
|  |     openim::log::info "Stopping OpenIM Tools..." | ||||||
|  |     for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do | ||||||
|  |         openim::log::info "Stopping ${tool}..." | ||||||
|  |         # Similarly, place the actual command to stop the tool here. | ||||||
|  |         echo "Stopping service for ${tool}" | ||||||
|  |         sleep 0.2 | ||||||
|  |     done | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function openim::tools::pre-stop() { | ||||||
|  |     openim::log::info "Preparing to stop OpenIM Tools..." | ||||||
|  |     for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do | ||||||
|  |         openim::log::info "Setting up pre-stop for ${tool}..." | ||||||
|  |         echo "Pre-stop actions for ${tool}" | ||||||
|  |         sleep 0.2 | ||||||
|  |     done | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | function openim::tools::post-stop() { | ||||||
|  |     openim::log::info "Post-stop actions for OpenIM Tools..." | ||||||
|  |     for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do | ||||||
|  |         openim::log::info "Executing post-stop for ${tool}..." | ||||||
|  |         echo "Post-stop cleanup for ${tool}" | ||||||
|  |         sleep 0.2 | ||||||
|  |     done | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | if [[ "$*" =~ openim::tools:: ]];then | ||||||
|  |   eval $* | ||||||
|  | fi | ||||||
| @ -98,6 +98,7 @@ openim::golang::start_script_list() { | |||||||
|       openim-msgtransfer.sh |       openim-msgtransfer.sh | ||||||
|       openim-msggateway.sh |       openim-msggateway.sh | ||||||
|       openim-crontask.sh |       openim-crontask.sh | ||||||
|  |       openim-tools.sh | ||||||
|   ) |   ) | ||||||
|   local result=() |   local result=() | ||||||
|   for target in "${targets[@]}"; do |   for target in "${targets[@]}"; do | ||||||
|  | |||||||
| @ -51,6 +51,7 @@ export no_proxy="127.0.0.1,localhost${no_proxy:+,${no_proxy}}" | |||||||
| 
 | 
 | ||||||
| # This is a symlink to binaries for "this platform", e.g. build tools. | # This is a symlink to binaries for "this platform", e.g. build tools. | ||||||
| export THIS_PLATFORM_BIN="${OPENIM_ROOT}/_output/bin/platforms" | export THIS_PLATFORM_BIN="${OPENIM_ROOT}/_output/bin/platforms" | ||||||
|  | export THIS_PLATFORM_BIN_TOOLS="${OPENIM_ROOT}/_output/bin/tools" | ||||||
| 
 | 
 | ||||||
| . $(dirname ${BASH_SOURCE})/color.sh | . $(dirname ${BASH_SOURCE})/color.sh | ||||||
| . $(dirname ${BASH_SOURCE})/util.sh | . $(dirname ${BASH_SOURCE})/util.sh | ||||||
| @ -66,6 +67,8 @@ openim::util::ensure-bash-version | |||||||
| 
 | 
 | ||||||
| OPENIM_OUTPUT_HOSTBIN="${OPENIM_OUTPUT_BINPATH}/$(openim::util::host_platform)" | OPENIM_OUTPUT_HOSTBIN="${OPENIM_OUTPUT_BINPATH}/$(openim::util::host_platform)" | ||||||
| export OPENIM_OUTPUT_HOSTBIN | export OPENIM_OUTPUT_HOSTBIN | ||||||
|  | OPENIM_OUTPUT_HOSTBIN_TOOLS="${OPENIM_OUTPUT_BINTOOLPATH}/$(openim::util::host_platform)" | ||||||
|  | export OPENIM_OUTPUT_HOSTBIN_TOOLS | ||||||
| 
 | 
 | ||||||
| export OPENIM_NONSERVER_GROUP_VERSIONS | export OPENIM_NONSERVER_GROUP_VERSIONS | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -147,8 +147,8 @@ go.build.%: | |||||||
| 			$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/$(COMMAND)/main.go; \
 | 			$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/$(COMMAND)/main.go; \
 | ||||||
| 		elif [ -f $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go ]; then \
 | 		elif [ -f $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go ]; then \
 | ||||||
| 			CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
 | 			CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
 | ||||||
| 			$(BIN_TOOLS_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go; \
 | 			$(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/tools/$(COMMAND)/$(COMMAND).go; \
 | ||||||
| 			chmod +x $(BIN_TOOLS_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT); \
 | 			chmod +x $(BIN_TOOLS_DIR)/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT); \
 | ||||||
| 		fi \
 | 		fi \
 | ||||||
| 	fi | 	fi | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -65,4 +65,10 @@ function execute_scripts() { | |||||||
|     done |     done | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | # TODO Prelaunch tools, simple for now, can abstract functions later | ||||||
|  | TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh | ||||||
|  | ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start | ||||||
|  | 
 | ||||||
| execute_scripts | execute_scripts | ||||||
|  | 
 | ||||||
|  | ${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start | ||||||
							
								
								
									
										0
									
								
								scripts/update-generated-docs.sh
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							
							
						
						
									
										0
									
								
								scripts/update-generated-docs.sh
									
									
									
									
									
										
										
										Normal file → Executable file
									
								
							| @ -12,26 +12,6 @@ As openim is using go1.18's [workspace feature](https://go.dev/doc/tutorial/work | |||||||
| You can execute the following commands to do things above: | You can execute the following commands to do things above: | ||||||
| 
 | 
 | ||||||
| ```bash | ```bash | ||||||
| # 4dd91a700d3f:/openim# tree |  | ||||||
| # . |  | ||||||
| # ├── LICENSE |  | ||||||
| # ├── README.md |  | ||||||
| # ├── openim-chat |  | ||||||
| # │   ├── bin |  | ||||||
| # │   ├── config |  | ||||||
| # │   ├── logs |  | ||||||
| # │   └── scripts |  | ||||||
| # ├── openim-server |  | ||||||
| # │   ├── bin |  | ||||||
| # │   ├── config |  | ||||||
| # │   ├── logs |  | ||||||
| # │   └── scripts |  | ||||||
| # ├── openkf |  | ||||||
| # │   ├── bin |  | ||||||
| # │   ├── config |  | ||||||
| # │   ├── logs |  | ||||||
| # │   └── scripts |  | ||||||
| # cd tools_code_dir |  | ||||||
| # edit the CRD_NAME and CRD_GROUP to your own | # edit the CRD_NAME and CRD_GROUP to your own | ||||||
| export OPENIM_TOOLS_NAME=<Changeme> | export OPENIM_TOOLS_NAME=<Changeme> | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ package main | |||||||
| import ( | import ( | ||||||
| 	"context" | 	"context" | ||||||
| 	"database/sql" | 	"database/sql" | ||||||
|  | 	"flag" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"net" | 	"net" | ||||||
| 	"net/url" | 	"net/url" | ||||||
| @ -29,7 +30,8 @@ import ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| const ( | const ( | ||||||
| 	cfgPath                  = "../../../../../config/config.yaml" | 	// defaultCfgPath is the default path of the configuration file | ||||||
|  | 	defaultCfgPath           = "../../../../../config/config.yaml" | ||||||
| 	minioHealthCheckDuration = 1 | 	minioHealthCheckDuration = 1 | ||||||
| 	maxRetry                 = 100 | 	maxRetry                 = 100 | ||||||
| 	componentStartErrCode    = 6000 | 	componentStartErrCode    = 6000 | ||||||
| @ -37,84 +39,64 @@ const ( | |||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| var ( | var ( | ||||||
|  | 	cfgPath = flag.String("c", defaultCfgPath, "Path to the configuration file") | ||||||
|  | 
 | ||||||
| 	ErrComponentStart = errs.NewCodeError(componentStartErrCode, "ComponentStartErr") | 	ErrComponentStart = errs.NewCodeError(componentStartErrCode, "ComponentStartErr") | ||||||
| 	ErrConfig         = errs.NewCodeError(configErrCode, "Config file is incorrect") | 	ErrConfig         = errs.NewCodeError(configErrCode, "Config file is incorrect") | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func initCfg() error { | func initCfg() error { | ||||||
| 	data, err := os.ReadFile(cfgPath) | 	data, err := os.ReadFile(*cfgPath) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| 	if err = yaml.Unmarshal(data, &config.Config); err != nil { | 	return yaml.Unmarshal(data, &config.Config) | ||||||
| 		return err |  | ||||||
| } | } | ||||||
| 	return nil | 
 | ||||||
|  | type checkFunc struct { | ||||||
|  | 	name     string | ||||||
|  | 	function func() error | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func main() { | func main() { | ||||||
| 	err := initCfg() | 	flag.Parse() | ||||||
| 	if err != nil { | 
 | ||||||
| 		fmt.Printf("Read config failed: %v", err.Error()) | 	if err := initCfg(); err != nil { | ||||||
|  | 		fmt.Printf("Read config failed: %v\n", err) | ||||||
|  | 		return | ||||||
| 	} | 	} | ||||||
|  | 
 | ||||||
|  | 	checks := []checkFunc{ | ||||||
|  | 		{name: "Mysql", function: checkMysql}, | ||||||
|  | 		{name: "Mongo", function: checkMongo}, | ||||||
|  | 		{name: "Minio", function: checkMinio}, | ||||||
|  | 		{name: "Redis", function: checkRedis}, | ||||||
|  | 		{name: "Zookeeper", function: checkZookeeper}, | ||||||
|  | 		{name: "Kafka", function: checkKafka}, | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	for i := 0; i < maxRetry; i++ { | 	for i := 0; i < maxRetry; i++ { | ||||||
| 		if i != 0 { | 		if i != 0 { | ||||||
| 			time.Sleep(3 * time.Second) | 			time.Sleep(3 * time.Second) | ||||||
| 		} | 		} | ||||||
| 		fmt.Printf("Checking components Round %v......\n", i+1) | 		fmt.Printf("Checking components Round %v...\n", i+1) | ||||||
| 		// Check MySQL | 
 | ||||||
| 		if err := checkMysql(); err != nil { | 		allSuccess := true | ||||||
| 			errorPrint(fmt.Sprintf("Starting Mysql failed: %v. Please make sure your mysql service has started", err.Error())) | 		for _, check := range checks { | ||||||
| 			continue | 			err := check.function() | ||||||
|  | 			if err != nil { | ||||||
|  | 				errorPrint(fmt.Sprintf("Starting %s failed: %v", check.name, err)) | ||||||
|  | 				allSuccess = false | ||||||
|  | 				break | ||||||
| 			} else { | 			} else { | ||||||
| 			successPrint(fmt.Sprint("Mysql starts successfully")) | 				successPrint(fmt.Sprintf("%s starts successfully", check.name)) | ||||||
|  | 			} | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// Check MongoDB | 		if allSuccess { | ||||||
| 		if err := checkMongo(); err != nil { | 			successPrint("All components started successfully!") | ||||||
| 			errorPrint(fmt.Sprintf("Starting Mongo failed: %v. Please make sure your monngo service has started", err.Error())) | 			return | ||||||
| 			continue |  | ||||||
| 		} else { |  | ||||||
| 			successPrint(fmt.Sprint("Mongo starts successfully")) |  | ||||||
| 		} | 		} | ||||||
| 
 |  | ||||||
| 		// Check Minio |  | ||||||
| 		if err := checkMinio(); err != nil { |  | ||||||
| 			if index := strings.Index(err.Error(), utils.IntToString(configErrCode)); index != -1 { |  | ||||||
| 				successPrint(fmt.Sprint("Minio starts successfully")) |  | ||||||
| 				warningPrint(fmt.Sprintf("%v. Please modify your config file", err.Error())) |  | ||||||
| 			} else { |  | ||||||
| 				errorPrint(fmt.Sprintf("Starting Minio failed: %v. Please make sure your Minio service has started", err.Error())) |  | ||||||
| 				continue |  | ||||||
| 			} |  | ||||||
| 		} else { |  | ||||||
| 			successPrint(fmt.Sprint("Minio starts successfully")) |  | ||||||
| 		} |  | ||||||
| 		// Check Redis |  | ||||||
| 		if err := checkRedis(); err != nil { |  | ||||||
| 			errorPrint(fmt.Sprintf("Starting Redis failed: %v.Please make sure your Redis service has started", err.Error())) |  | ||||||
| 			continue |  | ||||||
| 		} else { |  | ||||||
| 			successPrint(fmt.Sprint("Redis starts successfully")) |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		// Check Zookeeper |  | ||||||
| 		if err := checkZookeeper(); err != nil { |  | ||||||
| 			errorPrint(fmt.Sprintf("Starting Zookeeper failed: %v.Please make sure your Zookeeper service has started", err.Error())) |  | ||||||
| 			continue |  | ||||||
| 		} else { |  | ||||||
| 			successPrint(fmt.Sprint("Zookeeper starts successfully")) |  | ||||||
| 		} |  | ||||||
| 
 |  | ||||||
| 		// Check Kafka |  | ||||||
| 		if err := checkKafka(); err != nil { |  | ||||||
| 			errorPrint(fmt.Sprintf("Starting Kafka failed: %v.Please make sure your Kafka service has started", err.Error())) |  | ||||||
| 			continue |  | ||||||
| 		} else { |  | ||||||
| 			successPrint(fmt.Sprint("Kafka starts successfully")) |  | ||||||
| 		} |  | ||||||
| 		successPrint(fmt.Sprint("All components starts successfully")) |  | ||||||
| 		os.Exit(0) |  | ||||||
| 	} | 	} | ||||||
| 	os.Exit(1) | 	os.Exit(1) | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user