feat: add start sctips help

Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
pull/825/head
Xinwei Xiong(cubxxw-openim) 2 years ago
parent 0dcdcbed4b
commit f4c464003c
No known key found for this signature in database
GPG Key ID: 1BAD6F395338EFDE

@ -23,60 +23,10 @@ set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
source "${OPENIM_ROOT}/scripts/path_info.sh"
source "${OPENIM_ROOT}/scripts/install/common.sh"
OPENIM_VERBOSE=4
service_port_name=(
openImWsPort
openImApiPort
openImUserPort
openImFriendPort
openImMessagePort
openImMessageGatewayPort
openImGroupPort
openImAuthPort
openImPushPort
openImConversationPort
openImThirdPort
)
for i in ${service_port_name[*]}; do
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
openim::util::list-to-string $list
for j in ${ports_array}; do
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
if [[ ${port} -ne ${j} ]]; then
openim::log::info "service does not start normally,not initiated port is "${COLOR_SUFFIX}${BACKGROUND_GREEN}${j}
echo "please check ${log_file}"
exit -1
else
echo -e ${j}${GREEN_PREFIX}" port has been listening,belongs service is "${i}${COLOR_SUFFIX}
fi
done
done
#Check launched service process
check=$(ps aux | grep -w ./${openim_msgtransfer} | grep -v grep | wc -l)
if [ $check -eq ${msg_transfer_service_num} ]; then
echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImMsgTransfer"${COLOR_SUFFIX}
else
echo $check ${msg_transfer_service_num}
echo -e ${RED_PREFIX}"openImMsgTransfer service does not start normally, num err"${COLOR_SUFFIX}
echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log "${COLOR_SUFFIX}
exit -1
fi
check=$(ps aux | grep -w ./${cron_task_name} | grep -v grep | wc -l)
if [ $check -ge 1 ]; then
echo -e ${GREEN_PREFIX}"none port has been listening,belongs service is openImCronTask"${COLOR_SUFFIX}
else
echo -e ${RED_PREFIX}"cron_task_name service does not start normally"${COLOR_SUFFIX}
echo -e ${RED_PREFIX}"please check $OPENIM_ROOT/logs/openIM.log "${COLOR_SUFFIX}
exit -1
fi
echo "The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
echo -e ${BACKGROUND_GREEN}"all services launch success"${COLOR_SUFFIX}
openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}

