mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-11-05 03:42:08 +08:00
Merge remote-tracking branch 'origin/3.6.1-code-conventions' into 3.6.1-code-conventions
This commit is contained in:
commit
13c838ad97
@ -15,10 +15,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
_ "net/http/pprof"
|
||||
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
util "github.com/openimsdk/open-im-server/v3/pkg/util/genutil"
|
||||
_ "net/http/pprof"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@ -79,7 +79,6 @@ func (c *ConversationMgo) FindUserID(ctx context.Context, userIDs []string, conv
|
||||
options.Find().SetProjection(bson.M{"_id": 0, "owner_user_id": 1}),
|
||||
)
|
||||
}
|
||||
|
||||
func (c *ConversationMgo) FindUserIDAllConversationID(ctx context.Context, userID string) ([]string, error) {
|
||||
return mgoutil.Find[string](ctx, c.coll, bson.M{"owner_user_id": userID}, options.Find().SetProjection(bson.M{"_id": 0, "conversation_id": 1}))
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ fi
|
||||
|
||||
OPENIM_VERBOSE=4
|
||||
|
||||
openim::log::info "\n# Begin to check all openim service"
|
||||
openim::log::info "\n# Begin to check all OpenIM service"
|
||||
|
||||
openim::log::status "Check all dependent service ports"
|
||||
# Elegant printing function
|
||||
@ -65,16 +65,16 @@ print_services_and_ports "${OPENIM_SERVER_NAME_TARGETS[@]}" "${OPENIM_SERVER_POR
|
||||
print_services_and_ports "${OPENIM_DEPENDENCY_TARGETS[@]}" "${OPENIM_DEPENDENCY_PORT_TARGETS[@]}"
|
||||
|
||||
# OpenIM check
|
||||
echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
openim::log::info "\n## Check all dependent service ports"
|
||||
echo "++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
|
||||
#echo "++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
|
||||
openim::log::info "\n## Check all dependent components service ports"
|
||||
#echo "++ The port being checked: ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}"
|
||||
|
||||
|
||||
# Later, after discarding Docker, the Docker keyword is unreliable, and Kubepods is used
|
||||
if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then
|
||||
openim::color::echo ${COLOR_CYAN} "Environment in the interior of the container"
|
||||
else
|
||||
openim::color::echo ${COLOR_CYAN} "The environment is outside the container"
|
||||
openim::color::echo ${COLOR_CYAN}"The environment is outside the container"
|
||||
openim::util::check_ports ${OPENIM_DEPENDENCY_PORT_LISTARIES[@]}
|
||||
fi
|
||||
|
||||
@ -82,30 +82,39 @@ 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
|
||||
openim::log::success "All components depended on by openim are running normally! "
|
||||
openim::log::success "All components depended on by OpenIM are running normally! "
|
||||
fi
|
||||
|
||||
|
||||
openim::log::info "\n## Check openim service name:\n${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer"
|
||||
openim::log::status "Check OpenIM service:"
|
||||
openim::log::colorless "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer"
|
||||
result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "+++ cat openim log file >>> ${LOG_FILE}"
|
||||
openim::log::error "check process failed.\n $result"
|
||||
#echo "+++ cat openim log file >>> ${LOG_FILE}"
|
||||
|
||||
openim::log::error "The service is not running properly, please check the logs $result"
|
||||
fi
|
||||
|
||||
|
||||
echo "Check openim service name:"
|
||||
openim::log::status "Check OpenIM service:"
|
||||
for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do
|
||||
echo "$item"
|
||||
openim::log::colorless "$item"
|
||||
done
|
||||
|
||||
|
||||
result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "+++ cat openim log file >>> ${LOG_FILE}"
|
||||
openim::log::error "check process failed.\n "
|
||||
#echo "+++ cat OpenIM log file >>> ${LOG_FILE}"
|
||||
openim::log::error "The service is not running properly, please check the logs "
|
||||
echo "$result"
|
||||
exit 1
|
||||
else
|
||||
openim::log::success "All openim services are running normally! "
|
||||
openim::log::status "List the ports listened to by the OpenIM service:"
|
||||
openim::util::find_ports_for_all_services ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}
|
||||
openim::util::find_ports_for_all_services ${OPENIM_MSGTRANSFER_BINARY[@]}
|
||||
openim::log::success "All OpenIM services are running normally! "
|
||||
fi
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
156
scripts/demo.sh
156
scripts/demo.sh
@ -1,156 +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.
|
||||
|
||||
if ! command -v pv &> /dev/null
|
||||
then
|
||||
echo "pv not found, installing..."
|
||||
if [ -e /etc/debian_version ]; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y pv
|
||||
elif [ -e /etc/redhat-release ]; then
|
||||
sudo yum install -y pv
|
||||
else
|
||||
echo "Unsupported OS, please install pv manually."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
readonly t_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)
|
||||
readonly ipv6regex='(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))'
|
||||
|
||||
clear
|
||||
. $(dirname ${BASH_SOURCE})/lib/util.sh
|
||||
|
||||
openim::util::ensure-bash-version
|
||||
|
||||
trap 'openim::util::onCtrlC' INT
|
||||
|
||||
function openim::util::onCtrlC() {
|
||||
echo -e "\n${t_reset}Ctrl+C Press it. It's exiting openim make init..."
|
||||
exit 0
|
||||
}
|
||||
|
||||
openim::util::desc "========> Welcome to the OpenIM Demo"
|
||||
openim::util::desc "========> We'll help you get started with OpenIM quickly"
|
||||
openim::util::desc "========> Press Enter to continue...."
|
||||
openim::util::run "make advertise"
|
||||
clear
|
||||
|
||||
openim::util::desc "========> Initialize the project and generate configuration files"
|
||||
openim::util::run "make init"
|
||||
clear
|
||||
|
||||
# openim::util::desc "========> You can look git diff"
|
||||
# openim::util::run "git diff"
|
||||
# clear
|
||||
|
||||
openim::util::desc "You can learn a lot about automation using make help"
|
||||
openim::util::run "make help"
|
||||
clear
|
||||
|
||||
openim::util::desc "You can learn a lot about automation using make help-all"
|
||||
openim::util::run "make help-all"
|
||||
clear
|
||||
|
||||
openim::util::desc "First, let's verify and install some necessary tools"
|
||||
openim::util::run "make tools"
|
||||
clear
|
||||
|
||||
openim::util::desc "========> Start the basic openim docker components"
|
||||
openim::util::desc "========> You can use docker-compose ps to check the status of the container"
|
||||
openim::util::run "docker compose up -d"
|
||||
clear
|
||||
|
||||
openim::util::desc "========> Use make init-githooks Initialize git hooks "
|
||||
openim::util::run "make init-githooks"
|
||||
clear
|
||||
|
||||
openim::util::desc "The specification is pretty high, you need to be bound on your branch name, as well as commit messages"
|
||||
openim::util::run "git commit -a -s -m 'feta: commit demo against specification'"
|
||||
openim::util::run "# git commit -a -s -m 'feat: commit demo against specification' --amend"
|
||||
clear
|
||||
|
||||
openim::util::desc "How did we teach you how to build OpenIM"
|
||||
openim::util::desc "A full build startup check"
|
||||
openim::util::run "# make all"
|
||||
openim::util::desc "Build one OpenIM binary"
|
||||
openim::util::desc "BINS: openim-api openim-cmdutils openim-crontask openim-msggateway openim-msgtransfer openim-push openim-rpc changelog infra ncpu yamlfmt"
|
||||
openim::util::run "make build BINS=openim-api"
|
||||
openim::util::run "make build"
|
||||
|
||||
openim::util::desc "Build binaries for all platforms"
|
||||
openim::util::run "make multiarch -j BINS=openim-crontask PLATFORMS='linux_arm64 linux_amd64' "
|
||||
|
||||
openim::util::desc "If you wish to use dlv for debugging, either binary or process"
|
||||
openim::util::desc "You need to enable debug mode"
|
||||
openim::util::run "make build BINS=openim-cmdutils DEBUG=1"
|
||||
clear
|
||||
|
||||
openim::util::desc "Next, let's learn how to start the OpenIM service. For starting, we have two ways"
|
||||
openim::util::desc "The first is Background startup"
|
||||
openim::util::run "make start"
|
||||
openim::util::desc "The second way is through the Linux system way"
|
||||
openim::util::run "./scripts/install/install.sh --help"
|
||||
clear
|
||||
|
||||
openim::util::desc "Next, let's learn how to check the OpenIM service. For checking, we have two ways"
|
||||
openim::util::run "make check"
|
||||
clear
|
||||
|
||||
openim::util::desc "Next, let's learn how to stop the OpenIM service. For stopping, we have two ways"
|
||||
openim::util::run "make stop"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run tidy to format and fix imports"
|
||||
openim::util::run "make tidy"
|
||||
clear
|
||||
|
||||
openim::util::desc "Vendor go.mod dependencies"
|
||||
openim::util::run "# make vendor"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run unit tests"
|
||||
openim::util::run "# make test"
|
||||
clear
|
||||
|
||||
openim::util::desc "Run unit tests and get test coverage"
|
||||
openim::util::run "# make cover"
|
||||
clear
|
||||
|
||||
openim::util::desc "Check for updates to go.mod dependencies"
|
||||
openim::util::run "# make updates"
|
||||
clear
|
||||
|
||||
openim::util::desc "You can learn a lot about automation using make clean, remove all files that are created by building"
|
||||
openim::util::run "make clean"
|
||||
clear
|
||||
|
||||
openim::util::desc "Generate all necessary files"
|
||||
openim::util::run "make gen"
|
||||
clear
|
||||
|
||||
openim::util::desc "Verify the license headers for all files"
|
||||
openim::util::run "make verify-copyright"
|
||||
clear
|
||||
|
||||
openim::util::desc "Add copyright"
|
||||
openim::util::run "make add-copyright"
|
||||
clear
|
||||
|
||||
exit 0
|
||||
@ -1,91 +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.
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
|
||||
cd "$OPENIM_ROOT"
|
||||
|
||||
openim::util::check_docker_and_compose_versions
|
||||
|
||||
progress() {
|
||||
local _main_pid="$1"
|
||||
local _length=20
|
||||
local _ratio=1
|
||||
local _colors=("31" "32" "33" "34" "35" "36" "37")
|
||||
local _wave=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█" "▇" "▆" "▅" "▄" "▃" "▂")
|
||||
|
||||
while pgrep -P "$_main_pid" &> /dev/null; do
|
||||
local _mark='>'
|
||||
local _progress_bar=
|
||||
for ((i = 1; i <= _length; i++)); do
|
||||
if ((i > _ratio)); then
|
||||
_mark='-'
|
||||
fi
|
||||
_progress_bar="${_progress_bar}${_mark}"
|
||||
done
|
||||
|
||||
local _color_idx=$((_ratio % ${#_colors[@]}))
|
||||
local _color_prefix="\033[${_colors[_color_idx]}m"
|
||||
local _reset_suffix="\033[0m"
|
||||
|
||||
local _wave_idx=$((_ratio % ${#_wave[@]}))
|
||||
local _wave_progress=${_wave[_wave_idx]}
|
||||
|
||||
printf "Progress: ${_color_prefix}${_progress_bar}${_reset_suffix} ${_wave_progress} Countdown: %2ds \r" "$_countdown"
|
||||
((_ratio++))
|
||||
((_ratio > _length)) && _ratio=1
|
||||
sleep 0.1
|
||||
done
|
||||
}
|
||||
|
||||
countdown() {
|
||||
local _duration="$1"
|
||||
|
||||
for ((i = _duration; i >= 1; i--)); do
|
||||
printf "\rCountdown: %2ds \r" "$i"
|
||||
sleep 1
|
||||
done
|
||||
printf "\rCountdown: %2ds \r" "$_duration"
|
||||
}
|
||||
|
||||
do_sth() {
|
||||
echo "++++++++++++++++++++++++"
|
||||
progress $$ &
|
||||
local _progress_pid=$!
|
||||
local _countdown=30
|
||||
|
||||
countdown "$_countdown" &
|
||||
local _countdown_pid=$!
|
||||
|
||||
sleep 30
|
||||
|
||||
kill "$_progress_pid" "$_countdown_pid"
|
||||
|
||||
"${SCRIPTS_ROOT}/check-all.sh"
|
||||
echo -e "${PURPLE_PREFIX}=========> Check docker-compose status ${COLOR_SUFFIX} \n"
|
||||
}
|
||||
|
||||
set -e
|
||||
|
||||
do_sth &
|
||||
do_sth_pid=$(jobs -p | tail -1)
|
||||
|
||||
progress "${do_sth_pid}" &
|
||||
progress_pid=$(jobs -p | tail -1)
|
||||
|
||||
wait "${do_sth_pid}"
|
||||
printf "Progress: done \n"
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
source "${OPENIM_ROOT}/scripts/install/common.sh"
|
||||
openim::log::info "\n# Use Docker to start all openim service"
|
||||
openim::log::info "\n# Use Docker to start all OpenIM service"
|
||||
trap 'openim::util::onCtrlC' INT
|
||||
"${OPENIM_ROOT}"/scripts/start-all.sh 2>&1 &
|
||||
tail -f ${DOCKER_LOG_FILE}
|
||||
|
||||
@ -65,6 +65,8 @@ GENERATE_EXAMPLES=false
|
||||
CLEAN_CONFIG=false
|
||||
CLEAN_EXAMPLES=false
|
||||
|
||||
FILES_PROCESSED=false
|
||||
|
||||
# Function to display help information
|
||||
show_help() {
|
||||
echo "Usage: $(basename "$0") [options]"
|
||||
@ -126,7 +128,7 @@ process_file() {
|
||||
if [[ "${FORCE_OVERWRITE}" == true ]]; then
|
||||
openim::log::info "Force overwriting ${output_file}."
|
||||
elif [[ "${SKIP_EXISTING}" == true ]]; then
|
||||
openim::log::info "Skipping generation of ${output_file} as it already exists."
|
||||
#openim::log::info "Skipping generation of ${output_file} as it already exists."
|
||||
return
|
||||
else
|
||||
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
|
||||
@ -173,8 +175,7 @@ process_file() {
|
||||
exit 1
|
||||
}
|
||||
fi
|
||||
|
||||
sleep 0.5
|
||||
FILES_PROCESSED=true
|
||||
}
|
||||
|
||||
clean_config_files() {
|
||||
@ -259,4 +260,6 @@ if [[ "${GENERATE_EXAMPLES}" == true ]] && [[ "${CLEAN_EXAMPLES}" == false ]]; t
|
||||
generate_example_files
|
||||
fi
|
||||
|
||||
openim::log::success "Configuration and example files operation complete!"
|
||||
if [[ "${FILES_PROCESSED}" == true ]]; then
|
||||
openim::log::success "Configuration and example files operation complete!"
|
||||
fi
|
||||
|
||||
@ -89,7 +89,7 @@ function openim::api::start_service() {
|
||||
echo "Starting service with command: $cmd"
|
||||
|
||||
#nohup $cmd >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
||||
if [ $? -ne 0 ]; then
|
||||
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
|
||||
return 1
|
||||
|
||||
@ -53,7 +53,7 @@ function openim::crontask::start() {
|
||||
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
|
||||
#nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
cmd="${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG}"
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
||||
return 0
|
||||
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ function openim::msggateway::start() {
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
|
||||
fi
|
||||
cmd="${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG}"
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
||||
# nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
|
||||
done
|
||||
|
||||
@ -58,7 +58,8 @@ function openim::msgtransfer::start() {
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${PROMETHEUS_MSG_TRANSFER_PORT}"
|
||||
fi
|
||||
cmd="${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i}"
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
||||
#nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
done
|
||||
return 0
|
||||
@ -82,7 +83,7 @@ function openim::msgtransfer::check() {
|
||||
fi
|
||||
done
|
||||
else
|
||||
openim::log::error "Expected $OPENIM_MSGGATEWAY_NUM openim msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes."
|
||||
openim::log::error "Expected $OPENIM_MSGGATEWAY_NUM OpenIM msgtransfer processes, but found $NUM_PROCESSES msgtransfer processes running"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
|
||||
@ -72,7 +72,8 @@ function openim::push::start() {
|
||||
for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do
|
||||
openim::log::info "start push process, port: ${OPENIM_PUSH_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_PROM_PORTS_ARRAY[$i]}"
|
||||
cmd="${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]}"
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
||||
#nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
done
|
||||
return 0
|
||||
|
||||
@ -166,7 +166,8 @@ function openim::rpc::start_service() {
|
||||
cmd="${cmd} --prometheus_port ${prometheus_port}"
|
||||
fi
|
||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
#nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >/dev/null &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "$TMP_LOG_FILE" | while read line; do echo -e "\e[31m${line}\e[0m"; done >&2) >> "${LOG_FILE}" 2>&1 &
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@ -83,67 +83,65 @@ function openim::tools::start_service() {
|
||||
local prometheus_port="$4"
|
||||
|
||||
local cmd="${OPENIM_OUTPUT_HOSTBIN_TOOLS}/${binary_name}"
|
||||
openim::log::info "Starting PATH: ${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}"
|
||||
# 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}"
|
||||
#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}"
|
||||
#printf "Specifying prometheus port: %s\n" "${prometheus_port}"
|
||||
cmd="${cmd} --prometheus_port ${prometheus_port}"
|
||||
fi
|
||||
openim::log::status "Starting binary ${binary_name}..."
|
||||
#openim::log::status "Starting binary ${binary_name}..."
|
||||
|
||||
|
||||
|
||||
${cmd}
|
||||
|
||||
# openim::log::info "cmd: $cmd"
|
||||
${cmd}
|
||||
|
||||
|
||||
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
|
||||
if [ $status -eq 0 ]; then
|
||||
openim::log::colorless "Service ${binary_name} started successfully."
|
||||
return 0
|
||||
else
|
||||
openim::log::error "Failed to start service ${binary_name}."
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function openim::tools::start() {
|
||||
openim::log::info "Starting OpenIM Tools..."
|
||||
for tool in "${OPENIM_TOOLS_NAME_LISTARIES[@]}"; do
|
||||
openim::log::info "Starting tool ${tool}..."
|
||||
openim::log::colorless "Starting tool ${tool}..."
|
||||
# openim::tools::start_service ${tool}
|
||||
sleep 0.2
|
||||
#sleep 0.2
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
function openim::tools::pre-start() {
|
||||
openim::log::info "Preparing to start OpenIM Tools..."
|
||||
#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::log::colorless "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."
|
||||
#openim::log::info "All tools started successfully."
|
||||
}
|
||||
|
||||
function openim::tools::post-start() {
|
||||
openim::log::info "Post-start actions for OpenIM Tools..."
|
||||
#openim::log::info "Post-start actions for OpenIM Tools..."
|
||||
for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do
|
||||
openim::log::info "Starting tool ${tool}..."
|
||||
openim::log::colorless "Starting tool: ${tool}"
|
||||
openim::tools::start_service ${tool}
|
||||
done
|
||||
}
|
||||
|
||||
@ -149,7 +149,7 @@ openim::golang::start_script_list() {
|
||||
openim-msgtransfer.sh
|
||||
openim-msggateway.sh
|
||||
openim-crontask.sh
|
||||
openim-tools.sh
|
||||
#openim-tools.sh
|
||||
)
|
||||
local result=()
|
||||
for target in "${targets[@]}"; do
|
||||
@ -181,7 +181,7 @@ openim::golang::check_openim_binaries() {
|
||||
done
|
||||
return 1
|
||||
else
|
||||
echo "All binaries have been installed in ${OPENIM_OUTPUT_HOSTBIN}。"
|
||||
echo -e "All binaries have been installed in: \n${OPENIM_OUTPUT_HOSTBIN}\n${OPENIM_OUTPUT_HOSTBIN_TOOLS}"
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
@ -210,16 +210,26 @@ openim::log::status() {
|
||||
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
timestamp=$(date +"[%Y-%m-%d %H:%M:%S %Z]")
|
||||
echo_log "${timestamp} ${1}"
|
||||
|
||||
local COLOR_BLUE="\033[0;34m"
|
||||
local COLOR_RESET="\033[0m"
|
||||
|
||||
local timestamp=$(date +"[%Y-%m-%d %H:%M:%S %Z]")
|
||||
|
||||
echo_log() {
|
||||
echo -e "$@"
|
||||
}
|
||||
|
||||
|
||||
echo_log "${COLOR_BLUE}${timestamp} ${1}${COLOR_RESET}"
|
||||
shift
|
||||
for message; do
|
||||
echo_log " ${message}"
|
||||
echo_log "${COLOR_BLUE}${message}${COLOR_RESET}"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
openim::log::success() {
|
||||
local V="${V:-0}"
|
||||
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
|
||||
@ -232,7 +242,6 @@ openim::log::success() {
|
||||
|
||||
|
||||
|
||||
|
||||
function openim::log::test_log() {
|
||||
echo_log "test log"
|
||||
openim::log::info "openim::log::info"
|
||||
@ -249,3 +258,14 @@ function openim::log::print_blue() {
|
||||
echo -e "\033[0;36m$1\033[0m"
|
||||
}
|
||||
|
||||
|
||||
openim::log::colorless() {
|
||||
local V="${V:-0}"
|
||||
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
|
||||
return
|
||||
fi
|
||||
timestamp=$(date +"[%Y-%m-%d %H:%M:%S %Z]")
|
||||
echo_log -e "${timestamp} ${1} "
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -360,8 +360,8 @@ openim::util::check_ports() {
|
||||
|
||||
# If any of the processes is not running, return a status of 1.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::color::echo $COLOR_RED "OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED "OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
#openim::color::echo $COLOR_RED "OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
#openim::color::echo $COLOR_RED "OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||
return 1
|
||||
else
|
||||
@ -446,8 +446,8 @@ openim::util::check_process_names() {
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::color::echo $COLOR_RED "OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED "OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
#openim::color::echo $COLOR_RED "OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
#openim::color::echo $COLOR_RED "OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||
return 1
|
||||
else
|
||||
@ -599,33 +599,36 @@ openim::util::stop_services_with_name() {
|
||||
# An array to collect information about processes that were stopped.
|
||||
local stopped=()
|
||||
|
||||
echo "Stopping services with names: $*"
|
||||
# Iterate over each given service name.
|
||||
for server_name in "$@"; do
|
||||
# Use the `pgrep` command to find process IDs related to the given service name.
|
||||
local pids=$(pgrep -f "$server_name")
|
||||
|
||||
# If no process was found with the name, add it to the not_stopped list
|
||||
if [[ -z $pids ]]; then
|
||||
not_stopped+=("$server_name")
|
||||
continue
|
||||
fi
|
||||
local stopped_this_time=false
|
||||
for pid in $pids; do
|
||||
for pid in $pids; do
|
||||
|
||||
# Exclude the PID of the current script
|
||||
if [[ "$pid" == "$$" ]]; then
|
||||
continue
|
||||
fi
|
||||
# Exclude the PID of the current script
|
||||
if [[ "$pid" == "$$" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
# If there's a Process ID, it means the service with the name is running.
|
||||
if [[ -n $pid ]]; then
|
||||
# Print the binary path for the PID
|
||||
binary_path=$(readlink -f /proc/$pid/exe)
|
||||
openim::log::colorless "stop PID $pid full path: $binary_path"
|
||||
|
||||
# Try to stop the service by killing its process.
|
||||
if kill -15 $pid 2>/dev/null; then
|
||||
stopped_this_time=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# 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 -15 $pid 2>/dev/null; then
|
||||
stopped_this_time=true
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if $stopped_this_time; then
|
||||
stopped+=("$server_name")
|
||||
@ -2848,6 +2851,46 @@ function openim::util::check_process_names_for_stop() {
|
||||
|
||||
|
||||
|
||||
function openim::util::find_process_ports() {
|
||||
local process_path="$1"
|
||||
if [[ -z "$process_path" ]]; then
|
||||
echo "Usage: find_process_ports /path/to/process"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local protocol_ports=""
|
||||
while read -r line; do
|
||||
local port_protocol=($line)
|
||||
local port=${port_protocol[0]##*:}
|
||||
local protocol=${port_protocol[1]}
|
||||
protocol_ports="${protocol_ports}${protocol} ${port}, "
|
||||
|
||||
done < <(lsof -nP -iTCP -iUDP | grep LISTEN | grep "$(pgrep -f "$process_path")" | awk '{print $9, $8}')
|
||||
|
||||
protocol_ports=${protocol_ports%, }
|
||||
|
||||
if [[ -z "$protocol_ports" ]]; then
|
||||
openim::log::colorless "$process_path is not listening on any ports"
|
||||
else
|
||||
openim::log::colorless "$process_path is listening on protocol & port: $protocol_ports"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function openim::util::find_ports_for_all_services() {
|
||||
local services=("$@")
|
||||
for service in "${services[@]}"; do
|
||||
openim::util::find_process_ports "$service"
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if [[ "$*" =~ openim::util:: ]];then
|
||||
eval $*
|
||||
fi
|
||||
|
||||
@ -104,25 +104,25 @@ go.build: go.build.verify $(addprefix go.build., $(addprefix $(PLATFORM)., $(BIN
|
||||
## go.start: Start openim
|
||||
.PHONY: go.start
|
||||
go.start:
|
||||
@echo "===========> Starting openim"
|
||||
@echo "=========================> Starting OpenIM <========================="
|
||||
@$(ROOT_DIR)/scripts/start-all.sh
|
||||
|
||||
## go.stop: Stop openim
|
||||
.PHONY: go.stop
|
||||
go.stop:
|
||||
@echo "===========> Stopping openim"
|
||||
@echo "=========================> Stopping OpenIM <========================="
|
||||
@$(ROOT_DIR)/scripts/stop-all.sh
|
||||
|
||||
## go.check: Check openim
|
||||
.PHONY: go.check
|
||||
go.check:
|
||||
@echo "===========> Checking openim"
|
||||
@echo "=========================> Checking OpenIM <========================="
|
||||
@$(ROOT_DIR)/scripts/check-all.sh
|
||||
|
||||
## go.check-component: Check openim component
|
||||
.PHONY: go.check-component
|
||||
go.check-component:
|
||||
@echo "===========> Checking openim component"
|
||||
@echo "=========================> Checking OpenIM component <========================="
|
||||
@$(ROOT_DIR)/scripts/install/openim-tools.sh openim::tools::pre-start
|
||||
|
||||
## go.versionchecker: Design, detect some environment variables and versions
|
||||
|
||||
@ -42,8 +42,7 @@ function execute_start_scripts() {
|
||||
|
||||
# Check if the script file exists and is executable.
|
||||
if [[ -x "$script_path" ]]; then
|
||||
openim::log::print_blue "Starting script: ${script_path##*/}" # Log the script name.
|
||||
|
||||
openim::log::colorless "Starting script: ${script_path##*/}" # Log the script name.
|
||||
# Execute the script with the constructed argument.
|
||||
result=$("$script_path" "$arg")
|
||||
if [[ $? -ne 0 ]]; then
|
||||
@ -83,17 +82,16 @@ fi
|
||||
# TODO Prelaunch tools, simple for now, can abstract functions later
|
||||
TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh
|
||||
|
||||
openim::log::print_blue "\n## Pre Starting OpenIM services"
|
||||
|
||||
openim::log::status "Start the pre-start tools:"
|
||||
|
||||
|
||||
if ! ${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start; then
|
||||
openim::log::error "Pre Starting OpenIM services failed, aborting..."
|
||||
openim::log::error "Start the pre-start tools, aborting!"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
openim::log::print_blue "Pre Starting OpenIM services processed successfully"
|
||||
openim::log::colorless "pre-start has been successfully completed!"
|
||||
|
||||
result=$("${OPENIM_ROOT}"/scripts/stop-all.sh)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
@ -102,28 +100,32 @@ if [[ $? -ne 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
|
||||
openim::log::status "\n## Starting openim scripts: "
|
||||
openim::log::status "Start the OpenIM startup scripts: "
|
||||
execute_start_scripts
|
||||
openim::log::status "OpenIM startup scripts have been successfully completed!"
|
||||
|
||||
sleep 2
|
||||
|
||||
result=$(. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check)
|
||||
if [[ $? -ne 0 ]]; then
|
||||
openim::log::error "The program may fail to start.\n $result"
|
||||
openim::log::error "The OpenIM services may fail to start.\n $result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
result=$(openim::util::check_process_names ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]})
|
||||
if [[ $? -ne 0 ]]; then
|
||||
openim::log::error "The program may fail to start.\n $result"
|
||||
openim::log::error "The OpenIM services may fail to start.\n $result"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
openim::log::info "\n## Post Starting openim services"
|
||||
${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start
|
||||
|
||||
openim::log::success "All openim services have been successfully started!"
|
||||
|
||||
openim::log::status "Start the post-start tools:"
|
||||
${TOOLS_START_SCRIPTS_PATH} openim::tools::post-start
|
||||
openim::log::status "post-start has been successfully completed!"
|
||||
openim::util::find_ports_for_all_services ${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}
|
||||
openim::util::find_ports_for_all_services ${OPENIM_MSGTRANSFER_BINARY[@]}
|
||||
|
||||
openim::log::success "All OpenIM services have been successfully started!"
|
||||
@ -25,13 +25,14 @@ func printLinks() {
|
||||
blue := color.New(color.FgBlue).SprintFunc()
|
||||
fmt.Printf("OpenIM Github: %s\n", blue("https://github.com/OpenIMSDK/Open-IM-Server"))
|
||||
fmt.Printf("Slack Invitation: %s\n", blue("https://openimsdk.slack.com"))
|
||||
fmt.Printf("Follow Twitter: %s\n", blue("https://twitter.com/founder_im63606"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
yellow := color.New(color.FgYellow)
|
||||
blue := color.New(color.FgBlue, color.Bold)
|
||||
|
||||
yellow.Println("Current module is still under development.")
|
||||
yellow.Println("Please use the release branch or tag for production environments!")
|
||||
|
||||
message := `
|
||||
____ _____ __ __
|
||||
|
||||
@ -58,14 +58,6 @@ func getDockerVersion() string {
|
||||
return version
|
||||
}
|
||||
|
||||
func getDockerComposeVersion() string {
|
||||
version, err := ExecuteCommand("docker-compose", "--version")
|
||||
if err != nil {
|
||||
return "Docker Compose is not installed. Please install it to get the version."
|
||||
}
|
||||
return version
|
||||
}
|
||||
|
||||
func getKubernetesVersion() string {
|
||||
version, err := ExecuteCommand("kubectl", "version", "--client", "--short")
|
||||
if err != nil {
|
||||
@ -99,20 +91,15 @@ func getGitVersion() string {
|
||||
|
||||
func main() {
|
||||
// red := color.New(color.FgRed).SprintFunc()
|
||||
green := color.New(color.FgGreen).SprintFunc()
|
||||
// green := color.New(color.FgGreen).SprintFunc()
|
||||
blue := color.New(color.FgBlue).SprintFunc()
|
||||
yellow := color.New(color.FgYellow).SprintFunc()
|
||||
|
||||
fmt.Println(green(printTime()))
|
||||
fmt.Println(yellow("# Diagnostic Tool Result\n"))
|
||||
// yellow := color.New(color.FgYellow).SprintFunc()
|
||||
fmt.Println(blue("## Go Version"))
|
||||
fmt.Println(getGoVersion())
|
||||
fmt.Println(blue("## Branch Type"))
|
||||
fmt.Println(getGitVersion())
|
||||
fmt.Println(blue("## Docker Version"))
|
||||
fmt.Println(getDockerVersion())
|
||||
fmt.Println(blue("## Docker Compose Version"))
|
||||
fmt.Println(getDockerComposeVersion())
|
||||
fmt.Println(blue("## Kubernetes Version"))
|
||||
fmt.Println(getKubernetesVersion())
|
||||
// fmt.Println(blue("## OpenIM Versions"))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user