mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-21 20:32:32 +08:00
fix: fix scripts and optimize
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
parent
da1316af2a
commit
be6f189365
5
Makefile
5
Makefile
@ -191,6 +191,11 @@ advertise:
|
|||||||
release: release.verify release.ensure-tag
|
release: release.verify release.ensure-tag
|
||||||
@scripts/release.sh
|
@scripts/release.sh
|
||||||
|
|
||||||
|
## demo: Run demo ✨
|
||||||
|
.PHONY: demo
|
||||||
|
demo:
|
||||||
|
@$(MAKE) go.demo
|
||||||
|
|
||||||
## help: Show this help info. ✨
|
## help: Show this help info. ✨
|
||||||
.PHONY: help
|
.PHONY: help
|
||||||
help: Makefile
|
help: Makefile
|
||||||
|
@ -84,6 +84,36 @@ Each directory and script in the structure should be understood as a part of a l
|
|||||||
|
|
||||||
- Linux MIPS64LE (linux_mips64le) : Suitable for 64-bit Linux systems with little endian MIPS architecture.
|
- Linux MIPS64LE (linux_mips64le) : Suitable for 64-bit Linux systems with little endian MIPS architecture.
|
||||||
|
|
||||||
|
## Get started quickly - demo.sh
|
||||||
|
|
||||||
|
Is the `demo.sh` script teaching you how to quickly get started with OpenIM development and use
|
||||||
|
|
||||||
|
|
||||||
|
Steps to run demo:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
make demo
|
||||||
|
```
|
||||||
|
|
||||||
|
Instructions for producing the demo movie:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create temporary directory
|
||||||
|
mkdir /tmp/kb-demo
|
||||||
|
cd /tmp/kb-demo
|
||||||
|
|
||||||
|
asciinema rec
|
||||||
|
<path-to-KB-repo>/scripts/demo/run.sh
|
||||||
|
|
||||||
|
<CTRL-C> to terminate the script
|
||||||
|
<CTRL-D> to terminate the asciinema recording
|
||||||
|
<CTRL-C> to save the recording locally
|
||||||
|
|
||||||
|
# Edit the recorded file by editing the controller-gen path
|
||||||
|
# Once you are happy with the recording, use svg-term program to generate the svg
|
||||||
|
|
||||||
|
svg-term --cast=<movie-id> --out _output/demo.svg --window
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## examples
|
## examples
|
||||||
|
@ -21,9 +21,8 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||||
|
|
||||||
#Include shell font styles and some basic information
|
#Include shell font styles and some basic information
|
||||||
source $SCRIPTS_ROOT/style_info.sh
|
source $SCRIPTS_ROOT/lib/init.sh
|
||||||
source $SCRIPTS_ROOT/path_info.sh
|
source $SCRIPTS_ROOT/path_info.sh
|
||||||
source $SCRIPTS_ROOT/function.sh
|
|
||||||
|
|
||||||
cd $SCRIPTS_ROOT
|
cd $SCRIPTS_ROOT
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ if [ $? -ne 0 ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
gen_os_arch
|
openim::util::gen_os_arch
|
||||||
|
|
||||||
# Determine if all scripts were successfully built
|
# Determine if all scripts were successfully built
|
||||||
BUILD_SUCCESS=true
|
BUILD_SUCCESS=true
|
||||||
|
@ -43,7 +43,7 @@ service_port_name=(
|
|||||||
)
|
)
|
||||||
for i in ${service_port_name[*]}; do
|
for i in ${service_port_name[*]}; do
|
||||||
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
||||||
list_to_string $list
|
openim::util:list-to-string $list
|
||||||
for j in ${ports_array}; do
|
for j in ${ports_array}; do
|
||||||
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
||||||
if [[ ${port} -ne ${j} ]]; then
|
if [[ ${port} -ne ${j} ]]; then
|
||||||
|
@ -38,7 +38,7 @@ service_port_name=(
|
|||||||
|
|
||||||
for i in ${service_port_name[*]}; do
|
for i in ${service_port_name[*]}; do
|
||||||
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
list=$(cat $config_path | grep -w ${i} | awk -F '[:]' '{print $NF}')
|
||||||
list_to_string $list
|
openim::util:list-to-string $list
|
||||||
for j in ${ports_array}; do
|
for j in ${ports_array}; do
|
||||||
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
port=$(ss -tunlp| grep openim | awk '{print $5}' | grep -w ${j} | awk -F '[:]' '{print $NF}')
|
||||||
if [[ ${port} -ne ${j} ]]; then
|
if [[ ${port} -ne ${j} ]]; then
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
|
|
||||||
#input:[10023,2323,3434]
|
#input:[10023,2323,3434]
|
||||||
#output:10023 2323 3434
|
#output:10023 2323 3434
|
||||||
list_to_string(){
|
openim::util:list-to-string(){
|
||||||
ports_list=$*
|
ports_list=$*
|
||||||
sub_s1=`echo $ports_list | sed 's/ //g'`
|
sub_s1=`echo $ports_list | sed 's/ //g'`
|
||||||
sub_s2=${sub_s1//,/ }
|
sub_s2=${sub_s1//,/ }
|
||||||
@ -23,7 +23,7 @@ list_to_string(){
|
|||||||
sub_s4=${sub_s3%]*}
|
sub_s4=${sub_s3%]*}
|
||||||
ports_array=$sub_s4
|
ports_array=$sub_s4
|
||||||
}
|
}
|
||||||
remove_space(){
|
openim::util::remove_space(){
|
||||||
value=$*
|
value=$*
|
||||||
result=`echo $value | sed 's/ //g'`
|
result=`echo $value | sed 's/ //g'`
|
||||||
}
|
}
|
@ -19,9 +19,8 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|||||||
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..
|
OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/..
|
||||||
|
|
||||||
#Include shell font styles and some basic information
|
#Include shell font styles and some basic information
|
||||||
source $SCRIPTS_ROOT/style_info.sh
|
|
||||||
source $SCRIPTS_ROOT/path_info.sh
|
source $SCRIPTS_ROOT/path_info.sh
|
||||||
source $SCRIPTS_ROOT/function.sh
|
source $SCRIPTS_ROOT/lib/init.sh
|
||||||
|
|
||||||
cd $SCRIPTS_ROOT
|
cd $SCRIPTS_ROOT
|
||||||
|
|
||||||
|
@ -1,34 +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.
|
|
||||||
|
|
||||||
# input: [10023, 2323, 3434]
|
|
||||||
# output: 10023 2323 3434
|
|
||||||
|
|
||||||
# 函数功能:将列表转换为字符串,去除空格和括号
|
|
||||||
list_to_string() {
|
|
||||||
ports_list=$* # 获取传入的参数列表
|
|
||||||
sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格
|
|
||||||
sub_s2=${sub_s1//,/ } # 将逗号替换为空格
|
|
||||||
sub_s3=${sub_s2#*[} # 去除左括号及其之前的内容
|
|
||||||
sub_s4=${sub_s3%]*} # 去除右括号及其之后的内容
|
|
||||||
ports_array=$sub_s4 # 将处理后的字符串赋值给变量 ports_array
|
|
||||||
}
|
|
||||||
|
|
||||||
# 函数功能:去除字符串中的空格
|
|
||||||
remove_space() {
|
|
||||||
value=$* # 获取传入的参数
|
|
||||||
result=$(echo $value | sed 's/ //g') # 去除空格
|
|
||||||
}
|
|
@ -7,12 +7,12 @@
|
|||||||
# 本脚本功能:根据 scripts/environment.sh 配置,生成 OPENIM 组件 YAML 配置文件。
|
# 本脚本功能:根据 scripts/environment.sh 配置,生成 OPENIM 组件 YAML 配置文件。
|
||||||
# 示例:genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml
|
# 示例:genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml
|
||||||
|
|
||||||
|
# Path to the original script file
|
||||||
env_file="$1"
|
env_file="$1"
|
||||||
|
# Path to the generated config file
|
||||||
template_file="$2"
|
template_file="$2"
|
||||||
|
|
||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
. $(dirname ${BASH_SOURCE})/lib/init.sh
|
||||||
|
|
||||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
|
||||||
|
|
||||||
if [ $# -ne 2 ];then
|
if [ $# -ne 2 ];then
|
||||||
openim::log::error "Usage: genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml"
|
openim::log::error "Usage: genconfig.sh scripts/environment.sh configs/openim-apiserver.yaml"
|
||||||
|
@ -47,6 +47,13 @@ ITALIC_PREFIX="\033[3m" # Italic prefix
|
|||||||
BRIGHT_GREEN_PREFIX='\033[1;32m' # Bright green prefix
|
BRIGHT_GREEN_PREFIX='\033[1;32m' # Bright green prefix
|
||||||
CYAN_PREFIX="\033[0;36m" # Cyan prefix
|
CYAN_PREFIX="\033[0;36m" # Cyan prefix
|
||||||
|
|
||||||
|
# --- make demo (run demo) ---
|
||||||
|
readonly reset=$(tput sgr0)
|
||||||
|
readonly green=$(tput bold; tput setaf 2)
|
||||||
|
readonly yellow=$(tput bold; tput setaf 3)
|
||||||
|
readonly blue=$(tput bold; tput setaf 6)
|
||||||
|
readonly timeout=$(if [ "$(uname)" == "Darwin" ]; then echo "1"; else echo "0.1"; fi)
|
||||||
|
|
||||||
# --- helper functions for logs ---
|
# --- helper functions for logs ---
|
||||||
info()
|
info()
|
||||||
{
|
{
|
||||||
|
@ -710,12 +710,71 @@ fi
|
|||||||
|
|
||||||
# ex: ts=2 sw=2 et filetype=sh
|
# ex: ts=2 sw=2 et filetype=sh
|
||||||
|
|
||||||
|
function openim::util::desc() {
|
||||||
|
openim::util:run::maybe_first_prompt
|
||||||
|
rate=25
|
||||||
|
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||||
|
rate=1000
|
||||||
|
fi
|
||||||
|
echo "$blue# $@$reset" | pv -qL $rate
|
||||||
|
openim::util:run::prompt
|
||||||
|
}
|
||||||
|
|
||||||
|
function openim::util:run::prompt() {
|
||||||
|
echo -n "$yellow\$ $reset"
|
||||||
|
}
|
||||||
|
|
||||||
|
started=""
|
||||||
|
function openim::util:run::maybe_first_prompt() {
|
||||||
|
if [ -z "$started" ]; then
|
||||||
|
openim::util:run::prompt
|
||||||
|
started=true
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# After a `run` this variable will hold the stdout of the command that was run.
|
||||||
|
# If the command was interactive, this will likely be garbage.
|
||||||
|
DEMO_RUN_STDOUT=""
|
||||||
|
|
||||||
|
function openim::util::run() {
|
||||||
|
openim::util:run::maybe_first_prompt
|
||||||
|
rate=25
|
||||||
|
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||||
|
rate=1000
|
||||||
|
fi
|
||||||
|
echo "$green$1$reset" | pv -qL $rate
|
||||||
|
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||||
|
sleep 0.5
|
||||||
|
fi
|
||||||
|
OFILE="$(mktemp -t $(basename $0).XXXXXX)"
|
||||||
|
if [ "$(uname)" == "Darwin" ]; then
|
||||||
|
script -q "$OFILE" $1
|
||||||
|
else
|
||||||
|
script -eq -c "$1" -f "$OFILE"
|
||||||
|
fi
|
||||||
|
r=$?
|
||||||
|
read -d '' -t "${timeout}" -n 10000 # clear stdin
|
||||||
|
openim::util:run::prompt
|
||||||
|
if [ -z "$DEMO_AUTO_RUN" ]; then
|
||||||
|
read -s
|
||||||
|
fi
|
||||||
|
DEMO_RUN_STDOUT="$(tail -n +2 $OFILE | sed 's/\r//g')"
|
||||||
|
return $r
|
||||||
|
}
|
||||||
|
|
||||||
|
function openim::util::run::relative() {
|
||||||
|
for arg; do
|
||||||
|
echo "$(realpath $(dirname $(which $0)))/$arg" | sed "s|$(realpath $(pwd))|.|"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
trap "echo" EXIT
|
||||||
|
|
||||||
|
|
||||||
# input: [10023, 2323, 3434]
|
# input: [10023, 2323, 3434]
|
||||||
# output: 10023 2323 3434
|
# output: 10023 2323 3434
|
||||||
|
|
||||||
# Function function: Converts a list to a string, removing Spaces and parentheses
|
# Function function: Converts a list to a string, removing Spaces and parentheses
|
||||||
function list_to_string() {
|
function openim::util:list-to-string() {
|
||||||
ports_list=$* # 获取传入的参数列表
|
ports_list=$* # 获取传入的参数列表
|
||||||
sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格
|
sub_s1=$(echo $ports_list | sed 's/ //g') # 去除空格
|
||||||
sub_s2=${sub_s1//,/ } # 将逗号替换为空格
|
sub_s2=${sub_s1//,/ } # 将逗号替换为空格
|
||||||
@ -725,12 +784,12 @@ function list_to_string() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Function Function: Remove Spaces in the string
|
# Function Function: Remove Spaces in the string
|
||||||
function remove_space() {
|
function openim::util::remove_space() {
|
||||||
value=$* # 获取传入的参数
|
value=$* # 获取传入的参数
|
||||||
result=$(echo $value | sed 's/ //g') # 去除空格
|
result=$(echo $value | sed 's/ //g') # 去除空格
|
||||||
}
|
}
|
||||||
|
|
||||||
function gen_os_arch() {
|
function openim::util::gen_os_arch() {
|
||||||
# Get the current operating system and architecture
|
# Get the current operating system and architecture
|
||||||
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
ARCH=$(uname -m)
|
ARCH=$(uname -m)
|
||||||
|
@ -163,6 +163,12 @@ go.lint: tools.verify.golangci-lint
|
|||||||
go.test:
|
go.test:
|
||||||
@$(GO) test ./...
|
@$(GO) test ./...
|
||||||
|
|
||||||
|
## go.demo: Run demo
|
||||||
|
.PHONY: go.demo
|
||||||
|
go.demo:
|
||||||
|
@echo "===========> Run demo"
|
||||||
|
@$(ROOT_DIR)/scripts/demo.sh
|
||||||
|
|
||||||
## go.test.junit-report: Run unit test
|
## go.test.junit-report: Run unit test
|
||||||
.PHONY: go.test.junit-report
|
.PHONY: go.test.junit-report
|
||||||
go.test.junit-report: tools.verify.go-junit-report
|
go.test.junit-report: tools.verify.go-junit-report
|
||||||
|
@ -36,11 +36,11 @@ ulimit -n 200000
|
|||||||
list1=$(cat $config_path | grep openImMessageGatewayPort | awk -F '[:]' '{print $NF}')
|
list1=$(cat $config_path | grep openImMessageGatewayPort | awk -F '[:]' '{print $NF}')
|
||||||
list2=$(cat $config_path | grep openImWsPort | awk -F '[:]' '{print $NF}')
|
list2=$(cat $config_path | grep openImWsPort | awk -F '[:]' '{print $NF}')
|
||||||
list3=$(cat $config_path | grep messageGatewayPrometheusPort | awk -F '[:]' '{print $NF}')
|
list3=$(cat $config_path | grep messageGatewayPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||||
list_to_string $list1
|
openim::util:list-to-string $list1
|
||||||
rpc_ports=($ports_array)
|
rpc_ports=($ports_array)
|
||||||
list_to_string $list2
|
openim::util:list-to-string $list2
|
||||||
ws_ports=($ports_array)
|
ws_ports=($ports_array)
|
||||||
list_to_string $list3
|
openim::util:list-to-string $list3
|
||||||
prome_ports=($ports_array)
|
prome_ports=($ports_array)
|
||||||
if [ ${#rpc_ports[@]} -ne ${#ws_ports[@]} ]; then
|
if [ ${#rpc_ports[@]} -ne ${#ws_ports[@]} ]; then
|
||||||
|
|
||||||
|
@ -32,7 +32,7 @@ logs_dir="$OPENIM_ROOT/logs"
|
|||||||
cd $OPENIM_ROOT
|
cd $OPENIM_ROOT
|
||||||
|
|
||||||
list1=$(cat $config_path | grep messageTransferPrometheusPort | awk -F '[:]' '{print $NF}')
|
list1=$(cat $config_path | grep messageTransferPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||||
list_to_string $list1
|
openim::util:list-to-string $list1
|
||||||
prome_ports=($ports_array)
|
prome_ports=($ports_array)
|
||||||
|
|
||||||
#Check if the service exists
|
#Check if the service exists
|
||||||
|
@ -37,9 +37,9 @@ cd "$OPENIM_ROOT/scripts/"
|
|||||||
|
|
||||||
list1=$(cat $config_path | grep openImPushPort | awk -F '[:]' '{print $NF}')
|
list1=$(cat $config_path | grep openImPushPort | awk -F '[:]' '{print $NF}')
|
||||||
list2=$(cat $config_path | grep pushPrometheusPort | awk -F '[:]' '{print $NF}')
|
list2=$(cat $config_path | grep pushPrometheusPort | awk -F '[:]' '{print $NF}')
|
||||||
list_to_string $list1
|
openim::util:list-to-string $list1
|
||||||
rpc_ports=($ports_array)
|
rpc_ports=($ports_array)
|
||||||
list_to_string $list2
|
openim::util:list-to-string $list2
|
||||||
prome_ports=($ports_array)
|
prome_ports=($ports_array)
|
||||||
|
|
||||||
#Check if the service exists
|
#Check if the service exists
|
||||||
|
@ -19,9 +19,8 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|||||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||||
|
|
||||||
#Include shell font styles and some basic information
|
#Include shell font styles and some basic information
|
||||||
source $SCRIPTS_ROOT/style_info.sh
|
source $SCRIPTS_ROOT/lib/init.sh
|
||||||
source $SCRIPTS_ROOT/path_info.sh
|
source $SCRIPTS_ROOT/path_info.sh
|
||||||
source $SCRIPTS_ROOT/function.sh
|
|
||||||
|
|
||||||
cd $SCRIPTS_ROOT
|
cd $SCRIPTS_ROOT
|
||||||
|
|
||||||
|
@ -90,11 +90,11 @@ for ((i = 0; i < ${#service_filename[*]}; i++)); do
|
|||||||
cd $BIN_DIR
|
cd $BIN_DIR
|
||||||
# Get the rpc port in the configuration file
|
# Get the rpc port in the configuration file
|
||||||
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
portList=$(cat $config_path | grep ${service_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
||||||
list_to_string ${portList}
|
openim::util:list-to-string ${portList}
|
||||||
service_ports=($ports_array)
|
service_ports=($ports_array)
|
||||||
|
|
||||||
portList2=$(cat $config_path | grep ${service_prometheus_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
portList2=$(cat $config_path | grep ${service_prometheus_port_name[$i]} | awk -F '[:]' '{print $NF}')
|
||||||
list_to_string $portList2
|
openim::util:list-to-string $portList2
|
||||||
prome_ports=($ports_array)
|
prome_ports=($ports_array)
|
||||||
#Start related rpc services based on the number of ports
|
#Start related rpc services based on the number of ports
|
||||||
for ((j = 0; j < ${#service_ports[*]}; j++)); do
|
for ((j = 0; j < ${#service_ports[*]}; j++)); do
|
||||||
|
Loading…
x
Reference in New Issue
Block a user