mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-03 08:35:59 +08:00
feat(main): 🚀 Database Name Correction and S3 Module Int32 Overflow Fix with Go Routine Integration for Automated Checks and Script Optimization (#1799)
* feat: replace mongo database openIM_v3 to openim_v3 * openim-building-an-efficient-version-control-and-testing-workflow * feat: complete openim source deployment rpc start timeout * feat: optimize config Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * feat: add scripts format * feat: use scripts format code * fix cos and minio etc to typecheck * feat: scripts make verify check ci * fix: make file verify spelling * fix: make file verify spelling * Concurrent Type Checking and Cross-Platform Development in Go * feat: add copyright make lint and format * feat: add config examples file Signed-off-by: Xinwei Xiong <3293172751@qq.com> * feat: add config examples file Signed-off-by: Xinwei Xiong <3293172751@qq.com> --------- Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> Signed-off-by: Xinwei Xiong <3293172751@qq.com>
This commit is contained in:
+20
-20
@@ -30,12 +30,12 @@ openim::chat::validate() {
|
||||
openim::log::info "You can use 'scripts/install-chat.sh' to install a copy in third_party/."
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
# validate chat port is free
|
||||
local port_check_command
|
||||
if command -v ss &> /dev/null && ss -Version | grep 'iproute2' &> /dev/null; then
|
||||
port_check_command="ss"
|
||||
elif command -v netstat &>/dev/null; then
|
||||
elif command -v netstat &>/dev/null; then
|
||||
port_check_command="netstat"
|
||||
else
|
||||
openim::log::usage "unable to identify if chat is bound to port ${CHAT_PORT}. unable to find ss or netstat utilities."
|
||||
@@ -46,24 +46,24 @@ openim::chat::validate() {
|
||||
openim::log::usage "$(${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${CHAT_PORT:?}")"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
|
||||
# need set the env of "CHAT_UNSUPPORTED_ARCH" on unstable arch.
|
||||
arch=$(uname -m)
|
||||
if [[ $arch =~ arm* ]]; then
|
||||
export CHAT_UNSUPPORTED_ARCH=arm
|
||||
export CHAT_UNSUPPORTED_ARCH=arm
|
||||
fi
|
||||
# validate installed version is at least equal to minimum
|
||||
version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3)
|
||||
if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then
|
||||
export PATH="${OPENIM_ROOT}"/third_party/chat:${PATH}
|
||||
hash chat
|
||||
echo "${PATH}"
|
||||
version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3)
|
||||
if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then
|
||||
openim::log::usage "chat version ${CHAT_VERSION} or greater required."
|
||||
openim::log::info "You can use 'scripts/install-chat.sh' to install a copy in third_party/."
|
||||
exit 1
|
||||
fi
|
||||
export PATH="${OPENIM_ROOT}"/third_party/chat:${PATH}
|
||||
hash chat
|
||||
echo "${PATH}"
|
||||
version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3)
|
||||
if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then
|
||||
openim::log::usage "chat version ${CHAT_VERSION} or greater required."
|
||||
openim::log::info "You can use 'scripts/install-chat.sh' to install a copy in third_party/."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ openim::chat::version() {
|
||||
openim::chat::start() {
|
||||
# validate before running
|
||||
openim::chat::validate
|
||||
|
||||
|
||||
# Start chat
|
||||
CHAT_DIR=${CHAT_DIR:-$(mktemp -d 2>/dev/null || mktemp -d -t test-chat.XXXXXX)}
|
||||
if [[ -d "${ARTIFACTS:-}" ]]; then
|
||||
@@ -85,7 +85,7 @@ openim::chat::start() {
|
||||
openim::log::info "chat --advertise-client-urls ${OPENIM_INTEGRATION_CHAT_URL} --data-dir ${CHAT_DIR} --listen-client-urls http://${CHAT_HOST}:${CHAT_PORT} --log-level=${CHAT_LOGLEVEL} 2> \"${CHAT_LOGFILE}\" >/dev/null"
|
||||
chat --advertise-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --data-dir "${CHAT_DIR}" --listen-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --log-level="${CHAT_LOGLEVEL}" 2> "${CHAT_LOGFILE}" >/dev/null &
|
||||
CHAT_PID=$!
|
||||
|
||||
|
||||
echo "Waiting for chat to come up."
|
||||
openim::util::wait_for_url "${OPENIM_INTEGRATION_CHAT_URL}/health" "chat: " 0.25 80
|
||||
curl -fs -X POST "${OPENIM_INTEGRATION_CHAT_URL}/v3/kv/put" -d '{"key": "X3Rlc3Q=", "value": ""}'
|
||||
@@ -108,7 +108,7 @@ openim::chat::start_scraping() {
|
||||
}
|
||||
|
||||
openim::chat::scrape() {
|
||||
curl -s -S "${OPENIM_INTEGRATION_CHAT_URL}/metrics" > "${CHAT_SCRAPE_DIR}/next" && mv "${CHAT_SCRAPE_DIR}/next" "${CHAT_SCRAPE_DIR}/$(date +%s).scrape"
|
||||
curl -s -S "${OPENIM_INTEGRATION_CHAT_URL}/metrics" > "${CHAT_SCRAPE_DIR}/next" && mv "${CHAT_SCRAPE_DIR}/next" "${CHAT_SCRAPE_DIR}/$(date +%s).scrape"
|
||||
}
|
||||
|
||||
openim::chat::stop() {
|
||||
@@ -144,17 +144,17 @@ openim::chat::install() {
|
||||
(
|
||||
local os
|
||||
local arch
|
||||
|
||||
|
||||
os=$(openim::util::host_os)
|
||||
arch=$(openim::util::host_arch)
|
||||
|
||||
|
||||
cd "${OPENIM_ROOT}/third_party" || return 1
|
||||
if [[ $(readlink chat) == chat-v${CHAT_VERSION}-${os}-* ]]; then
|
||||
openim::log::info "chat v${CHAT_VERSION} already installed. To use:"
|
||||
openim::log::info "export PATH=\"$(pwd)/chat:\${PATH}\""
|
||||
return #already installed
|
||||
fi
|
||||
|
||||
|
||||
if [[ ${os} == "darwin" ]]; then
|
||||
download_file="chat-v${CHAT_VERSION}-${os}-${arch}.zip"
|
||||
url="https://github.com/chat-io/chat/releases/download/v${CHAT_VERSION}/${download_file}"
|
||||
@@ -162,7 +162,7 @@ openim::chat::install() {
|
||||
unzip -o "${download_file}"
|
||||
ln -fns "chat-v${CHAT_VERSION}-${os}-${arch}" chat
|
||||
rm "${download_file}"
|
||||
elif [[ ${os} == "linux" ]]; then
|
||||
elif [[ ${os} == "linux" ]]; then
|
||||
url="https://github.com/coreos/chat/releases/download/v${CHAT_VERSION}/chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz"
|
||||
download_file="chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz"
|
||||
openim::util::download_file "${url}" "${download_file}"
|
||||
|
||||
+56
-56
@@ -21,24 +21,24 @@
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
if [ -z "${COLOR_OPEN+x}" ]; then
|
||||
COLOR_OPEN=1
|
||||
COLOR_OPEN=1
|
||||
fi
|
||||
|
||||
# Function for colored echo
|
||||
openim::color::echo() {
|
||||
COLOR=$1
|
||||
[ $COLOR_OPEN -eq 1 ] && echo -e "${COLOR} $(date '+%Y-%m-%d %H:%M:%S') $@ ${COLOR_SUFFIX}"
|
||||
shift
|
||||
COLOR=$1
|
||||
[ $COLOR_OPEN -eq 1 ] && echo -e "${COLOR} $(date '+%Y-%m-%d %H:%M:%S') $@ ${COLOR_SUFFIX}"
|
||||
shift
|
||||
}
|
||||
|
||||
# Define color variables
|
||||
# --- Feature ---
|
||||
# --- Feature ---
|
||||
COLOR_NORMAL='\033[0m';COLOR_BOLD='\033[1m';COLOR_DIM='\033[2m';COLOR_UNDER='\033[4m';
|
||||
COLOR_ITALIC='\033[3m';COLOR_NOITALIC='\033[23m';COLOR_BLINK='\033[5m';
|
||||
COLOR_REVERSE='\033[7m';COLOR_CONCEAL='\033[8m';COLOR_NOBOLD='\033[22m';
|
||||
COLOR_NOUNDER='\033[24m';COLOR_NOBLINK='\033[25m';
|
||||
|
||||
# --- Front color ---
|
||||
# --- Front color ---
|
||||
COLOR_BLACK='\033[30m';
|
||||
COLOR_RED='\033[31m';
|
||||
COLOR_GREEN='\033[32m';
|
||||
@@ -48,13 +48,13 @@ COLOR_MAGENTA='\033[35m';
|
||||
COLOR_CYAN='\033[36m';
|
||||
COLOR_WHITE='\033[37m';
|
||||
|
||||
# --- background color ---
|
||||
# --- background color ---
|
||||
COLOR_BBLACK='\033[40m';COLOR_BRED='\033[41m';
|
||||
COLOR_BGREEN='\033[42m';COLOR_BYELLOW='\033[43m';
|
||||
COLOR_BBLUE='\033[44m';COLOR_BMAGENTA='\033[45m';
|
||||
COLOR_BCYAN='\033[46m';COLOR_BWHITE='\033[47m';
|
||||
|
||||
# --- Color definitions ---
|
||||
# --- Color definitions ---
|
||||
# Color definitions
|
||||
COLOR_SUFFIX="\033[0m" # End all colors and special effects
|
||||
BLACK_PREFIX="\033[30m" # Black prefix
|
||||
@@ -86,54 +86,54 @@ openim::color::print_color() {
|
||||
|
||||
# test functions
|
||||
openim::color::test() {
|
||||
echo "Starting the color tests..."
|
||||
|
||||
echo "Testing normal echo without color"
|
||||
openim::color::echo $COLOR_NORMAL "This is a normal text"
|
||||
|
||||
echo "Testing bold echo"
|
||||
openim::color::echo $COLOR_BOLD "This is bold text"
|
||||
|
||||
echo "Testing dim echo"
|
||||
openim::color::echo $COLOR_DIM "This is dim text"
|
||||
|
||||
echo "Testing underlined echo"
|
||||
openim::color::echo $COLOR_UNDER "This is underlined text"
|
||||
|
||||
echo "Testing italic echo"
|
||||
openim::color::echo $COLOR_ITALIC "This is italic text"
|
||||
|
||||
echo "Testing red color"
|
||||
openim::color::echo $COLOR_RED "This is red text"
|
||||
|
||||
echo "Testing green color"
|
||||
openim::color::echo $COLOR_GREEN "This is green text"
|
||||
|
||||
echo "Testing yellow color"
|
||||
openim::color::echo $COLOR_YELLOW "This is yellow text"
|
||||
|
||||
echo "Testing blue color"
|
||||
openim::color::echo $COLOR_BLUE "This is blue text"
|
||||
|
||||
echo "Testing magenta color"
|
||||
openim::color::echo $COLOR_MAGENTA "This is magenta text"
|
||||
|
||||
echo "Testing cyan color"
|
||||
openim::color::echo $COLOR_CYAN "This is cyan text"
|
||||
|
||||
echo "Testing black background"
|
||||
openim::color::echo $COLOR_BBLACK "This is text with black background"
|
||||
|
||||
echo "Testing red background"
|
||||
openim::color::echo $COLOR_BRED "This is text with red background"
|
||||
|
||||
echo "Testing green background"
|
||||
openim::color::echo $COLOR_BGREEN "This is text with green background"
|
||||
|
||||
echo "Testing blue background"
|
||||
openim::color::echo $COLOR_BBLUE "This is text with blue background"
|
||||
|
||||
echo "All tests completed!"
|
||||
echo "Starting the color tests..."
|
||||
|
||||
echo "Testing normal echo without color"
|
||||
openim::color::echo $COLOR_NORMAL "This is a normal text"
|
||||
|
||||
echo "Testing bold echo"
|
||||
openim::color::echo $COLOR_BOLD "This is bold text"
|
||||
|
||||
echo "Testing dim echo"
|
||||
openim::color::echo $COLOR_DIM "This is dim text"
|
||||
|
||||
echo "Testing underlined echo"
|
||||
openim::color::echo $COLOR_UNDER "This is underlined text"
|
||||
|
||||
echo "Testing italic echo"
|
||||
openim::color::echo $COLOR_ITALIC "This is italic text"
|
||||
|
||||
echo "Testing red color"
|
||||
openim::color::echo $COLOR_RED "This is red text"
|
||||
|
||||
echo "Testing green color"
|
||||
openim::color::echo $COLOR_GREEN "This is green text"
|
||||
|
||||
echo "Testing yellow color"
|
||||
openim::color::echo $COLOR_YELLOW "This is yellow text"
|
||||
|
||||
echo "Testing blue color"
|
||||
openim::color::echo $COLOR_BLUE "This is blue text"
|
||||
|
||||
echo "Testing magenta color"
|
||||
openim::color::echo $COLOR_MAGENTA "This is magenta text"
|
||||
|
||||
echo "Testing cyan color"
|
||||
openim::color::echo $COLOR_CYAN "This is cyan text"
|
||||
|
||||
echo "Testing black background"
|
||||
openim::color::echo $COLOR_BBLACK "This is text with black background"
|
||||
|
||||
echo "Testing red background"
|
||||
openim::color::echo $COLOR_BRED "This is text with red background"
|
||||
|
||||
echo "Testing green background"
|
||||
openim::color::echo $COLOR_BGREEN "This is text with green background"
|
||||
|
||||
echo "Testing blue background"
|
||||
openim::color::echo $COLOR_BBLUE "This is text with blue background"
|
||||
|
||||
echo "All tests completed!"
|
||||
}
|
||||
|
||||
# openim::color::test
|
||||
|
||||
+27
-27
@@ -21,24 +21,24 @@ ENABLE_LOGGING="${ENABLE_LOGGING:-true}"
|
||||
|
||||
# If OPENIM_OUTPUT is not set, set it to the default value
|
||||
if [ -z "${OPENIM_OUTPUT+x}" ]; then
|
||||
OPENIM_OUTPUT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../_output" && pwd -P)"
|
||||
OPENIM_OUTPUT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../../_output" && pwd -P)"
|
||||
fi
|
||||
|
||||
# Set the log file path
|
||||
LOG_FILE="${OPENIM_OUTPUT}/logs/openim_$(date '+%Y%m%d').log"
|
||||
|
||||
if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then
|
||||
mkdir -p "${OPENIM_OUTPUT}/logs"
|
||||
touch "$LOG_FILE"
|
||||
mkdir -p "${OPENIM_OUTPUT}/logs"
|
||||
touch "$LOG_FILE"
|
||||
fi
|
||||
|
||||
# Define the logging function
|
||||
function echo_log() {
|
||||
if $ENABLE_LOGGING; then
|
||||
echo -e "$@" | tee -a "${LOG_FILE}"
|
||||
else
|
||||
echo -e "$@"
|
||||
fi
|
||||
if $ENABLE_LOGGING; then
|
||||
echo -e "$@" | tee -a "${LOG_FILE}"
|
||||
else
|
||||
echo -e "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
# MAX_LOG_SIZE=10485760 # 10MB
|
||||
@@ -50,11 +50,11 @@ function echo_log() {
|
||||
# Borrowed from https://gist.github.com/ahendrix/7030300
|
||||
openim::log::errexit() {
|
||||
local err="${PIPESTATUS[*]}"
|
||||
|
||||
|
||||
# If the shell we are in doesn't have errexit set (common in subshells) then
|
||||
# don't dump stacks.
|
||||
set +o | grep -qe "-o errexit" || return
|
||||
|
||||
|
||||
set +o xtrace
|
||||
local code="${1:-1}"
|
||||
# Print out the stack trace described by $function_stack
|
||||
@@ -73,7 +73,7 @@ openim::log::install_errexit() {
|
||||
# trap ERR to provide an error handler whenever a command exits nonzero this
|
||||
# is a more verbose version of set -o errexit
|
||||
trap 'openim::log::errexit' ERR
|
||||
|
||||
|
||||
# setting errtrace allows our ERR trap handler to be propagated to functions,
|
||||
# expansions and subshells
|
||||
set -o errtrace
|
||||
@@ -110,7 +110,7 @@ openim::log::error_exit() {
|
||||
local code="${2:-1}"
|
||||
local stack_skip="${3:-0}"
|
||||
stack_skip=$((stack_skip + 1))
|
||||
|
||||
|
||||
if [[ ${OPENIM_VERBOSE} -ge 4 ]]; then
|
||||
local source_file=${BASH_SOURCE[${stack_skip}]}
|
||||
local source_line=${BASH_LINENO[$((stack_skip - 1))]}
|
||||
@@ -118,12 +118,12 @@ openim::log::error_exit() {
|
||||
[[ -z ${1-} ]] || {
|
||||
echo_log " ${1}" >&2
|
||||
}
|
||||
|
||||
|
||||
openim::log::stack ${stack_skip}
|
||||
|
||||
|
||||
echo_log "Exiting with status ${code}" >&2
|
||||
fi
|
||||
|
||||
|
||||
exit "${code}"
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ openim::log::usage_from_stdin() {
|
||||
while read -r line; do
|
||||
messages+=("${line}")
|
||||
done
|
||||
|
||||
|
||||
openim::log::usage "${messages[@]}"
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ openim::log::info() {
|
||||
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
for message; do
|
||||
echo_log "${message}"
|
||||
done
|
||||
@@ -181,7 +181,7 @@ openim::log::info_from_stdin() {
|
||||
while read -r line; do
|
||||
messages+=("${line}")
|
||||
done
|
||||
|
||||
|
||||
openim::log::info "${messages[@]}"
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ openim::log::status() {
|
||||
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
timestamp=$(date +"[%m%d %H:%M:%S]")
|
||||
echo_log "+++ ${timestamp} ${1}"
|
||||
shift
|
||||
@@ -203,20 +203,20 @@ openim::log::status() {
|
||||
openim::log::success() {
|
||||
local V="${V:-0}"
|
||||
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
|
||||
return
|
||||
return
|
||||
fi
|
||||
timestamp=$(date +"%m%d %H:%M:%S")
|
||||
echo_log -e "${COLOR_GREEN}[success ${timestamp}] ${COLOR_SUFFIX}==> " "$@"
|
||||
}
|
||||
|
||||
function openim::log::test_log() {
|
||||
echo_log "test log"
|
||||
openim::log::info "openim::log::info"
|
||||
openim::log::progress "openim::log::progress"
|
||||
openim::log::status "openim::log::status"
|
||||
openim::log::success "openim::log::success"
|
||||
openim::log::error "openim::log::error"
|
||||
openim::log::error_exit "openim::log::error_exit"
|
||||
echo_log "test log"
|
||||
openim::log::info "openim::log::info"
|
||||
openim::log::progress "openim::log::progress"
|
||||
openim::log::status "openim::log::status"
|
||||
openim::log::success "openim::log::success"
|
||||
openim::log::error "openim::log::error"
|
||||
openim::log::error_exit "openim::log::error_exit"
|
||||
}
|
||||
|
||||
# openim::log::test_log
|
||||
+25
-25
@@ -46,11 +46,11 @@ OPENIM_BUILD_CONFORMANCE=${OPENIM_BUILD_CONFORMANCE:-y}
|
||||
OPENIM_BUILD_PULL_LATEST_IMAGES=${OPENIM_BUILD_PULL_LATEST_IMAGES:-y}
|
||||
|
||||
if [ -z "${OPENIM_ROOT}" ]; then
|
||||
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
|
||||
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
|
||||
fi
|
||||
|
||||
if [ -z "${TOOLS_DIR}" ]; then
|
||||
TOOLS_DIR="${OPENIM_ROOT}/_output/tools"
|
||||
TOOLS_DIR="${OPENIM_ROOT}/_output/tools"
|
||||
fi
|
||||
|
||||
# Validate a ci version
|
||||
@@ -77,10 +77,10 @@ function openim::release::parse_and_validate_ci_version() {
|
||||
openim::log::error "Invalid ci version: '${version}', must match regex ${version_regex}"
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
# The VERSION variables are used when this file is sourced, hence
|
||||
# the shellcheck SC2034 'appears unused' warning is to be ignored.
|
||||
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
VERSION_MAJOR="${BASH_REMATCH[1]}"
|
||||
# shellcheck disable=SC2034
|
||||
@@ -115,7 +115,7 @@ function openim::release::package_tarballs() {
|
||||
openim::release::package_openim_manifests_tarball &
|
||||
openim::release::package_server_tarballs &
|
||||
openim::util::wait-for-jobs || { openim::log::error "previous tarball phase failed"; return 1; }
|
||||
|
||||
|
||||
openim::release::package_final_tarball & # _final depends on some of the previous phases
|
||||
openim::util::wait-for-jobs || { openim::log::error "previous tarball phase failed"; return 1; }
|
||||
}
|
||||
@@ -143,24 +143,24 @@ function openim::release::package_src_tarball() {
|
||||
git archive -o "${src_tarball}" HEAD
|
||||
else
|
||||
find "${OPENIM_ROOT}" -mindepth 1 -maxdepth 1 \
|
||||
! \( \
|
||||
\( -path "${OPENIM_ROOT}"/_\* -o \
|
||||
-path "${OPENIM_ROOT}"/.git\* -o \
|
||||
-path "${OPENIM_ROOT}"/.github\* -o \
|
||||
-path "${OPENIM_ROOT}"/components\* -o \
|
||||
-path "${OPENIM_ROOT}"/logs\* -o \
|
||||
-path "${OPENIM_ROOT}"/.gitignore\* -o \
|
||||
-path "${OPENIM_ROOT}"/.gsemver.yml\* -o \
|
||||
-path "${OPENIM_ROOT}"/.config\* -o \
|
||||
-path "${OPENIM_ROOT}"/.chglog\* -o \
|
||||
-path "${OPENIM_ROOT}"/.gitlint -o \
|
||||
-path "${OPENIM_ROOT}"/.golangci.yml -o \
|
||||
-path "${OPENIM_ROOT}"/build/goreleaser.yaml -o \
|
||||
-path "${OPENIM_ROOT}"/.note.md -o \
|
||||
-path "${OPENIM_ROOT}"/.todo.md \
|
||||
\) -prune \
|
||||
\) -print0 \
|
||||
| "${TAR}" czf "${src_tarball}" --transform "s|${OPENIM_ROOT#/*}|openim|" --null -T -
|
||||
! \( \
|
||||
\( -path "${OPENIM_ROOT}"/_\* -o \
|
||||
-path "${OPENIM_ROOT}"/.git\* -o \
|
||||
-path "${OPENIM_ROOT}"/.github\* -o \
|
||||
-path "${OPENIM_ROOT}"/components\* -o \
|
||||
-path "${OPENIM_ROOT}"/logs\* -o \
|
||||
-path "${OPENIM_ROOT}"/.gitignore\* -o \
|
||||
-path "${OPENIM_ROOT}"/.gsemver.yml\* -o \
|
||||
-path "${OPENIM_ROOT}"/.config\* -o \
|
||||
-path "${OPENIM_ROOT}"/.chglog\* -o \
|
||||
-path "${OPENIM_ROOT}"/.gitlint -o \
|
||||
-path "${OPENIM_ROOT}"/.golangci.yml -o \
|
||||
-path "${OPENIM_ROOT}"/build/goreleaser.yaml -o \
|
||||
-path "${OPENIM_ROOT}"/.note.md -o \
|
||||
-path "${OPENIM_ROOT}"/.todo.md \
|
||||
\) -prune \
|
||||
\) -print0 \
|
||||
| "${TAR}" czf "${src_tarball}" --transform "s|${OPENIM_ROOT#/*}|openim|" --null -T -
|
||||
fi
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ function openim::release::package_src_tarball() {
|
||||
function openim::release::package_server_tarballs() {
|
||||
# Find all of the built client binaries
|
||||
local long_platforms=("${LOCAL_OUTPUT_BINPATH}"/*/*)
|
||||
|
||||
|
||||
if [[ -n ${OPENIM_BUILD_PLATFORMS-} ]]; then
|
||||
read -ra long_platforms <<< "${OPENIM_BUILD_PLATFORMS}"
|
||||
fi
|
||||
@@ -636,7 +636,7 @@ function openim::release::github_release() {
|
||||
for file in ${RELEASE_TARS}/*.tar.gz; do
|
||||
if [[ -f "$file" ]]; then
|
||||
filename=$(basename "$file")
|
||||
openim::log::info "Update file ${filename} to release vertion ${OPENIM_GIT_VERSION}"
|
||||
openim::log::info "Update file ${filename} to release vertion ${OPENIM_GIT_VERSION}"
|
||||
${TOOLS_DIR}/github-release upload \
|
||||
--user ${OPENIM_GITHUB_ORG} \
|
||||
--repo ${OPENIM_GITHUB_REPO} \
|
||||
|
||||
+240
-240
@@ -30,27 +30,27 @@ function openim:util::setup_ssh_key_copy() {
|
||||
local hosts_file="$1"
|
||||
local username="${2:-root}"
|
||||
local password="${3:-123}"
|
||||
|
||||
|
||||
local sshkey_file=~/.ssh/id_rsa.pub
|
||||
|
||||
# check sshkey file
|
||||
|
||||
# check sshkey file
|
||||
if [[ ! -e $sshkey_file ]]; then
|
||||
expect -c "
|
||||
spawn ssh-keygen -t rsa
|
||||
expect \"Enter*\" { send \"\n\"; exp_continue; }
|
||||
"
|
||||
fi
|
||||
|
||||
|
||||
# get hosts list
|
||||
local hosts=$(awk '/^[^#]/ {print $1}' "${hosts_file}")
|
||||
|
||||
|
||||
ssh_key_copy() {
|
||||
local target=$1
|
||||
|
||||
|
||||
# delete history
|
||||
sed -i "/$target/d" ~/.ssh/known_hosts
|
||||
|
||||
# copy key
|
||||
|
||||
# copy key
|
||||
expect -c "
|
||||
set timeout 100
|
||||
spawn ssh-copy-id $username@$target
|
||||
@@ -62,14 +62,14 @@ function openim:util::setup_ssh_key_copy() {
|
||||
expect eof
|
||||
"
|
||||
}
|
||||
|
||||
|
||||
# auto sshkey pair
|
||||
for host in $hosts; do
|
||||
if ! ping -i 0.2 -c 3 -W 1 "$host" > /dev/null 2>&1; then
|
||||
echo "[ERROR]: Can't connect $host"
|
||||
continue
|
||||
fi
|
||||
|
||||
|
||||
local host_entry=$(awk "/$host/"'{print $1, $2}' /etc/hosts)
|
||||
if [[ $host_entry ]]; then
|
||||
local hostaddr=$(echo "$host_entry" | awk '{print $1}')
|
||||
@@ -102,7 +102,7 @@ openim::util::array_contains() {
|
||||
for element; do
|
||||
if [[ "${element}" == "${search}" ]]; then
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
done
|
||||
return 1
|
||||
}
|
||||
@@ -113,12 +113,12 @@ openim::util::wait_for_url() {
|
||||
local wait=${3:-1}
|
||||
local times=${4:-30}
|
||||
local maxtime=${5:-1}
|
||||
|
||||
|
||||
command -v curl >/dev/null || {
|
||||
openim::log::usage "curl must be installed"
|
||||
exit 1
|
||||
}
|
||||
|
||||
|
||||
local i
|
||||
for i in $(seq 1 "${times}"); do
|
||||
local out
|
||||
@@ -156,20 +156,20 @@ openim::util::trap_add() {
|
||||
local trap_add_cmd
|
||||
trap_add_cmd=$1
|
||||
shift
|
||||
|
||||
|
||||
for trap_add_name in "$@"; do
|
||||
local existing_cmd
|
||||
local new_cmd
|
||||
|
||||
|
||||
# Grab the currently defined trap commands for this trap
|
||||
existing_cmd=$(trap -p "${trap_add_name}" | awk -F"'" '{print $2}')
|
||||
|
||||
|
||||
if [[ -z "${existing_cmd}" ]]; then
|
||||
new_cmd="${trap_add_cmd}"
|
||||
else
|
||||
new_cmd="${trap_add_cmd};${existing_cmd}"
|
||||
fi
|
||||
|
||||
|
||||
# Assign the test. Disable the shellcheck warning telling that trap
|
||||
# commands should be single quoted to avoid evaluating them at this
|
||||
# point instead evaluating them at run time. The logic of adding new
|
||||
@@ -200,14 +200,14 @@ openim::util::host_os() {
|
||||
case "$(uname -s)" in
|
||||
Darwin)
|
||||
host_os=darwin
|
||||
;;
|
||||
;;
|
||||
Linux)
|
||||
host_os=linux
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
openim::log::error "Unsupported host OS. Must be Linux or Mac OS X."
|
||||
exit 1
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
echo "${host_os}"
|
||||
}
|
||||
@@ -217,70 +217,70 @@ openim::util::host_arch() {
|
||||
case "$(uname -m)" in
|
||||
x86_64*)
|
||||
host_arch=amd64
|
||||
;;
|
||||
;;
|
||||
i?86_64*)
|
||||
host_arch=amd64
|
||||
;;
|
||||
;;
|
||||
amd64*)
|
||||
host_arch=amd64
|
||||
;;
|
||||
;;
|
||||
aarch64*)
|
||||
host_arch=arm64
|
||||
;;
|
||||
;;
|
||||
arm64*)
|
||||
host_arch=arm64
|
||||
;;
|
||||
;;
|
||||
arm*)
|
||||
host_arch=arm
|
||||
;;
|
||||
;;
|
||||
i?86*)
|
||||
host_arch=x86
|
||||
;;
|
||||
;;
|
||||
s390x*)
|
||||
host_arch=s390x
|
||||
;;
|
||||
;;
|
||||
ppc64le*)
|
||||
host_arch=ppc64le
|
||||
;;
|
||||
;;
|
||||
*)
|
||||
openim::log::error "Unsupported host arch. Must be x86_64, 386, arm, arm64, s390x or ppc64le."
|
||||
exit 1
|
||||
;;
|
||||
;;
|
||||
esac
|
||||
echo "${host_arch}"
|
||||
}
|
||||
|
||||
# Define a bash function to check the versions of Docker and Docker Compose
|
||||
openim::util::check_docker_and_compose_versions() {
|
||||
# Define the required versions of Docker and Docker Compose
|
||||
required_docker_version="20.10.0"
|
||||
required_compose_version="2.0"
|
||||
|
||||
# Get the currently installed Docker version
|
||||
installed_docker_version=$(docker --version | awk '{print $3}' | sed 's/,//')
|
||||
|
||||
# Check if the installed Docker version matches the required version
|
||||
if [[ "$installed_docker_version" < "$required_docker_version" ]]; then
|
||||
echo "Docker version mismatch. Installed: $installed_docker_version, Required: $required_docker_version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if the docker compose sub-command is available
|
||||
if ! docker compose version &> /dev/null; then
|
||||
echo "Docker does not support the docker compose sub-command"
|
||||
echo "You need to upgrade Docker to the right version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get the currently installed Docker Compose version
|
||||
installed_compose_version=$(docker compose version --short)
|
||||
|
||||
# Check if the installed Docker Compose version matches the required version
|
||||
if [[ "$installed_compose_version" < "$required_compose_version" ]]; then
|
||||
echo "Docker Compose version mismatch. Installed: $installed_compose_version, Required: $required_compose_version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Define the required versions of Docker and Docker Compose
|
||||
required_docker_version="20.10.0"
|
||||
required_compose_version="2.0"
|
||||
|
||||
# Get the currently installed Docker version
|
||||
installed_docker_version=$(docker --version | awk '{print $3}' | sed 's/,//')
|
||||
|
||||
# Check if the installed Docker version matches the required version
|
||||
if [[ "$installed_docker_version" < "$required_docker_version" ]]; then
|
||||
echo "Docker version mismatch. Installed: $installed_docker_version, Required: $required_docker_version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check if the docker compose sub-command is available
|
||||
if ! docker compose version &> /dev/null; then
|
||||
echo "Docker does not support the docker compose sub-command"
|
||||
echo "You need to upgrade Docker to the right version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Get the currently installed Docker Compose version
|
||||
installed_compose_version=$(docker compose version --short)
|
||||
|
||||
# Check if the installed Docker Compose version matches the required version
|
||||
if [[ "$installed_compose_version" < "$required_compose_version" ]]; then
|
||||
echo "Docker Compose version mismatch. Installed: $installed_compose_version, Required: $required_compose_version"
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -292,80 +292,80 @@ openim::util::check_docker_and_compose_versions() {
|
||||
# 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.
|
||||
local not_started=()
|
||||
|
||||
# An array to collect information about processes that are running.
|
||||
local started=()
|
||||
|
||||
openim::log::info "Checking ports: $*"
|
||||
# Iterate over each given port.
|
||||
for port in "$@"; do
|
||||
# Initialize variables
|
||||
# Check the OS and use the appropriate command
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
if command -v ss > /dev/null 2>&1; then
|
||||
info=$(ss -ltnp | grep ":$port" || true)
|
||||
else
|
||||
info=$(netstat -ltnp | grep ":$port" || true)
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# For macOS, use lsof
|
||||
info=$(lsof -P -i:"$port" | grep "LISTEN" || true)
|
||||
fi
|
||||
|
||||
# Check if any process is using the port
|
||||
if [[ -z $info ]]; then
|
||||
not_started+=($port)
|
||||
else
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Extract relevant details for Linux: Process Name, PID, and FD.
|
||||
details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p')
|
||||
command=$(echo $details | awk '{print $1}')
|
||||
pid=$(echo $details | awk '{print $2}')
|
||||
fd=$(echo $details | awk '{print $3}')
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# Handle extraction for macOS
|
||||
pid=$(echo $info | awk '{print $2}' | cut -d'/' -f1)
|
||||
command=$(ps -p $pid -o comm= | xargs basename)
|
||||
fd=$(echo $info | awk '{print $4}' | cut -d'/' -f1)
|
||||
fi
|
||||
|
||||
# Get the start time of the process using the PID
|
||||
if [[ -z $pid ]]; then
|
||||
start_time="N/A"
|
||||
else
|
||||
start_time=$(ps -p $pid -o lstart=)
|
||||
fi
|
||||
|
||||
started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time")
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information about ports whose processes are not running.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "\n### Not started ports:"
|
||||
for port in "${not_started[@]}"; do
|
||||
openim::log::error "Port $port is not started."
|
||||
done
|
||||
# An array to collect ports of processes that are not running.
|
||||
local not_started=()
|
||||
|
||||
# An array to collect information about processes that are running.
|
||||
local started=()
|
||||
|
||||
openim::log::info "Checking ports: $*"
|
||||
# Iterate over each given port.
|
||||
for port in "$@"; do
|
||||
# Initialize variables
|
||||
# Check the OS and use the appropriate command
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
if command -v ss > /dev/null 2>&1; then
|
||||
info=$(ss -ltnp | grep ":$port" || true)
|
||||
else
|
||||
info=$(netstat -ltnp | grep ":$port" || true)
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# For macOS, use lsof
|
||||
info=$(lsof -P -i:"$port" | grep "LISTEN" || true)
|
||||
fi
|
||||
|
||||
# Print information about ports whose processes are running.
|
||||
if [[ ${#started[@]} -ne 0 ]]; then
|
||||
openim::log::info "\n### 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
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
|
||||
# Check if any process is using the port
|
||||
if [[ -z $info ]]; then
|
||||
not_started+=($port)
|
||||
else
|
||||
openim::log::success "All specified processes are running."
|
||||
return 0
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Extract relevant details for Linux: Process Name, PID, and FD.
|
||||
details=$(echo $info | sed -n 's/.*users:(("\([^"]*\)",pid=\([^,]*\),fd=\([^)]*\))).*/\1 \2 \3/p')
|
||||
command=$(echo $details | awk '{print $1}')
|
||||
pid=$(echo $details | awk '{print $2}')
|
||||
fd=$(echo $details | awk '{print $3}')
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# Handle extraction for macOS
|
||||
pid=$(echo $info | awk '{print $2}' | cut -d'/' -f1)
|
||||
command=$(ps -p $pid -o comm= | xargs basename)
|
||||
fd=$(echo $info | awk '{print $4}' | cut -d'/' -f1)
|
||||
fi
|
||||
|
||||
# Get the start time of the process using the PID
|
||||
if [[ -z $pid ]]; then
|
||||
start_time="N/A"
|
||||
else
|
||||
start_time=$(ps -p $pid -o lstart=)
|
||||
fi
|
||||
|
||||
started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time")
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information about ports whose processes are not running.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "\n### 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
|
||||
openim::log::info "\n### 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
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All specified processes are running."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# set +o errexit
|
||||
@@ -381,75 +381,75 @@ openim::util::check_ports() {
|
||||
# openim::util::check_process_names nginx mysql redis
|
||||
# The function returns a status of 1 if any of the processes is not running.
|
||||
openim::util::check_process_names() {
|
||||
# Function to get the port of a process
|
||||
get_port() {
|
||||
local pid=$1
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://'
|
||||
else
|
||||
echo "Unsupported OS"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Arrays to collect details of processes
|
||||
local not_started=()
|
||||
local started=()
|
||||
|
||||
openim::log::info "Checking processes: $*"
|
||||
# Iterate over each given process name
|
||||
for process_name in "$@"; do
|
||||
# Use `pgrep` to find process IDs related to the given process name
|
||||
local pids=($(pgrep -f $process_name))
|
||||
|
||||
# Check if any process IDs were found
|
||||
if [[ ${#pids[@]} -eq 0 ]]; then
|
||||
not_started+=($process_name)
|
||||
else
|
||||
# If there are PIDs, loop through each one
|
||||
for pid in "${pids[@]}"; do
|
||||
local command=$(ps -p $pid -o cmd=)
|
||||
local start_time=$(ps -p $pid -o lstart=)
|
||||
local port=$(get_port $pid)
|
||||
|
||||
# Check if port information was found for the PID
|
||||
if [[ -z $port ]]; then
|
||||
port="N/A"
|
||||
fi
|
||||
|
||||
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "Not started processes:"
|
||||
for process_name in "${not_started[@]}"; do
|
||||
openim::log::error "Process $process_name is not started."
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${#started[@]} -ne 0 ]]; then
|
||||
echo
|
||||
openim::log::info "Started processes:"
|
||||
for info in "${started[@]}"; do
|
||||
openim::log::info "$info"
|
||||
done
|
||||
fi
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
# Function to get the port of a process
|
||||
get_port() {
|
||||
local pid=$1
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
# Linux
|
||||
ss -ltnp 2>/dev/null | grep $pid | awk '{print $4}' | cut -d ':' -f2
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# macOS
|
||||
lsof -nP -iTCP -sTCP:LISTEN -a -p $pid | awk 'NR>1 {print $9}' | sed 's/.*://'
|
||||
else
|
||||
openim::log::success "All processes are running."
|
||||
return 0
|
||||
echo "Unsupported OS"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Arrays to collect details of processes
|
||||
local not_started=()
|
||||
local started=()
|
||||
|
||||
openim::log::info "Checking processes: $*"
|
||||
# Iterate over each given process name
|
||||
for process_name in "$@"; do
|
||||
# Use `pgrep` to find process IDs related to the given process name
|
||||
local pids=($(pgrep -f $process_name))
|
||||
|
||||
# Check if any process IDs were found
|
||||
if [[ ${#pids[@]} -eq 0 ]]; then
|
||||
not_started+=($process_name)
|
||||
else
|
||||
# If there are PIDs, loop through each one
|
||||
for pid in "${pids[@]}"; do
|
||||
local command=$(ps -p $pid -o cmd=)
|
||||
local start_time=$(ps -p $pid -o lstart=)
|
||||
local port=$(get_port $pid)
|
||||
|
||||
# Check if port information was found for the PID
|
||||
if [[ -z $port ]]; then
|
||||
port="N/A"
|
||||
fi
|
||||
|
||||
started+=("Process $process_name - Command: $command, PID: $pid, Port: $port, Start time: $start_time")
|
||||
done
|
||||
fi
|
||||
done
|
||||
|
||||
# Print information
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
openim::log::info "Not started processes:"
|
||||
for process_name in "${not_started[@]}"; do
|
||||
openim::log::error "Process $process_name is not started."
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${#started[@]} -ne 0 ]]; then
|
||||
echo
|
||||
openim::log::info "Started processes:"
|
||||
for info in "${started[@]}"; do
|
||||
openim::log::info "$info"
|
||||
done
|
||||
fi
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All processes are running."
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# openim::util::check_process_names docker-pr
|
||||
@@ -462,30 +462,30 @@ openim::util::check_process_names() {
|
||||
# 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.
|
||||
local not_stopped=()
|
||||
|
||||
# An array to collect information about processes that were stopped.
|
||||
local stopped=()
|
||||
|
||||
openim::log::info "Stopping services on ports: $*"
|
||||
# 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.
|
||||
while read -r line; do
|
||||
local pid=$(echo $line | awk '{print $2}')
|
||||
|
||||
# Try to stop the service by killing its process.
|
||||
if kill -TERM $pid; then
|
||||
stopped+=($port)
|
||||
else
|
||||
not_stopped+=($port)
|
||||
fi
|
||||
# An array to collect ports of processes that couldn't be stopped.
|
||||
local not_stopped=()
|
||||
|
||||
# An array to collect information about processes that were stopped.
|
||||
local stopped=()
|
||||
|
||||
openim::log::info "Stopping services on ports: $*"
|
||||
# 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.
|
||||
while read -r line; do
|
||||
local pid=$(echo $line | awk '{print $2}')
|
||||
|
||||
# Try to stop the service by killing its process.
|
||||
if kill -TERM $pid; then
|
||||
stopped+=($port)
|
||||
else
|
||||
not_stopped+=($port)
|
||||
fi
|
||||
done <<< "$info"
|
||||
fi
|
||||
done
|
||||
@@ -519,7 +519,7 @@ openim::util::stop_services_on_ports() {
|
||||
# nc -l -p 12345
|
||||
# nc -l -p 123456
|
||||
# ps -ef | grep "nc -l"
|
||||
# openim::util::stop_services_on_ports 1234 12345
|
||||
# openim::util::stop_services_on_ports 1234 12345
|
||||
|
||||
|
||||
# The `openim::util::stop_services_with_name` function stops services with specified names.
|
||||
@@ -1086,7 +1086,7 @@ function openim::util::ensure-install-nginx {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for port in 80
|
||||
for port in "80"
|
||||
do
|
||||
if echo |telnet 127.0.0.1 $port 2>&1|grep refused &>/dev/null;then
|
||||
exit 1
|
||||
@@ -1263,7 +1263,7 @@ function openim:util::setup_ssh_key_copy() {
|
||||
|
||||
local sshkey_file=~/.ssh/id_rsa.pub
|
||||
|
||||
# check sshkey file
|
||||
# check sshkey file
|
||||
if [[ ! -e $sshkey_file ]]; then
|
||||
expect -c "
|
||||
spawn ssh-keygen -t rsa
|
||||
@@ -1280,7 +1280,7 @@ function openim:util::setup_ssh_key_copy() {
|
||||
# delete history
|
||||
sed -i "/$target/d" ~/.ssh/known_hosts
|
||||
|
||||
# copy key
|
||||
# copy key
|
||||
expect -c "
|
||||
set timeout 100
|
||||
spawn ssh-copy-id $username@$target
|
||||
@@ -1571,7 +1571,7 @@ openim::util::check_ports() {
|
||||
else
|
||||
start_time=$(ps -p $pid -o lstart=)
|
||||
fi
|
||||
|
||||
|
||||
started+=("Port $port - Command: $command, PID: $pid, FD: $fd, Started: $start_time")
|
||||
fi
|
||||
done
|
||||
@@ -1639,7 +1639,7 @@ openim::util::check_process_names() {
|
||||
for process_name in "$@"; do
|
||||
# Use `pgrep` to find process IDs related to the given process name
|
||||
local pids=($(pgrep -f $process_name))
|
||||
|
||||
|
||||
# Check if any process IDs were found
|
||||
if [[ ${#pids[@]} -eq 0 ]]; then
|
||||
not_started+=($process_name)
|
||||
@@ -1713,7 +1713,7 @@ openim::util::stop_services_on_ports() {
|
||||
# Extract the Process ID.
|
||||
while read -r line; do
|
||||
local pid=$(echo $line | awk '{print $2}')
|
||||
|
||||
|
||||
# Try to stop the service by killing its process.
|
||||
if kill -TERM $pid; then
|
||||
stopped+=($port)
|
||||
@@ -1753,7 +1753,7 @@ openim::util::stop_services_on_ports() {
|
||||
# nc -l -p 12345
|
||||
# nc -l -p 123456
|
||||
# ps -ef | grep "nc -l"
|
||||
# openim::util::stop_services_on_ports 1234 12345
|
||||
# openim::util::stop_services_on_ports 1234 12345
|
||||
|
||||
|
||||
# The `openim::util::stop_services_with_name` function stops services with specified names.
|
||||
@@ -2320,7 +2320,7 @@ function openim::util::ensure-install-nginx {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for port in 80
|
||||
for port in "80"
|
||||
do
|
||||
if echo |telnet 127.0.0.1 $port 2>&1|grep refused &>/dev/null;then
|
||||
exit 1
|
||||
@@ -2467,7 +2467,7 @@ function openim::util::desc() {
|
||||
}
|
||||
|
||||
function openim::util:run::prompt() {
|
||||
echo -n "$yellow\$ $reset"
|
||||
echo -n "${yellow}\$ ${reset}"
|
||||
}
|
||||
|
||||
started=""
|
||||
@@ -2488,7 +2488,7 @@ function openim::util::run() {
|
||||
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||
rate=1000
|
||||
fi
|
||||
echo "$green$1$reset" | pv -qL $rate
|
||||
echo "${green}$1${reset}" | pv -qL "$rate"
|
||||
if [ -n "$DEMO_RUN_FAST" ]; then
|
||||
sleep 0.5
|
||||
fi
|
||||
@@ -2516,7 +2516,7 @@ function openim::util::run::relative() {
|
||||
|
||||
# This function retrieves the IP address of the current server.
|
||||
# It primarily uses the `curl` command to fetch the public IP address from ifconfig.me.
|
||||
# If curl or the service is not available, it falls back
|
||||
# If curl or the service is not available, it falls back
|
||||
# to the internal IP address provided by the hostname command.
|
||||
# TODO: If a delay is found, the delay needs to be addressed
|
||||
function openim::util::get_server_ip() {
|
||||
@@ -2524,7 +2524,7 @@ function openim::util::get_server_ip() {
|
||||
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 | sed 's/"//g' | tr -d '\n')
|
||||
|
||||
|
||||
# Check if IP retrieval was successful
|
||||
if [[ -z "$IP" ]]; then
|
||||
# If not, get the internal IP address
|
||||
@@ -2534,7 +2534,7 @@ function openim::util::get_server_ip() {
|
||||
# If curl is not available, get the internal IP address
|
||||
IP=$(ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
|
||||
fi
|
||||
|
||||
|
||||
# Return the fetched IP address
|
||||
echo "$IP"
|
||||
}
|
||||
@@ -2580,7 +2580,7 @@ function openim::util::set_max_fd() {
|
||||
if [ "$desired_fd" = "maximum" ] || [ "$desired_fd" = "max" ]; then
|
||||
desired_fd="$max_fd_limit"
|
||||
fi
|
||||
|
||||
|
||||
# Check if desired_fd is less than or equal to max_fd_limit.
|
||||
if [ "$desired_fd" -le "$max_fd_limit" ]; then
|
||||
ulimit -n "$desired_fd"
|
||||
@@ -2696,7 +2696,7 @@ function openim::util::run::relative() {
|
||||
|
||||
# This function retrieves the IP address of the current server.
|
||||
# It primarily uses the `curl` command to fetch the public IP address from ifconfig.me.
|
||||
# If curl or the service is not available, it falls back
|
||||
# If curl or the service is not available, it falls back
|
||||
# to the internal IP address provided by the hostname command.
|
||||
# TODO: If a delay is found, the delay needs to be addressed
|
||||
function openim::util::get_server_ip() {
|
||||
@@ -2704,7 +2704,7 @@ function openim::util::get_server_ip() {
|
||||
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 | sed 's/"//g' | tr -d '\n')
|
||||
|
||||
|
||||
# Check if IP retrieval was successful
|
||||
if [[ -z "$IP" ]]; then
|
||||
# If not, get the internal IP address
|
||||
@@ -2714,7 +2714,7 @@ function openim::util::get_server_ip() {
|
||||
# If curl is not available, get the internal IP address
|
||||
IP=$(ip addr show | grep 'inet ' | grep -v 127.0.0.1 | awk '{print $2}' | cut -d'/' -f1 | head -n 1)
|
||||
fi
|
||||
|
||||
|
||||
# Return the fetched IP address
|
||||
echo "$IP"
|
||||
}
|
||||
@@ -2760,7 +2760,7 @@ function openim::util::set_max_fd() {
|
||||
if [ "$desired_fd" = "maximum" ] || [ "$desired_fd" = "max" ]; then
|
||||
desired_fd="$max_fd_limit"
|
||||
fi
|
||||
|
||||
|
||||
# Check if desired_fd is less than or equal to max_fd_limit.
|
||||
if [ "$desired_fd" -le "$max_fd_limit" ]; then
|
||||
ulimit -n "$desired_fd"
|
||||
|
||||
+14
-14
@@ -12,7 +12,7 @@
|
||||
# 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.
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Version management helpers. These functions help to set, save and load the
|
||||
# following variables:
|
||||
@@ -35,7 +35,7 @@ openim::version::get_version_vars() {
|
||||
openim::version::load_version_vars "${OPENIM_GIT_VERSION_FILE}"
|
||||
return
|
||||
fi
|
||||
|
||||
|
||||
# If the iamrnetes source was exported through git archive, then
|
||||
# we likely don't have a git tree, but these magic values may be filled in.
|
||||
# shellcheck disable=SC2016,SC2050
|
||||
@@ -48,12 +48,12 @@ openim::version::get_version_vars() {
|
||||
# something like 'HEAD -> release-1.8, tag: v1.8.3' where then 'tag: '
|
||||
# can be extracted from it.
|
||||
if [[ '$Format:%D$' =~ tag:\ (v[^ ,]+) ]]; then
|
||||
OPENIM_GIT_VERSION="${BASH_REMATCH[1]}"
|
||||
OPENIM_GIT_VERSION="${BASH_REMATCH[1]}"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
local git=(git --work-tree "${OPENIM_ROOT}")
|
||||
|
||||
|
||||
if [[ -n ${OPENIM_GIT_COMMIT-} ]] || OPENIM_GIT_COMMIT=$("${git[@]}" rev-parse "HEAD^{commit}" 2>/dev/null); then
|
||||
if [[ -z ${OPENIM_GIT_TREE_STATE-} ]]; then
|
||||
# Check if the tree is dirty. default to dirty
|
||||
@@ -63,7 +63,7 @@ openim::version::get_version_vars() {
|
||||
OPENIM_GIT_TREE_STATE="dirty"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Use git describe to find the version based on tags.
|
||||
if [[ -n ${OPENIM_GIT_VERSION-} ]] || OPENIM_GIT_VERSION=$("${git[@]}" describe --tags --always --match='v*' 2>/dev/null); then
|
||||
# This translates the "git describe" to an actual semver.org
|
||||
@@ -81,7 +81,7 @@ openim::version::get_version_vars() {
|
||||
# shellcheck disable=SC2001
|
||||
# We have distance to subversion (v1.1.0-subversion-1-gCommitHash)
|
||||
OPENIM_GIT_VERSION=$(echo "${OPENIM_GIT_VERSION}" | sed "s/-\([0-9]\{1,\}\)-g\([0-9a-f]\{14\}\)$/.\1\+\2/")
|
||||
elif [[ "${DASHES_IN_VERSION}" == "--" ]] ; then
|
||||
elif [[ "${DASHES_IN_VERSION}" == "--" ]] ; then
|
||||
# shellcheck disable=SC2001
|
||||
# We have distance to base tag (v1.1.0-1-gCommitHash)
|
||||
OPENIM_GIT_VERSION=$(echo "${OPENIM_GIT_VERSION}" | sed "s/-g\([0-9a-f]\{14\}\)$/+\1/")
|
||||
@@ -94,7 +94,7 @@ openim::version::get_version_vars() {
|
||||
#OPENIM_GIT_VERSION+="-dirty"
|
||||
:
|
||||
fi
|
||||
|
||||
|
||||
# Try to match the "git describe" output to a regex to try to extract
|
||||
# the "major" and "minor" versions and whether this is the exact tagged
|
||||
# version or whether the tree is between two tagged versions.
|
||||
@@ -105,12 +105,12 @@ openim::version::get_version_vars() {
|
||||
OPENIM_GIT_MINOR+="+"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# If OPENIM_GIT_VERSION is not a valid Semantic Version, then refuse to build.
|
||||
if ! [[ "${OPENIM_GIT_VERSION}" =~ ^v([0-9]+)\.([0-9]+)(\.[0-9]+)?(-[0-9A-Za-z.-]+)?(\+[0-9A-Za-z.-]+)?$ ]]; then
|
||||
echo "OPENIM_GIT_VERSION should be a valid Semantic Version. Current value: ${OPENIM_GIT_VERSION}"
|
||||
echo "Please see more details here: https://semver.org"
|
||||
exit 1
|
||||
echo "OPENIM_GIT_VERSION should be a valid Semantic Version. Current value: ${OPENIM_GIT_VERSION}"
|
||||
echo "Please see more details here: https://semver.org"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
@@ -123,7 +123,7 @@ openim::version::save_version_vars() {
|
||||
echo "!!! Internal error. No file specified in openim::version::save_version_vars"
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
cat <<EOF >"${version_file}"
|
||||
OPENIM_GIT_COMMIT='${OPENIM_GIT_COMMIT-}'
|
||||
OPENIM_GIT_TREE_STATE='${OPENIM_GIT_TREE_STATE-}'
|
||||
@@ -140,6 +140,6 @@ openim::version::load_version_vars() {
|
||||
echo "!!! Internal error. No file specified in openim::version::load_version_vars"
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
source "${version_file}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user