@ -30,10 +30,29 @@ source "${OPENIM_ROOT}/scripts/lib/init.sh"
# Make sure the environment is only called via common to avoid too much nesting
source "${OPENIM_ROOT}/scripts/install/environment.sh"
service_port_name={
# Storing all the defined ports in an array for easy management and access.
# This array consolidates the port numbers for all the services defined above.
openim::common::service_port_name() {
local targets=(
$OPENIM_USER_PORT # User service
$OPENIM_FRIEND_PORT # Friend service
$OPENIM_MESSAGE_PORT # Message service
$OPENIM_MESSAGE_GATEWAY_PORT # Message gateway
$OPENIM_GROUP_PORT # Group service
$OPENIM_AUTH_PORT # Authorization service
$OPENIM_PUSH_PORT # Push service
$OPENIM_CONVERSATION_PORT # Conversation service
$OPENIM_THIRD_PORT # Third-party service
$API_OPENIM_PORT # API service
$OPENIM_WS_PORT # WebSocket service
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_SERVER_PORT_TARGETS <<< "$(openim::common::service_port_name)"
readonly OPENIM_SERVER_PORT_TARGETS
readonly OPENIM_SERVER_PORT_LISTARIES=("${OPENIM_SERVER_PORT_TARGETS[@]##*/}")
# Execute commands that require root permission without entering a password
function openim::common::sudo {
echo ${LINUX_PASSWORD} | sudo -S $1

@ -15,8 +15,11 @@
# This script will install the dependencies required for openim
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
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
# Start MySQL service

@ -16,6 +16,7 @@
# This is a file that initializes variables for the automation script that initializes the config file
# You need to supplement the script according to the specification.
# Read: https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/contrib/init_config.md
# 格式化 bash 注释https://tool.lu/shell/
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
@ -210,7 +211,68 @@ def "THIRD_PROM_PORT" "21301" # Third 服务的 Prometheus 端
# Message Transfer 服务的 Prometheus 端口列表
readonly MSG_TRANSFER_PROM_PORTS=${MSG_TRANSFER_PROM_PORTS:-'21400, 21401, 21402, 21403'}
###################### OpenIM openim-api ######################
def "OPENIM_API_BINARY" "${LOCAL_OUTPUT_ROOT}/bin/platforms/linux/amd64/openim-api" # OpenIM openim-api 二进制文件路径
def "OPENIM_API_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-api 配置文件路径
def "OPENIM_API_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-api" # OpenIM openim-api 日志存储路径
def "OPENIM_API_LOG_LEVEL" "info" # OpenIM openim-api 日志级别
def "OPENIM_API_LOG_MAX_SIZE" "100" # OpenIM openim-api 日志最大大小MB
def "OPENIM_API_LOG_MAX_BACKUPS" "7" # OpenIM openim-api 日志最大备份数
def "OPENIM_API_LOG_MAX_AGE" "7" # OpenIM openim-api 日志最大保存时间(天)
def "OPENIM_API_LOG_COMPRESS" "false" # OpenIM openim-api 日志是否压缩
def "OPENIM_API_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-api 日志是否带有堆栈信息
###################### OpenIM openim-cmdutils ######################
def "OPENIM_CMDUTILS_BINARY" "${LOCAL_OUTPUT_ROOT}/bin/platforms/linux/amd64/openim-cmdutils" # OpenIM openim-cmdutils 二进制文件路径
def "OPENIM_CMDUTILS_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-cmdutils 配置文件路径
def "OPENIM_CMDUTILS_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-cmdutils" # OpenIM openim-cmdutils 日志存储路径
def "OPENIM_CMDUTILS_LOG_LEVEL" "info" # OpenIM openim-cmdutils 日志级别
def "OPENIM_CMDUTILS_LOG_MAX_SIZE" "100" # OpenIM openim-cmdutils 日志最大大小MB
def "OPENIM_CMDUTILS_LOG_MAX_BACKUPS" "7" # OpenIM openim-cmdutils 日志最大备份数
def "OPENIM_CMDUTILS_LOG_MAX_AGE" "7" # OpenIM openim-cmdutils 日志最大保存时间(天)
def "OPENIM_CMDUTILS_LOG_COMPRESS" "false" # OpenIM openim-cmdutils 日志是否压缩
def "OPENIM_CMDUTILS_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-cmdutils 日志是否带有堆栈信息
###################### OpenIM openim-crontask ######################
def "OPENIM_CRONTASK_BINARY" "${LOCAL_OUTPUT_ROOT}/bin/platforms/linux/amd64/openim-crontask" # OpenIM openim-crontask 二进制文件路径
def "OPENIM_CRONTASK_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-crontask 配置文件路径
def "OPENIM_CRONTASK_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-crontask" # OpenIM openim-crontask 日志存储路径
def "OPENIM_CRONTASK_LOG_LEVEL" "info" # OpenIM openim-crontask 日志级别
def "OPENIM_CRONTASK_LOG_MAX_SIZE" "100" # OpenIM openim-crontask 日志最大大小MB
def "OPENIM_CRONTASK_LOG_MAX_BACKUPS" "7" # OpenIM openim-crontask 日志最大备份数
def "OPENIM_CRONTASK_LOG_MAX_AGE" "7" # OpenIM openim-crontask 日志最大保存时间(天)
def "OPENIM_CRONTASK_LOG_COMPRESS" "false" # OpenIM openim-crontask 日志是否压缩
def "OPENIM_CRONTASK_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-crontask 日志是否带有堆栈信息
###################### OpenIM openim-msggateway ######################
# 和上述相似,仅替换 openim-crontask 为 openim-msggateway
###################### OpenIM openim-msgtransfer ######################
# 和上述相似,仅替换 openim-crontask 为 openim-msgtransfer
###################### OpenIM openim-push ######################
# 和上述相似,仅替换 openim-crontask 为 openim-push
###################### OpenIM openim-rpc-auth ######################
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-auth
###################### OpenIM openim-rpc-conversation ######################
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-conversation
###################### OpenIM openim-rpc-friend ######################
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-friend
###################### OpenIM openim-rpc-group ######################
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-group
###################### OpenIM openim-rpc-msg ######################
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-msg
###################### OpenIM openim-rpc-third ######################
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-third
###################### OpenIM openim-rpc-user ######################
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-user
###################### 设计中...暂时不需要######################################
# openim 配置

@ -13,19 +13,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
# Common utilities, variables and checks for all build scripts.
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
#Include shell font styles and some basic information
source $SCRIPTS_ROOT/lib/init.sh
source $SCRIPTS_ROOT/path_info.sh
cd $SCRIPTS_ROOT
bin_dir="$BIN_DIR"
logs_dir="$OPENIM_ROOT/logs"
ulimit -n 200000
list1=$(cat $config_path | grep openImMessageGatewayPort | awk -F '[:]' '{print $NF}')
@ -58,7 +58,7 @@ for ((i = 0; i < ${#ws_ports[@]}; i++)); do
nohup ./${openim_msggateway} --port ${rpc_ports[$i]} --ws_port ${ws_ports[$i]} --prometheus_port ${prome_ports[$i]} --config_folder_path ${configfile_path} >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
done
#Check launched service process
# Check launched service process
sleep 3
check=$(ps aux | grep -w ./${openim_msggateway} | grep -v grep | wc -l)
allPorts=""

@ -13,9 +13,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
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
#Include shell font styles and some basic information
source $SCRIPTS_ROOT/lib/init.sh

@ -15,9 +15,12 @@
# Common utilities, variables and checks for all build scripts.
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
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
#Include shell font styles and some basic information
source $SCRIPTS_ROOT/lib/init.sh

@ -14,37 +14,25 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
set -o errexit
set +o nounset
set -o pipefail
#Include shell font styles and some basic information
source $SCRIPTS_ROOT/lib/init.sh
source $SCRIPTS_ROOT/path_info.sh
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
cd $SCRIPTS_ROOT
readonly SERVER_NAME="openim-crontask"
readonly SERVER_PATH="${OPENIM_OUTPUT_HOSTBIN}/openim-crontask"
echo -e "${YELLOW_PREFIX}=======>SCRIPTS_ROOT=$SCRIPTS_ROOT${COLOR_SUFFIX}"
echo -e "${YELLOW_PREFIX}=======>OPENIM_ROOT=$OPENIM_ROOT${COLOR_SUFFIX}"
echo -e "${YELLOW_PREFIX}=======>pwd=$PWD${COLOR_SUFFIX}"
openim::log::status "Start OpenIM Cron, binary root: ${SERVER_NAME}"
openim::log::info "Start OpenIM Cron, path: ${SERVER_PATH}"
bin_dir="$BIN_DIR"
logs_dir="$OPENIM_ROOT/logs"
openim::util::stop_services_with_name ${SERVER_NAME}
#Check if the service exists
#If it is exists,kill this process
check=`ps | grep -w ./${cron_task_name} | grep -v grep| wc -l`
if [ $check -ge 1 ]
then
oldPid=`ps | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'`
kill -9 $oldPid
fi
#Waiting port recycling
sleep 1
cd ${cron_task_binary_root}
#for ((i = 0; i < ${cron_task_service_num}; i++)); do
echo "==========================start cron_task process===========================">>$OPENIM_ROOT/logs/openIM.log
openim::log::status "start cron_task process"
nohup ./${cron_task_name} >>$OPENIM_ROOT/logs/openIM.log 2>&1 &
#done

@ -14,12 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#Include shell font styles and some basic information
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
# Common utilities, variables and checks for all build scripts.
set -o errexit
set +o nounset
set -o pipefail
#Include shell font styles and some basic information
source $SCRIPTS_ROOT/lib/init.sh
source $SCRIPTS_ROOT/path_info.sh
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
#service filename
service_filename=(

@ -90,6 +90,7 @@ IFS=" " read -ra OPENIM_SERVER_TARGETS <<< "$(openim::golang::server_targets)"
readonly OPENIM_SERVER_TARGETS
readonly OPENIM_SERVER_BINARIES=("${OPENIM_SERVER_TARGETS[@]##*/}")
# TODO: Label
START_SCRIPTS_PATH="${OPENIM_ROOT}/scripts/install/"
openim::golang::start_script_list() {
local targets=(
@ -99,17 +100,21 @@ openim::golang::start_script_list() {
msg_gateway_start.sh
start_cron.sh
)
local result=()
for target in "${targets[@]}"; do
local full_path="${START_SCRIPTS_PATH}${target}"
echo "$full_path"
chmod +x "$full_path"
result+=("${START_SCRIPTS_PATH}${target}")
done
echo "${result[@]}"
}
# Populate the OPENIM_SERVER_SCRIPT_START_LIST with the full path names of the scripts.
IFS=" " read -ra OPENIM_SERVER_SCRIPT_START_LIST <<< "$(openim::golang::start_script_list)"
readonly OPENIM_SERVER_SCRIPT_START_LIST
# Extract just the script names from the full paths.
readonly OPENIM_SERVER_SCRIPTARIES=("${OPENIM_SERVER_SCRIPT_START_LIST[@]##*/}")
openim::golang::check_openim_binaries() {
local missing_binaries=()
for binary in "${OPENIM_SERVER_BINARIES[@]}"; do

@ -246,6 +246,182 @@ openim::util::host_arch() {
echo "${host_arch}"
}
# The `openim::util::check_ports` function analyzes the state of processes based on given ports.
# It accepts multiple ports as arguments and prints:
# 1. The state of the process (whether it's running or not).
# 2. The start time of the process if it's running.
# User:
# openim::util::check_ports 8080 8081 8082
# The function returns a status of 1 if any of the processes is not running.
openim::util::check_ports() {
# An array to collect ports of processes that are not running.
not_started=()
# An array to collect information about processes that are running.
started=()
# Iterate over each given port.
for port in "$@"; do
# Use the `lsof` command to find process information related to the given port.
info=$(lsof -i :$port -n -P | grep LISTEN || true)
# If there's no process information, it means the process associated with the port is not running.
if [[ -z $info ]]; then
not_started+=($port)
else
# If there's process information, extract relevant details:
# Process ID, Command Name, and Start Time.
pid=$(echo $info | awk '{print $2}')
command=$(echo $info | awk '{print $1}')
start_time=$(ps -o lstart= -p $pid)
started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time")
fi
done
# Print information about ports whose processes are not running.
if [[ ${#not_started[@]} -ne 0 ]]; then
openim::log::info "Not started ports:"
for port in "${not_started[@]}"; do
openim::log::error "Port $port is not started."
done
fi
# Print information about ports whose processes are running.
if [[ ${#started[@]} -ne 0 ]]; then
echo
openim::log::info "Started ports:"
for info in "${started[@]}"; do
openim::log::info "$info"
done
fi
# If any of the processes is not running, return a status of 1.
if [[ ${#not_started[@]} -ne 0 ]]; then
return 1
else
openim::log::success "All processes are running."
return 0
fi
}
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
# It accepts multiple ports as arguments and performs the following:
# 1. Attempts to stop any services running on the specified ports.
# 2. Prints details of services successfully stopped and those that failed to stop.
# Usage:
# openim::util::stop_services_on_ports 8080 8081 8082
# The function returns a status of 1 if any service couldn't be stopped.
openim::util::stop_services_on_ports() {
# An array to collect ports of processes that couldn't be stopped.
not_stopped=()
# An array to collect information about processes that were stopped.
stopped=()
# Iterate over each given port.
for port in "$@"; do
# Use the `lsof` command to find process information related to the given port.
info=$(lsof -i :$port -n -P | grep LISTEN || true)
# If there's process information, it means the process associated with the port is running.
if [[ -n $info ]]; then
# Extract the Process ID.
pid=$(echo $info | awk '{print $2}')
# Try to stop the service by killing its process.
if kill -TERM $pid; then
stopped+=($port)
else
not_stopped+=($port)
fi
fi
done
# Print information about ports whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Ports that couldn't be stopped:"
for port in "${not_stopped[@]}"; do
openim::log::error "Failed to stop service on port $port."
done
fi
# Print information about ports whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services on ports:"
for port in "${stopped[@]}"; do
openim::log::info "Successfully stopped service on port $port."
done
fi
# If any of the processes couldn't be stopped, return a status of 1.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
return 1
else
openim::log::success "All specified services were stopped."
return 0
fi
}
# The `openim::util::stop_services_with_name` function stops services with specified names.
# It accepts multiple service names as arguments and performs the following:
# 1. Attempts to stop any services with the specified names.
# 2. Prints details of services successfully stopped and those that failed to stop.
# Usage:
# openim::util::stop_services_with_name nginx apache
# The function returns a status of 1 if any service couldn't be stopped.
openim::util::stop_services_with_name() {
# An array to collect names of processes that couldn't be stopped.
not_stopped=()
# An array to collect information about processes that were stopped.
stopped=()
# Iterate over each given service name.
for name in "$@"; do
# Use the `pgrep` command to find process IDs related to the given service name.
pids=$(pgrep -f $name)
for pid in $pids; do
# If there's a Process ID, it means the service with the name is running.
if [[ -n $pid ]]; then
# Try to stop the service by killing its process.
if kill -TERM $pid; then
stopped+=($name)
else
not_stopped+=($name)
fi
fi
done
done
# Print information about services whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Services that couldn't be stopped:"
for name in "${not_stopped[@]}"; do
openim::log::error "Failed to stop the $name service."
done
fi
# Print information about services whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services:"
for name in "${stopped[@]}"; do
openim::log::info "Successfully stopped the $name service."
done
fi
# If any of the services couldn't be stopped, return a status of 1.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
return 1
else
openim::log::success "All specified services were stopped."
return 0
fi
}
# This figures out the host platform without relying on golang. We need this as
# we don't want a golang install to be a prerequisite to building yet we need
# this info to figure out where the final binaries are placed.

@ -1,58 +1,3 @@
#!/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.
# Determine the architecture and version
architecture=$(uname -m)
version=$(uname -s | tr '[:upper:]' '[:lower:]')
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
#Include shell font styles and some basic information
source $SCRIPTS_ROOT/lib/color.sh
cd $SCRIPTS_ROOT
# Define the supported architectures and corresponding bin directories
declare -A supported_architectures=(
["linux-amd64"]="_output/bin/platforms/linux/amd64"
["linux-arm64"]="_output/bin/platforms/linux/arm64"
["linux-mips64"]="_output/bin/platforms/linux/mips64"
["linux-mips64le"]="_output/bin/platforms/linux/mips64le"
["linux-ppc64le"]="_output/bin/platforms/linux/ppc64le"
["linux-s390x"]="_output/bin/platforms/linux/s390x"
["darwin-amd64"]="_output/bin/platforms/darwin/amd64"
["windows-amd64"]="_output/bin/platforms/windows/amd64"
["linux-x86_64"]="_output/bin/platforms/linux/amd64" # Alias for linux-amd64
["darwin-x86_64"]="_output/bin/platforms/darwin/amd64" # Alias for darwin-amd64
)
# Check if the architecture and version are supported
if [[ -z ${supported_architectures["$version-$architecture"]} ]]; then
echo -e "${BLUE_PREFIX}================> Unsupported architecture: $architecture or version: $version${COLOR_SUFFIX}"
exit 1
fi
echo -e "${BLUE_PREFIX}================> Architecture: $architecture${COLOR_SUFFIX}"
# Set the BIN_DIR based on the architecture and version
BIN_DIR=${supported_architectures["$version-$architecture"]}
echo -e "${BLUE_PREFIX}================> BIN_DIR: $OPENIM_ROOT/$BIN_DIR${COLOR_SUFFIX}"
# Don't put the space between "="
openim_msggateway="openim-msggateway"
msg_gateway_binary_root="$OPENIM_ROOT/$BIN_DIR"
@ -77,30 +22,6 @@ cmd_utils_binary_root="$OPENIM_ROOT/$BIN_DIR"
# Global configuration file default dir
config_path="$OPENIM_ROOT/config/config.yaml"
configfile_path="$OPENIM_ROOT/config"
log_path="$OPENIM_ROOT/log"
component_check="component"
component_check_binary_root="$OPENIM_ROOT/$BIN_DIR_TOOLS"
# servicefile dir path
service_source_root=(
# api service file
"$OPENIM_ROOT/cmd/api/"
# rpc service file
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-user/"
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-friend/"
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-group/"
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-auth/"
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-conversation/"
"$OPENIM_ROOT/cmd/openim-rpc/openim-rpc-third/"
"$OPENIM_ROOT/cmd/openim-crontask"
"${msg_gateway_source_root}"
"${msg_transfer_source_root}"
"${msg_source_root}"
"${push_source_root}"
# "${sdk_server_source_root}"
)
# service filename
service_names=(

@ -20,26 +20,39 @@ set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"
source "${OPENIM_ROOT}/scripts/install/common.sh"
set +o errexit
openim::golang::check_openim_binaries
if [[ $? -ne 0 ]]; then
openim::log::error "OpenIM binaries are not found. Please run 'make' to build binaries."
openim::log::error "OpenIM binaries are not found. Please run 'make build' to build binaries."
${OPENIM_ROOT}/scripts/build_all_service.sh
fi
set -o errexit
scripts_to_run=$(openim::golang::start_script_list)
echo "You need to start the following scripts in order: ${OPENIM_SERVER_SCRIPTARIES[@]}"
openim::log::install_errexit
for script in $scripts_to_run; do
openim::log::info "Executing: $script"
"$script"
if [ $? -ne 0 ]; then
# Print error message and exit
openim::log::error "Error executing ${i}. Exiting..."
exit -1
# Function to execute the scripts.
function execute_scripts() {
for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do
# Check if the script file exists and is executable.
if [[ -x "$script_path" ]]; then
openim::log::status "Starting script: ${script_path##*/}" # Log the script name.
# Execute the script.
"$script_path"
# Check if the script executed successfully.
if [[ $? -eq 0 ]]; then
openim::log::info "${script_path##*/} executed successfully."
else
openim::log::errexit "Error executing ${script_path##*/}."
fi
else
openim::log::errexit "Script ${script_path##*/} is missing or not executable."
fi
done
done
}
openim::log::success "OpenIM Server has been started successfully!"
execute_scripts

@ -13,29 +13,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#Include shell font styles and some basic information
SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
# This script is stop all openim service
#
# Usage: `scripts/stop.sh`.
# Encapsulated as: `make stop`.
#Include shell font styles and some basic information
source $OPENIM_ROOT/scripts/lib/init.sh
source $OPENIM_ROOT/scripts/path_info.sh
set -o errexit
set -o nounset
set -o pipefail
bin_dir="$BIN_DIR"
logs_dir="$OPENIM_ROOT/logs"
sdk_db_dir="$OPENIM_ROOT/sdk/db/"
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
cd "$SCRIPTS_ROOT"
echo "Ready to stop port: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
for i in ${service_names[*]}; do
#Check whether the service exists
name="ps -aux |grep -w $i |grep -v grep"
count="${name}| wc -l"
if [ $(eval ${count}) -gt 0 ]; then
pid="${name}| awk '{print \$2}'"
echo -e "${SKY_BLUE_PREFIX}Killing service:$i pid:$(eval $pid)${COLOR_SUFFIX}"
#kill the service that existed
kill -9 $(eval $pid)
echo -e "${SKY_BLUE_PREFIX}service:$i was killed ${COLOR_SUFFIX}"
fi
done
openim::util::stop_services_on_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
Loading…
Cancel
Save