fix: reconstruct the script of 'make start' 'make stop' and 'make check' (#1953)

* fix: del the error world

* fix: refactoring scripts

* fix: del nounset

* rm set error

* rm set error

* replace openim::log::info

* replace openim::log::info

* replace openim::log::info

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* fix: fix the error output format

* log

* fix: fix the error

* log

* log

* fix: fi the code error

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* log

* fix: use printf replace the echo

---------

Co-authored-by: skiffer-git <44203734@qq.com>
pull/1963/head
Brabem 4 months ago committed by GitHub
parent 8e6c1d74c7
commit ac8775827d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -119,7 +119,7 @@ func run(port int, proPort int) error {
defer cancel()
select {
case <-sigs:
util.SIGUSR1Exit()
util.SIGTERMExit()
err := server.Shutdown(ctx)
if err != nil {
return errs.Wrap(err, "shutdown err")

@ -18,7 +18,7 @@
#
set -e
set -o pipefail
############################## OpenIM Github ##############################
# ... rest of the script ...

@ -46,9 +46,7 @@ func RunWsAndServer(rpcPort, wsPort, prometheusPort int) error {
netDone := make(chan error)
go func() {
err = hubServer.Start()
if err != nil {
netDone <- err
}
netDone <- err
}()
return hubServer.LongConnServer.Run(netDone)
}

@ -139,12 +139,12 @@ func (m *MsgTransfer) Start(prometheusPort int) error {
signal.Notify(sigs, syscall.SIGTERM)
select {
case <-sigs:
util.SIGUSR1Exit()
util.SIGTERMExit()
// graceful close kafka client.
m.cancel()
m.historyCH.historyConsumerGroup.Close()
m.historyMongoCH.historyConsumerGroup.Close()
return nil
case <-netDone:
m.cancel()
m.historyCH.historyConsumerGroup.Close()
@ -152,6 +152,4 @@ func (m *MsgTransfer) Start(prometheusPort int) error {
close(netDone)
return netErr
}
return nil
}

@ -140,7 +140,7 @@ func Start(
signal.Notify(sigs, syscall.SIGTERM)
select {
case <-sigs:
util.SIGUSR1Exit()
util.SIGTERMExit()
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
if err := gracefulStopWithCtx(ctx, srv.GracefulStop); err != nil {
@ -152,7 +152,7 @@ func Start(
if err != nil {
return errs.Wrap(err, "shutdown err")
}
return errors.New("SIGTERM EXIT")
return nil
case <-netDone:
close(netDone)
return netErr

@ -15,7 +15,6 @@
package genutil
import (
"errors"
"fmt"
"os"
"path/filepath"
@ -42,15 +41,12 @@ func OutDir(path string) (string, error) {
}
func ExitWithError(err error) {
if errors.Is(err, errors.New("SIGTERM EXIT")) {
os.Exit(-1)
}
progName := filepath.Base(os.Args[0])
fmt.Fprintf(os.Stderr, "\n\n%s exit -1: \n%+v\n\n", progName, err)
fmt.Fprintf(os.Stderr, "%s exit -1: %+v\n", progName, err)
os.Exit(-1)
}
func SIGUSR1Exit() {
func SIGTERMExit() {
progName := filepath.Base(os.Args[0])
fmt.Printf("\n\n%s receive process terminal SIGTERM exit 0\n\n", progName)
fmt.Fprintf(os.Stderr, "Warning %s receive process terminal SIGTERM exit 0\n", progName)
}

@ -14,7 +14,7 @@
# limitations under the License.
set -e
set -o pipefail
. $(dirname ${BASH_SOURCE})/lib/init.sh

@ -22,9 +22,9 @@
# Usage: `scripts/build-all-service.sh`.
# Example: `scripts/build-go.sh WHAT=cmd/kubelet`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -19,9 +19,9 @@
# Encapsulated as: `make check`.
# READ: https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
@ -49,13 +49,6 @@ print_services_and_ports() {
echo "+-------------------------+----------+"
}
handle_error() {
echo "An error occurred. Printing ${STDERR_LOG_FILE} contents:"
cat "${STDERR_LOG_FILE}"
exit 1
}
trap handle_error ERR
# Assuming OPENIM_SERVER_NAME_TARGETS and OPENIM_SERVER_PORT_TARGETS are defined
# Similarly for OPENIM_DEPENDENCY_TARGETS and OPENIM_DEPENDENCY_PORT_TARGETS
@ -71,7 +64,6 @@ 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[@]}"
set +e
# Later, after discarding Docker, the Docker keyword is unreliable, and Kubepods is used
if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then
@ -85,22 +77,29 @@ if [[ $? -ne 0 ]]; then
openim::log::error_exit "The service does not start properly, please check the port, query variable definition!"
echo "+++ https://github.com/openimsdk/open-im-server/tree/main/scripts/install/environment.sh +++"
else
echo "++++ Check all dependent service ports successfully !"
openim::log::success "All components depended on by openim are running normally! "
fi
openim::log::info "\n## Check OpenIM service name"
. $(dirname ${BASH_SOURCE})/install/openim-msgtransfer.sh openim::msgtransfer::check
openim::log::info "\n## Check all OpenIM service ports"
echo "+++ The port being checked: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
openim::util::check_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
openim::log::info "\n## Check openim service name:\n${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_exit "The service does not start properly, please check the port, query variable definition!"
else
echo "++++ Check all openim service ports successfully !"
openim::log::error "check process failed.\n $result"
fi
set -e
trap - ERR
echo "Check openim service name:"
for item in "${OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER[@]}"; do
echo "$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 "$result"
else
openim::log::success "All openim services are running normally! "
fi

@ -21,9 +21,9 @@
# checks them out to a branch named:
# automated-cherry-pick-of-<pr>-<target branch>-<timestamp>
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -18,9 +18,9 @@
# shellcheck disable=SC2034 # Variables sourced in other scripts.
# Common utilities, variables and checks for all build scripts.
set -o errexit
set +o nounset
set -o pipefail
# Unset CDPATH, having it set messes up with script import paths
unset CDPATH

@ -14,9 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
#fixme This scripts is the total startup scripts
#fixme The full name of the shell scripts that needs to be started is placed in the need_to_start_server_shell array

@ -15,9 +15,9 @@
# Script to generate docs from the latest swagger spec.
set -o errexit
set -o nounset
set -o pipefail
# The root of the build/dist directory
OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"

@ -15,9 +15,9 @@
# This script automatically initializes various configuration files and can generate example files.
set -o errexit
set -o nounset
set -o pipefail
# Root directory of the OpenIM project
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

@ -16,8 +16,8 @@
#FIXME This script is the startup script for multiple servers.
#FIXME The full names of the shell scripts that need to be started are placed in the `need_to_start_server_shell` array.
set -o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd -P)
source "${OPENIM_ROOT}/scripts/install/common.sh"

@ -27,9 +27,9 @@
# Usage:
# SERVER_IMAGE_VERSION=latest IMAGE_REGISTRY=myregistry ./this_script.sh
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -15,9 +15,9 @@
# Common utilities, variables and checks for all build scripts.
set -o errexit
set +o nounset
set -o pipefail
# Sourced flag
COMMON_SOURCED=true
@ -99,6 +99,22 @@ IFS=" " read -ra OPENIM_SERVER_PORT_TARGETS <<< "$(openim::common::service_port)
readonly OPENIM_SERVER_PORT_TARGETS
readonly OPENIM_SERVER_PORT_LISTARIES=("${OPENIM_SERVER_PORT_TARGETS[@]##*/}")
OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER=()
for target in "${OPENIM_SERVER_BINARIES_NO_TRANSFER[@]}"; do
OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
done
readonly OPENIM_ALL_SERVICE_LIBRARIES_NO_TRANSFER
OPENIM_ALL_SERVICE_LIBRARIES=()
for target in "${OPENIM_SERVER_BINARIES_NO_CMDUTILS[@]}"; do
OPENIM_ALL_SERVICE_LIBRARIES+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
done
readonly OPENIM_ALL_SERVICE_LIBRARIES
openim::common::dependency_name() {
local targets=(
redis

@ -15,9 +15,9 @@
# This script will install the dependencies required for openim
set -o errexit
set +o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh

@ -109,7 +109,7 @@ function openim::uninstall::uninstall_openim() {
openim::common::sudo "systemctl stop openim.target"
openim::common::sudo "systemctl disable openim.target"
openim::common::sudo "rm -f /etc/systemd/system/openim.target"
set -o errexit
openim::log::success "openim uninstall success"
}

@ -14,9 +14,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set +o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
@ -47,24 +47,31 @@ function openim::api::start() {
openim::log::info "Starting ${SERVER_NAME} ..."
readonly OPENIM_API_SERVER_LIBRARIES="${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}"
printf "+------------------------+--------------+\n"
printf "| Service Name | Port |\n"
printf "+------------------------+--------------+\n"
local length=${#OPENIM_API_SERVICE_LISTARIES[@]}
for ((i=0; i<length; i++)); do
printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}"
printf "+------------------------+--------------+\n"
# Stop services on the specified ports before starting new ones
openim::util::stop_services_on_ports "${OPENIM_API_PORT_LISTARIES[$i]}"
openim::util::stop_services_on_ports "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}"
openim::log::info "OpenIM ${OPENIM_API_SERVICE_LISTARIES[$i]} config path: ${OPENIM_API_CONFIG}"
# Start the service with Prometheus port if specified
openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}"
sleep 2
result=$(openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}" "${OPENIM_API_PROMETHEUS_PORT_LISTARIES[$i]}")
if [[ $? -ne 0 ]]; then
openim::log::error "stop ${SERVER_NAME} failed"
else
openim::log::info "$result"
fi
done
return 0
}
function openim::api::start_service() {
@ -85,7 +92,9 @@ function openim::api::start_service() {
if [ $? -ne 0 ]; then
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
return 1
fi
return 0
}
###################################### Linux Systemd ######################################
@ -138,7 +147,7 @@ function openim::api::uninstall() {
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
set -o errexit
openim::log::info "uninstall ${SERVER_NAME} successfully"
}

@ -49,13 +49,11 @@ function openim::crontask::start() {
openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}"
openim::util::stop_services_with_name ${OPENIM_CRONTASK_BINARY}
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) &
openim::util::check_process_names ${SERVER_NAME}
return 0
}
@ -107,7 +105,7 @@ function openim::crontask::uninstall() {
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
set -o errexit
openim::log::info "uninstall ${SERVER_NAME} successfully"
}

@ -76,7 +76,7 @@ function openim::man::uninstall() {
# Turn off exit-on-error temporarily to handle non-existing files gracefully
set +o errexit
openim::common::sudo "rm -f /usr/share/man/man1/openim-*"
set -o errexit
openim::log::info "Uninstalled openim man pages successfully"
}

@ -14,14 +14,13 @@
# limitations under the License.
# Common utilities, variables and checks for all build scripts.
set -o errexit
set +o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
openim::util::set_max_fd 200000
SERVER_NAME="openim-msggateway"
@ -31,8 +30,7 @@ function openim::msggateway::start() {
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
openim::util::stop_services_with_name ${OPENIM_MSGGATEWAY_BINARY}
# OpenIM message gateway service port
OPENIM_MESSAGE_GATEWAY_PORTS=$(openim::util::list-to-string ${OPENIM_MESSAGE_GATEWAY_PORT} )
@ -66,8 +64,7 @@ function openim::msggateway::start() {
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
openim::util::check_process_names ${SERVER_NAME}
return 0
}
###################################### Linux Systemd ######################################
@ -117,7 +114,7 @@ function openim::msggateway::uninstall() {
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
set -o errexit
openim::log::info "uninstall ${SERVER_NAME} successfully"
}

@ -16,15 +16,13 @@
# ./scripts/install/openim-msgtransfer.sh openim::msgtransfer::start
# Common utilities, variables and checks for all build scripts.
set -o errexit
set +o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
openim::util::set_max_fd 200000
SERVER_NAME="openim-msgtransfer"
function openim::msgtransfer::start() {
@ -33,9 +31,7 @@ function openim::msgtransfer::start() {
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
openim::util::stop_services_with_name ${OPENIM_MSGTRANSFER_BINARY}
# Message Transfer Prometheus port list
MSG_TRANSFER_PROM_PORTS=(openim::util::list-to-string ${MSG_TRANSFER_PROM_PORT} )
@ -46,11 +42,11 @@ function openim::msgtransfer::start() {
openim::log::info "openim maggateway num: ${OPENIM_MSGGATEWAY_NUM}"
if [ "${OPENIM_MSGGATEWAY_NUM}" -lt 1 ]; then
opeim::log::error_exit "OPENIM_MSGGATEWAY_NUM must be greater than 0"
opeim::log::error "OPENIM_MSGGATEWAY_NUM must be greater than 0"
fi
if [ ${OPENIM_MSGGATEWAY_NUM} -ne $((${#MSG_TRANSFER_PROM_PORTS[@]} - 1)) ]; then
openim::log::error_exit "OPENIM_MSGGATEWAY_NUM must be equal to the number of MSG_TRANSFER_PROM_PORTS"
openim::log::error "OPENIM_MSGGATEWAY_NUM must be equal to the number of MSG_TRANSFER_PROM_PORTS"
fi
for (( i=0; i<$OPENIM_MSGGATEWAY_NUM; i++ )) do
@ -63,17 +59,18 @@ function openim::msgtransfer::start() {
fi
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
openim::util::check_process_names "${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}"
return 0
}
function openim::msgtransfer::check() {
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer")
NUM_PROCESSES=$(echo "$PIDS" | wc -l)
if [ -z "$PIDS" ]; then
NUM_PROCESSES=0
else
NUM_PROCESSES=$(echo "$PIDS" | wc -l)
fi
if [ "$NUM_PROCESSES" -eq "$OPENIM_MSGGATEWAY_NUM" ]; then
openim::log::info "Found $OPENIM_MSGGATEWAY_NUM processes named $OPENIM_OUTPUT_HOSTBIN"
for PID in $PIDS; do
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
ps -p $PID -o pid,cmd
@ -84,10 +81,39 @@ function openim::msgtransfer::check() {
fi
done
else
openim::log::error_exit "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."
return 1
fi
return 0
}
function openim::msgtransfer::check_for_stop() {
PIDS=$(pgrep -f "${OPENIM_OUTPUT_HOSTBIN}/openim-msgtransfer") || PIDS="0"
if [ "$PIDS" = "0" ]; then
return 0
fi
NUM_PROCESSES=$(echo "$PIDS" | wc -l | xargs)
if [ "$NUM_PROCESSES" -gt 0 ]; then
openim::log::error "Found $NUM_PROCESSES processes for $OPENIM_OUTPUT_HOSTBIN/openim-msgtransfer"
for PID in $PIDS; do
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo -e "\033[31m$(ps -p $PID -o pid,cmd)\033[0m"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "\033[31m$(ps -p $PID -o pid,comm)\033[0m"
else
openim::log::error "Unsupported OS type: $OSTYPE"
fi
done
openim::log::error "Processes have not been stopped properly."
else
openim::log::success "All openim-msgtransfer processes have been stopped properly."
fi
return 0
}
###################################### Linux Systemd ######################################
SYSTEM_FILE_PATH="/etc/systemd/system/${SERVER_NAME}.service"
@ -138,7 +164,7 @@ function openim::msgtransfer::uninstall() {
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
set -o errexit
openim::log::info "uninstall ${SERVER_NAME} successfully"
}

@ -40,9 +40,9 @@
#
# Note: Ensure that the appropriate permissions and environmental variables are set prior to script execution.
#
set -o errexit
set +o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
@ -61,22 +61,20 @@ function openim::push::start() {
OPENIM_PUSH_PORTS_ARRAY=$(openim::util::list-to-string ${OPENIM_PUSH_PORT} )
PUSH_PROM_PORTS_ARRAY=$(openim::util::list-to-string ${PUSH_PROM_PORT} )
openim::util::stop_services_with_name ${SERVER_NAME}
openim::log::status "push port list: ${OPENIM_PUSH_PORTS_ARRAY[@]}"
openim::log::status "prometheus port list: ${PUSH_PROM_PORTS_ARRAY[@]}"
if [ ${#OPENIM_PUSH_PORTS_ARRAY[@]} -ne ${#PUSH_PROM_PORTS_ARRAY[@]} ]; then
openim::log::error_exit "The length of the two port lists is different!"
openim::log::error "The length of the two port lists is different!"
fi
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]}"
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
openim::util::check_process_names ${SERVER_NAME}
}
###################################### Linux Systemd ######################################
@ -125,7 +123,7 @@ function openim::push::uninstall() {
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/${SERVER_NAME}"
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${SERVER_NAME}.yaml"
openim::common::sudo "rm -f /etc/systemd/system/${SERVER_NAME}.service"
set -o errexit
openim::log::info "uninstall ${SERVER_NAME} successfully"
}

@ -38,9 +38,9 @@
# Note: Before executing this script, ensure that the necessary permissions are granted and relevant environmental variables are set.
#
set -o errexit
set +o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
@ -64,6 +64,16 @@ IFS=" " read -ra OPENIM_RPC_SERVICE_TARGETS <<< "$(openim::rpc::service_name)"
readonly OPENIM_RPC_SERVICE_TARGETS
readonly OPENIM_RPC_SERVICE_LISTARIES=("${OPENIM_RPC_SERVICE_TARGETS[@]##*/}")
OPENIM_ALL_RPC_FULL_PATH=()
for target in openim::rpc::service_name; do
OPENIM_ALL_RPC_FULL_PATH+=("${OPENIM_OUTPUT_HOSTBIN}/${target}")
done
readonly OPENIM_ALL_RPC_FULL_PATH
# Make sure the environment is only called via common to avoid too much nesting
openim::rpc::service_port() {
local targets=(
@ -121,14 +131,11 @@ function openim::rpc::start() {
printf "+------------------------+-------+-----------------+\n"
done
# start all rpc services
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
# openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES
openim::util::stop_services_on_ports ${OPENIM_RPC_PORT_LISTARIES[$i]}
openim::util::stop_services_on_ports ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}
openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}"
# Get the service and Prometheus ports.
OPENIM_RPC_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_RPC_PORT_LISTARIES[$i]}) )
read -a OPENIM_RPC_SERVICE_PORTS_ARRAY <<< ${OPENIM_RPC_SERVICE_PORTS}
@ -138,15 +145,17 @@ function openim::rpc::start() {
for ((j = 0; j < ${#OPENIM_RPC_SERVICE_PORTS_ARRAY[@]}; j++)); do
openim::log::info "Starting ${OPENIM_RPC_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_RPC_SERVICE_PORTS[j]}, prometheus port: ${OPENIM_RPC_PROM_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_RPC_SERVICE_LISTARIES[$i]}"
openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}"
result=$(openim::rpc::start_service "${OPENIM_RPC_SERVICE_LISTARIES[$i]}" "${OPENIM_RPC_SERVICE_PORTS[j]}" "${OPENIM_RPC_PROM_PORTS[j]}")
if [[ $? -ne 0 ]]; then
openim::log::error "start ${SERVER_NAME} failed"
else
openim::log::info "$result"
fi
done
done
sleep 5
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}
return 0
}
function openim::rpc::start_service() {
@ -161,6 +170,7 @@ 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) &
return 0
}
###################################### Linux Systemd ######################################
@ -220,7 +230,7 @@ function openim::rpc::uninstall() {
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/${service}.yaml"
openim::common::sudo "rm -f ${SYSTEM_FILE_PATHS[$service]}"
done
set -o errexit
openim::log::info "uninstall openim-rpc successfully"
}

@ -38,9 +38,9 @@
# Example: ./openim-tools.sh openim::tools::install
#
set -o errexit
set +o nounset
set -o pipefail
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
[[ -z ${COMMON_SOURCED} ]] && source "${OPENIM_ROOT}"/scripts/install/common.sh
@ -122,7 +122,6 @@ function openim::tools::pre-start() {
for tool in "${OPENIM_TOOLS_PRE_START_NAME_LISTARIES[@]}"; do
openim::log::info "Starting ${tool}..."
openim::tools::start_service ${tool} ${OPNEIM_CONFIG}
sleep 0.2
done
}
@ -131,7 +130,6 @@ function openim::tools::post-start() {
for tool in "${OPENIM_TOOLS_POST_START_NAME_LISTARIES[@]}"; do
openim::log::info "Starting ${tool}..."
openim::tools::start_service ${tool}
sleep 0.2
done
}

@ -84,6 +84,57 @@ openim::golang::server_targets() {
echo "${targets[@]}"
}
openim::golang::server_targets_no_transfer() {
local targets=(
openim-api
openim-crontask
openim-msggateway
openim-push
openim-rpc-auth
openim-rpc-conversation
openim-rpc-friend
openim-rpc-group
openim-rpc-msg
openim-rpc-third
openim-rpc-user
)
echo "${targets[@]}"
}
openim::golang::server_targets_no_cmdutils() {
local targets=(
openim-api
openim-crontask
openim-msggateway
openim-msgtransfer
openim-push
openim-rpc-auth
openim-rpc-conversation
openim-rpc-friend
openim-rpc-group
openim-rpc-msg
openim-rpc-third
openim-rpc-user
)
echo "${targets[@]}"
}
IFS=" " read -ra OPENIM_SERVER_TARGETS_NO_CMDUTILS <<< "$(openim::golang::server_targets_no_cmdutils)"
readonly OPENIM_SERVER_TARGETS_NO_CMDUTILS
readonly OPENIM_SERVER_BINARIES_NO_CMDUTILS=("${OPENIM_SERVER_TARGETS_NO_CMDUTILS[@]##*/}")
IFS=" " read -ra OPENIM_SERVER_TARGETS_NO_TRANSFER <<< "$(openim::golang::server_targets_no_transfer)"
readonly OPENIM_SERVER_TARGETS_NO_TRANSFER
readonly OPENIM_SERVER_BINARIES_NO_TRANSFER=("${OPENIM_SERVER_TARGETS_NO_TRANSFER[@]##*/}")
IFS=" " read -ra OPENIM_SERVER_TARGETS <<< "$(openim::golang::server_targets)"
readonly OPENIM_SERVER_TARGETS
readonly OPENIM_SERVER_BINARIES=("${OPENIM_SERVER_TARGETS[@]##*/}")

@ -13,9 +13,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set +o nounset
set -o pipefail
# Short-circuit if init.sh has already been sourced
[[ $(type -t openim::init::loaded) == function ]] && return 0

@ -75,12 +75,13 @@ openim::log::errexit() {
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
# is a more verbose version of
# trap 'openim::log::errexit' ERR
# setting errtrace allows our ERR trap handler to be propagated to functions,
# expansions and subshells
set -o errtrace
#set -o errtrace
return 0
}
# Print out the stack trace
@ -205,22 +206,27 @@ openim::log::status() {
fi
timestamp=$(date +"[%Y-%m-%d %H:%M:%S %Z]")
echo_log "+++ ${timestamp} ${1}"
echo_log "${timestamp} ${1}"
shift
for message; do
echo_log " ${message}"
done
}
openim::log::success() {
local V="${V:-0}"
if [[ ${OPENIM_VERBOSE} < ${V} ]]; then
return
fi
timestamp=$(date +"%m%d %H:%M:%S")
echo_log -e "${COLOR_GREEN}[success ${timestamp}] ${COLOR_SUFFIX}==> " "$@"
local timestamp=$(date +"%m%d %H:%M:%S")
local reset_color='\033[0m'
echo_log -e "${COLOR_GREEN}[success ${timestamp}]${COLOR_SUFFIX}==> ${COLOR_GREEN}$@${reset_color}"
}
function openim::log::test_log() {
echo_log "test log"
openim::log::info "openim::log::info"

@ -298,7 +298,7 @@ openim::util::check_ports() {
# An array to collect information about processes that are running.
local started=()
openim::log::info "Checking ports: $*"
echo "Checking ports: $*"
# Iterate over each given port.
for port in "$@"; do
# Initialize variables
@ -344,7 +344,7 @@ openim::util::check_ports() {
# Print information about ports whose processes are not running.
if [[ ${#not_started[@]} -ne 0 ]]; then
openim::log::info "\n### Not started ports:"
echo "### Not started ports:"
for port in "${not_started[@]}"; do
openim::log::error "Port $port is not started."
done
@ -352,20 +352,20 @@ openim::util::check_ports() {
# Print information about ports whose processes are running.
if [[ ${#started[@]} -ne 0 ]]; then
openim::log::info "\n### Started ports:"
echo "### Started ports:"
for info in "${started[@]}"; do
openim::log::info "$info"
echo "$info"
done
fi
# 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
openim::log::success "All specified processes are running."
#openim::log::success "All specified ports are running."
return 0
fi
}
@ -373,7 +373,7 @@ openim::util::check_ports() {
# set +o errexit
# Sample call for testing:
# openim::util::check_ports 10002 1004 12345 13306
# set -o errexit
#
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
# It accepts multiple process names as arguments and prints:
@ -402,7 +402,6 @@ openim::util::check_process_names() {
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
@ -430,24 +429,24 @@ openim::util::check_process_names() {
# Print information
if [[ ${#not_started[@]} -ne 0 ]]; then
openim::log::info "Not started processes:"
echo "Not started processes:"
for process_name in "${not_started[@]}"; do
openim::log::error "Process $process_name is not started."
echo "Process $process_name is not started."
done
fi
if [[ ${#started[@]} -ne 0 ]]; then
echo
openim::log::info "Started processes:"
echo "Started processes:"
for info in "${started[@]}"; do
openim::log::info "$info"
echo "$info"
done
fi
# 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
@ -457,6 +456,66 @@ openim::util::check_process_names() {
fi
}
openim::util::check_process_names_for_stop() {
# 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=()
# 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
if [[ ${#started[@]} -ne 0 ]]; then
echo
echo "The programs that have not exited are:"
for info in "${started[@]}"; do
echo "$info "
done
return 1
fi
return 0
}
# openim::util::check_process_names docker-pr
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
@ -473,7 +532,7 @@ openim::util::stop_services_on_ports() {
# An array to collect information about processes that were stopped.
local stopped=()
openim::log::info "Stopping services on ports: $*"
echo "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.
@ -497,7 +556,7 @@ openim::util::stop_services_on_ports() {
# Print information about ports whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Ports that couldn't be stopped:"
echo "Ports that couldn't be stopped:"
for port in "${not_stopped[@]}"; do
openim::log::status "Failed to stop service on port $port."
done
@ -506,7 +565,7 @@ openim::util::stop_services_on_ports() {
# Print information about ports whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
for port in "${stopped[@]}"; do
openim::log::info "Successfully stopped service on port $port."
echo "Successfully stopped service on port $port."
done
fi
@ -539,7 +598,7 @@ openim::util::stop_services_with_name() {
# An array to collect information about processes that were stopped.
local stopped=()
openim::log::info "Stopping services with names: $*"
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.
@ -573,26 +632,8 @@ openim::util::stop_services_with_name() {
not_stopped+=("$server_name")
fi
done
return 0
# Print information about services whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Services that couldn't be stopped:"
for name in "${not_stopped[@]}"; do
openim::log::status "Failed to stop the $name service."
done
fi
# Print information about services whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services:"
for name in "${stopped[@]}"; do
openim::log::info "Successfully stopped the $name service."
done
fi
openim::log::success "All specified services were stopped."
echo ""
}
# sleep 333333&
# sleep 444444&
@ -1531,7 +1572,7 @@ openim::util::check_ports() {
# An array to collect information about processes that are running.
local started=()
openim::log::info "Checking ports: $*"
echo "Checking ports: $*"
# Iterate over each given port.
for port in "$@"; do
# Initialize variables
@ -1577,7 +1618,7 @@ openim::util::check_ports() {
# Print information about ports whose processes are not running.
if [[ ${#not_started[@]} -ne 0 ]]; then
openim::log::info "\n### Not started ports:"
printf "\n### Not started ports:"
for port in "${not_started[@]}"; do
openim::log::error "Port $port is not started."
done
@ -1585,16 +1626,16 @@ openim::util::check_ports() {
# Print information about ports whose processes are running.
if [[ ${#started[@]} -ne 0 ]]; then
openim::log::info "\n### Started ports:"
printf "\n### Started ports:"
for info in "${started[@]}"; do
openim::log::info "$info"
echo "$info"
done
fi
# 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}"
echo ""
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
return 1
@ -1607,7 +1648,7 @@ openim::util::check_ports() {
# set +o errexit
# Sample call for testing:
# openim::util::check_ports 10002 1004 12345 13306
# set -o errexit
#
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
# It accepts multiple process names as arguments and prints:
@ -1636,7 +1677,7 @@ openim::util::check_process_names() {
local not_started=()
local started=()
openim::log::info "Checking processes: $*"
echo "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
@ -1664,7 +1705,7 @@ openim::util::check_process_names() {
# Print information
if [[ ${#not_started[@]} -ne 0 ]]; then
openim::log::info "Not started processes:"
echo "Not started processes:"
for process_name in "${not_started[@]}"; do
openim::log::error "Process $process_name is not started."
done
@ -1672,9 +1713,9 @@ openim::util::check_process_names() {
if [[ ${#started[@]} -ne 0 ]]; then
echo
openim::log::info "Started processes:"
echo "Started processes:"
for info in "${started[@]}"; do
openim::log::info "$info"
echo "$info"
done
fi
@ -1707,7 +1748,7 @@ openim::util::stop_services_on_ports() {
# An array to collect information about processes that were stopped.
local stopped=()
openim::log::info "Stopping services on ports: $*"
echo "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.
@ -1731,7 +1772,7 @@ openim::util::stop_services_on_ports() {
# Print information about ports whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Ports that couldn't be stopped:"
echo "Ports that couldn't be stopped:"
for port in "${not_stopped[@]}"; do
openim::log::status "Failed to stop service on port $port."
done
@ -1740,7 +1781,7 @@ openim::util::stop_services_on_ports() {
# Print information about ports whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
for port in "${stopped[@]}"; do
openim::log::info "Successfully stopped service on port $port."
echo "Successfully stopped service on port $port."
done
fi
@ -1773,7 +1814,7 @@ openim::util::stop_services_with_name() {
# An array to collect information about processes that were stopped.
local stopped=()
openim::log::info "Stopping services with names: $*"
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.
@ -1810,7 +1851,7 @@ openim::util::stop_services_with_name() {
# Print information about services whose processes couldn't be stopped.
if [[ ${#not_stopped[@]} -ne 0 ]]; then
openim::log::info "Services that couldn't be stopped:"
echo "Services that couldn't be stopped:"
for name in "${not_stopped[@]}"; do
openim::log::status "Failed to stop the $name service."
done
@ -1819,9 +1860,9 @@ openim::util::stop_services_with_name() {
# Print information about services whose processes were successfully stopped.
if [[ ${#stopped[@]} -ne 0 ]]; then
echo
openim::log::info "Stopped services:"
echo "Stopped services:"
for name in "${stopped[@]}"; do
openim::log::info "Successfully stopped the $name service."
echo "Successfully stopped the $name service."
done
fi
@ -2822,6 +2863,46 @@ function openim::util::gen_os_arch() {
fi
}
function openim::util::check_process_names_for_stop() {
local all_stopped=true
for service in "${OPENIM_ALL_SERVICE_LIBRARIES[@]}"; do
PIDS=$(pgrep -f "${service}") || PIDS="0"
if [ "$PIDS" = "0" ]; then
continue
fi
NUM_PROCESSES=$(echo "$PIDS" | wc -l | xargs)
if [ "$NUM_PROCESSES" -gt 0 ]; then
all_stopped=false
echo "Found $NUM_PROCESSES processes for ${service}"
for PID in $PIDS; do
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
echo -e "\033[31m$(ps -p $PID -o pid,cmd)\033[0m"
elif [[ "$OSTYPE" == "darwin"* ]]; then
echo -e "\033[31m$(ps -p $PID -o pid,comm)\033[0m"
else
openim::log::error "Unsupported OS type: $OSTYPE"
fi
done
echo "Processes for ${service} have not been stopped properly. " "$NUM_PROCESSES"
fi
done
if [ "$all_stopped" = true ]; then
openim::log::success "All processes have been stopped properly."
return 0
fi
return 1
}
if [[ "$*" =~ openim::util:: ]];then
eval $*
fi
fi

@ -18,9 +18,9 @@
#
# Usage: `scripts/list-feature-tests.sh`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
grep "\[Feature:\w+\]" "${OPENIM_ROOT}"/test/e2e/**/*.go -Eoh | LC_ALL=C sort -u

@ -47,9 +47,9 @@
# images and other build artifacts.
# Build a OpenIM release. This script supports various flags for flexible execution control.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/common.sh"
source "${OPENIM_ROOT}/scripts/lib/release.sh"

@ -20,9 +20,9 @@
# the project.
# Usage: `scripts/run-in-gopath.sh <command>`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -16,70 +16,100 @@
#FIXME This script is the startup script for multiple servers.
#FIXME The full names of the shell scripts that need to be started are placed in the `need_to_start_server_shell` array.
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
openim::log::info "\n# Begin to start all openim service scripts"
set +o errexit
openim::golang::check_openim_binaries
if [[ $? -ne 0 ]]; then
openim::log::error "OpenIM binaries are not found. Please run 'make build' to build binaries."
"${OPENIM_ROOT}"/scripts/build-all-service.sh
fi
set -o errexit
"${OPENIM_ROOT}"/scripts/init-config.sh --skip
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
echo "You need to start the following scripts in order: ${OPENIM_SERVER_SCRIPTARIES[@]}"
openim::log::install_errexit
# Function to execute the scripts.
function execute_scripts() {
function execute_start_scripts() {
for script_path in "${OPENIM_SERVER_SCRIPT_START_LIST[@]}"; do
# Extract the script name without extension for argument generation.
script_name_with_prefix=$(basename "$script_path" .sh)
# Remove the "openim-" prefix.
script_name=${script_name_with_prefix#openim-}
# Construct the argument based on the script name.
arg="openim::${script_name}::start"
# Check if the script file exists and is executable.
if [[ -x "$script_path" ]]; then
openim::log::status "Starting script: ${script_path##*/}" # Log the script name.
openim::log::info "Starting script: ${script_path##*/}" # Log the script name.
# Execute the script with the constructed argument.
"$script_path" "$arg"
# Check if the script executed successfully.
if [[ $? -eq 0 ]]; then
openim::log::info "${script_path##*/} executed successfully."
else
openim::log::errexit "Error executing ${script_path##*/}."
result=$("$script_path" "$arg")
if [[ $? -ne 0 ]]; then
openim::log::error "Start script: ${script_path##*/} failed"
openim::log::error "$result"
return 1
fi
else
openim::log::errexit "Script ${script_path##*/} is missing or not executable."
return 1
fi
done
sleep 0.5
}
openim::golang::check_openim_binaries
if [[ $? -ne 0 ]]; then
openim::log::error "OpenIM binaries are not found. Please run 'make build' to build binaries."
"${OPENIM_ROOT}"/scripts/build-all-service.sh
fi
"${OPENIM_ROOT}"/scripts/init-config.sh --skip
echo "You need to start the following scripts in order: ${OPENIM_SERVER_SCRIPTARIES[@]}"
# TODO Prelaunch tools, simple for now, can abstract functions later
TOOLS_START_SCRIPTS_PATH=${START_SCRIPTS_PATH}/openim-tools.sh
openim::log::info "\n## Pre Starting OpenIM services"
openim::log::status "\n## Pre Starting OpenIM services"
${TOOLS_START_SCRIPTS_PATH} openim::tools::pre-start
openim::log::info "\n## Starting OpenIM services"
execute_scripts
openim::log::info "\n## Post Starting OpenIM services"
result=$("${OPENIM_ROOT}"/scripts/stop-all.sh)
if [[ $? -ne 0 ]]; then
echo "+++ cat openim log file >>> ${LOG_FILE}"
openim::log::error "Some programs have not exited; the start process is aborted .\n $result"
exit 1
fi
openim::log::status "\n## Starting openim scripts: "
execute_start_scripts
sleep 2
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 "The program 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
echo "+++ cat openim log file >>> ${LOG_FILE}"
openim::log::error "The program 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::color::echo $COLOR_BLUE "✨ All OpenIM services have been successfully started!"
openim::log::success "All openim services have been successfully started!"

@ -18,22 +18,43 @@
# Usage: `scripts/stop.sh`.
# Encapsulated as: `make stop`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/install/common.sh"
openim::log::info "\n# Begin to stop all openim service"
openim::log::status "Begin to stop all openim service"
echo "++ Ready to stop port: ${OPENIM_SERVER_PORT_LISTARIES[@]}"
openim::log::status "Stop all processes in the path ${OPENIM_OUTPUT_HOSTBIN}"
openim::util::stop_services_on_ports ${OPENIM_SERVER_PORT_LISTARIES[@]}
openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}"
# todo OPENIM_ALL_SERVICE_LIBRARIES
echo -e "\n++ Stop all processes in the path ${OPENIM_OUTPUT_HOSTBIN}"
openim::util::stop_services_with_name "${OPENIM_OUTPUT_HOSTBIN}"
openim::log::success "✨ All processes to be killed"
max_retries=15
attempt=0
while [[ $attempt -lt $max_retries ]]
do
result=$(openim::util::check_process_names_for_stop)
if [[ $? -ne 0 ]]; then
if [[ $attempt -ne 0 ]] ; then
echo "+++ cat openim log file >>> ${LOG_FILE} " $attempt
openim::log::error "stop process failed. continue waiting\n" "${result}"
fi
sleep 1
((attempt++))
else
openim::log::success " All openim processes to be stopped"
exit 0
fi
done
openim::log::error "openim processes stopped failed"
exit 1

@ -18,9 +18,9 @@
# immediately before exporting docs. We do not want to check these documents in
# by default.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -14,9 +14,9 @@
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -17,9 +17,9 @@
# This script verifies whether codes follow golang convention.
# Usage: `scripts/verify-pkg-names.sh`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -17,9 +17,9 @@
# This script lints each shell script by `shellcheck`.
# Usage: `scripts/verify-shellcheck.sh`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -17,9 +17,9 @@
# working directory by client9/misspell package.
# Usage: `scripts/verify-spelling.sh`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
export OPENIM_ROOT

@ -16,9 +16,9 @@
# This script does a fast type check of script srnetes code for all platforms.
# Usage: `scripts/verify-typecheck.sh`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

@ -19,9 +19,9 @@
#
# Usage: `scripts/verify-yamlfmt.sh`.
set -o errexit
set -o nounset
set -o pipefail
OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${OPENIM_ROOT}/scripts/lib/init.sh"

Loading…
Cancel
Save