diff --git a/deployments/templates/openim.yaml b/deployments/templates/openim.yaml index 0f2d9952e..b71207ebf 100644 --- a/deployments/templates/openim.yaml +++ b/deployments/templates/openim.yaml @@ -28,7 +28,7 @@ # Zookeeper password zookeeper: schema: ${ZOOKEEPER_SCHEMA} - address: [ ${ZOOKEEPER_ADDRESS} ] + address: [ ${ZOOKEEPER_ADDRESS}:${ZOOKEEPER_PORT} ] username: ${ZOOKEEPER_USERNAME} password: ${ZOOKEEPER_PASSWORD} @@ -42,7 +42,7 @@ zookeeper: # Log level: 1=slient, 2=error, 3=warn, 4=info # Slow query threshold in milliseconds mysql: - address: [ ${MYSQL_ADDRESS} ] + address: [ ${MYSQL_ADDRESS}:${MYSQL_PORT} ] username: ${MYSQL_USERNAME} password: ${MYSQL_PASSWORD} database: ${MYSQL_DATABASE} @@ -61,7 +61,7 @@ mysql: # Maximum connection pool size mongo: uri: ${MONGO_URI} - address: [ ${MONGO_ADDRESS} ] + address: [ ${MONGO_ADDRESS}:${MONGO_PORT} ] database: ${MONGO_DATABASE} username: ${MONGO_USERNAME} password: ${MONGO_PASSWORD} @@ -72,7 +72,7 @@ mongo: # # Username is required only for Redis version 6.0+ redis: - address: [ ${REDIS_ADDRESS} ] + address: [ ${REDIS_ADDRESS}:${REDIS_PORT} ] username: ${REDIS_USERNAME} password: ${REDIS_PASSWORD} @@ -86,7 +86,7 @@ redis: kafka: username: ${KAFKA_USERNAME} password: ${KAFKA_PASSWORD} - addr: [ ${KAFKA_ADDR} ] + addr: [ ${KAFKA_ADDR}:${KAFKA_PORT} ] latestMsgToRedis: topic: ${KAFKA_LATESTMSG_REDIS_TOPIC} offlineMsgToMongo: diff --git a/scripts/batch_start_all.sh b/scripts/batch_start_all.sh index 4c3d14832..5836144aa 100755 --- a/scripts/batch_start_all.sh +++ b/scripts/batch_start_all.sh @@ -26,6 +26,7 @@ source "${OPENIM_ROOT}/scripts/lib/init.sh" trap 'openim::util::onCtrlC' INT need_to_start_server_shell=( + "oepnim-api.sh" "openim-rpc.sh" "openim-msggateway.sh" "openim-push.sh" diff --git a/scripts/check_all.sh b/scripts/check_all.sh index 14cac1106..7a861a7ea 100755 --- a/scripts/check_all.sh +++ b/scripts/check_all.sh @@ -17,6 +17,7 @@ # # Usage: `scripts/check_all.sh`. # Encapsulated as: `make check`. +# READ: https://github.com/OpenIMSDK/Open-IM-Server/tree/main/scripts/install/environment.sh set -o errexit set -o nounset @@ -27,6 +28,19 @@ source "${OPENIM_ROOT}/scripts/install/common.sh" OPENIM_VERBOSE=4 -echo "The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}" +echo "++++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}" -openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]} +echo "++++ Check all dependent service ports" +echo "+ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}" +openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]} + +if [[ $? -ne 0 ]]; then + openim::log::error_exit "The service does not start properly, please check the port, query variable definition!" + echo "+++ https://github.com/OpenIMSDK/Open-IM-Server/tree/main/scripts/install/environment.sh +++" +else + echo "++++ Check all dependent service ports successfully !" +fi + +echo "++++ Check all OpenIM service ports" +echo "+ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}" +openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]} \ No newline at end of file diff --git a/scripts/init_config.sh b/scripts/init_config.sh deleted file mode 100755 index f5945d50c..000000000 --- a/scripts/init_config.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/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. - -# This script automatically initializes the various configuration files -# Read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/init_config.md - -set -o errexit -set -o nounset -set -o pipefail - -OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. - -source "${OPENIM_ROOT}/scripts/lib/init.sh" - -# 定义一个配置文件数组,其中包含需要生成的配置文件的名称路径 (en: Define a profile array that contains the name path of the profile to be generated.) -readonly ENV_FILE=${ENV_FILE:-${OPENIM_ROOT}/scripts/install/environment.sh} - -# 定义关联数组,其中键是模板文件,值是对应的输出文件 (en: Defines an associative array where the keys are the template files and the values are the corresponding output files.) -declare -A TEMPLATES=( - ["${OPENIM_ROOT}/deployments/templates/env_template.yaml"]="${OPENIM_OUTPUT_SUBPATH}/bin/.env" - ["${OPENIM_ROOT}/deployments/templates/openim.yaml"]="${OPENIM_OUTPUT_SUBPATH}/bin/openim_config.yaml" -) - -for template in "${!TEMPLATES[@]}"; do - output_file=${TEMPLATES[$template]} - - if [[ ! -f "${template}" ]]; then - openim::log::error_exit "template file ${template} does not exist..." - fi - - openim::log::info "Working with template file: ${template} to ${output_file}..." - "${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${output_file}" || { - openim::log::error "Error processing template file ${template}" - exit 1 - } -done - -openim::log::success "All configuration files have been successfully generated!" \ No newline at end of file diff --git a/scripts/install/common.sh b/scripts/install/common.sh index 5b067b521..7aeff653c 100755 --- a/scripts/install/common.sh +++ b/scripts/install/common.sh @@ -75,6 +75,28 @@ IFS=" " read -ra OPENIM_SERVER_PORT_TARGETS <<< "$(openim::common::service_port) readonly OPENIM_SERVER_PORT_TARGETS readonly OPENIM_SERVER_PORT_LISTARIES=("${OPENIM_SERVER_PORT_TARGETS[@]##*/}") +# This function returns a list of ports for various services +# - zookeeper +# - kafka +# - mysql +# - mongodb +# - redis +# - minio +openim::common::dependency_port() { + local targets=( + ${MYSQL_PORT} # MySQL port + ${REDIS_PORT} # Redis port + ${ZOOKEEPER_PORT} # Zookeeper port + ${KAFKA_PORT} # Kafka port + ${MongoDB_PORT} # MongoDB port + ${MINIO_PORT} # MinIO port + ) + echo "${targets[@]}" +} +IFS=" " read -ra OPENIM_DEPENDENCY_PORT_TARGETS <<< "$(openim::common::dependency_port)" +readonly OPENIM_DEPENDENCY_PORT_TARGETS +readonly OPENIM_DEPENDENCY_PORT_LISTARIES=("${OPENIM_DEPENDENCY_PORT_TARGETS[@]##*/}") + # Execute commands that require root permission without entering a password function openim::common::sudo { echo ${LINUX_PASSWORD} | sudo -S $1 diff --git a/scripts/install/environment.sh b/scripts/install/environment.sh index 0bde5acd8..a4bdd8e40 100755 --- a/scripts/install/environment.sh +++ b/scripts/install/environment.sh @@ -22,7 +22,7 @@ OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)" # 生成文件存放目录 LOCAL_OUTPUT_ROOT="${OPENIM_ROOT}/${OUT_DIR:-_output}" -source "${OPENIM_ROOT}/scripts/lib/util.sh" +source "${OPENIM_ROOT}/scripts/lib/init.sh" IP=$(openim::util::get_server_ip) @@ -70,12 +70,14 @@ def "OPNEIM_CONFIG" "${OPENIM_ROOT}/config" ###################### Zookeeper 配置信息 ###################### def "ZOOKEEPER_SCHEMA" "openim" # Zookeeper的模式 -def "ZOOKEEPER_ADDRESS" "127.0.0.1:2181" # Zookeeper的地址 +def "ZOOKEEPER_PORT" "2181" # Zookeeper的端口 +def "ZOOKEEPER_ADDRESS" "127.0.0.1" # Zookeeper的地址 def "ZOOKEEPER_USERNAME" "" # Zookeeper的用户名 def "ZOOKEEPER_PASSWORD" "" # Zookeeper的密码 ###################### MySQL 配置信息 ###################### -def "MYSQL_ADDRESS" "127.0.0.1:13306" # MySQL的地址 +def "MYSQL_PORT" "13306" # MySQL的端口 +def "MYSQL_ADDRESS" "127.0.0.1" # MySQL的地址 def "MYSQL_USERNAME" "${USER}" # MySQL的用户名 def "MYSQL_PASSWORD" "${PASSWORD}" # MySQL的密码 def "MYSQL_DATABASE" "${DATABASE_NAME}" # MySQL的数据库名 @@ -87,7 +89,8 @@ def "MYSQL_SLOW_THRESHOLD" "500" # 慢 ###################### MongoDB 配置信息 ###################### def "MONGO_URI" # MongoDB的URI -def "MONGO_ADDRESS" "127.0.0.1:37017" # MongoDB的地址 +def "MONGO_PORT" "37017" # MongoDB的端口 +def "MONGO_ADDRESS" "127.0.0.1" # MongoDB的地址 def "MONGO_DATABASE" "${DATABASE_NAME}" # MongoDB的数据库名 def "MONGO_USERNAME" "${USER}" # MongoDB的用户名 def "MONGO_PASSWORD" "${PASSWORD}" # MongoDB的密码 @@ -97,7 +100,9 @@ def "MONGO_MAX_POOL_SIZE" "100" # 最 def "OBJECT_ENABLE" "minio" # 对象是否启用 def "OBJECT_APIURL" "http://127.0.0.1:10002/object/" # 对象的API地址 def "MINIO_BUCKET" "openim" # MinIO的存储桶名称 -def "MINIO_ENDPOINT" "http://${IP}:10005" # MinIO的端点URL +def "MINIO_PORT" "10005" # MinIO的端口 +# MinIO的端点URL +readonly MINIO_ENDPOINT=${MINIO_ENDPOINT:-"http://${IP}:${MINIO_PORT}"} def "MINIO_ACCESS_KEY" "${USER}" # MinIO的访问密钥ID def "MINIO_SECRET_KEY" "${PASSWORD}" # MinIO的密钥 def "MINIO_SESSION_TOKEN" # MinIO的会话令牌 @@ -113,14 +118,16 @@ def "OSS_ACCESS_KEY_SECRET" # 阿 def "OSS_SESSION_TOKEN" # 阿里云OSS的会话令牌 ###################### Redis 配置信息 ###################### -def "REDIS_ADDRESS" "127.0.0.1:16379" # Redis的地址 +def "REDIS_PORT" "16379" # Redis的端口 +def "REDIS_ADDRESS" "127.0.0.1" # Redis的地址 def "REDIS_USERNAME" # Redis的用户名 def "REDIS_PASSWORD" "${PASSWORD}" # Redis的密码 ###################### Kafka 配置信息 ###################### def "KAFKA_USERNAME" # Kafka的用户名 def "KAFKA_PASSWORD" # Kafka的密码 -def "KAFKA_ADDR" "127.0.0.1:9092" # Kafka的地址 +def "KAFKA_PORT" "9092" # Kafka的端口 +def "KAFKA_ADDR" "127.0.0.1" # Kafka的地址 def "KAFKA_LATESTMSG_REDIS_TOPIC" "latestMsgToRedis" # Kafka的最新消息到Redis的主题 def "KAFKA_OFFLINEMSG_MONGO_TOPIC" "offlineMsgToMongoMysql" # Kafka的离线消息到Mongo的主题 def "KAFKA_MSG_PUSH_TOPIC" "msgToPush" # Kafka的消息到推送的主题 diff --git a/scripts/lib/util.sh b/scripts/lib/util.sh index 1954396c0..12417e991 100755 --- a/scripts/lib/util.sh +++ b/scripts/lib/util.sh @@ -282,10 +282,10 @@ openim::util::check_ports() { started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time") fi done - + echo # Print information about ports whose processes are not running. if [[ ${#not_started[@]} -ne 0 ]]; then - openim::log::info "Not started ports:" + openim::log::info "### Not started ports:" for port in "${not_started[@]}"; do openim::log::error "Port $port is not started." done @@ -294,7 +294,7 @@ openim::util::check_ports() { # Print information about ports whose processes are running. if [[ ${#started[@]} -ne 0 ]]; then echo - openim::log::info "Started ports:" + openim::log::info "### Started ports:" for info in "${started[@]}"; do openim::log::info "$info" done @@ -304,7 +304,7 @@ openim::util::check_ports() { if [[ ${#not_started[@]} -ne 0 ]]; then return 1 else - openim::log::success "All processes are running." + openim::log::success "started[@] processes are running." return 0 fi } @@ -1196,7 +1196,7 @@ function openim::util::get_server_ip() { # Check if the 'curl' command is available if command -v curl &> /dev/null; then # Try to retrieve the public IP address using curl and ifconfig.me - IP=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com) + IP=$(dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/"//g' | tr -d '\n') # Check if IP retrieval was successful if [[ -z "$IP" ]]; then