mirror of
https://github.com/openimsdk/open-im-server.git
synced 2026-05-09 19:45:58 +08:00
Fix Script Error and Enhance Code Robustness and Details (#1890)
* feat: add openim deployment tactics Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * feat: add openim deployment tactics Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * fix: set openim admin chat code Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * fix: set openim admin chat code Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * fix: fix openim msgtransfer code * fix: fix openim msgtransfer code --------- Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
@@ -33,8 +33,12 @@ readonly OPENIM_API_SERVICE_TARGETS=(
|
||||
)
|
||||
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
|
||||
|
||||
function openim::api::start() {
|
||||
readonly OPENIM_API_PROMETHEUS_PORT_TARGETS=(
|
||||
${API_PROM_PORT}
|
||||
)
|
||||
readonly OPENIM_API_PROMETHEUS_PORT_LISTARIES=("${OPENIM_API_PROMETHEUS_PORT_TARGETS[@]##*/}")
|
||||
|
||||
function openim::api::start() {
|
||||
rm -rf "$TMP_LOG_FILE"
|
||||
|
||||
echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}"
|
||||
@@ -47,34 +51,20 @@ function openim::api::start() {
|
||||
printf "| Service Name | Port |\n"
|
||||
printf "+------------------------+--------------+\n"
|
||||
|
||||
length=${#OPENIM_API_SERVICE_LISTARIES[@]}
|
||||
local length=${#OPENIM_API_SERVICE_LISTARIES[@]}
|
||||
|
||||
for ((i=0; i<$length; i++)); do
|
||||
for ((i=0; i<length; i++)); do
|
||||
printf "| %-22s | %6s |\n" "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[$i]}"
|
||||
printf "+------------------------+--------------+\n"
|
||||
done
|
||||
# start all api services
|
||||
for ((i = 0; i < ${#OPENIM_API_SERVICE_LISTARIES[*]}; i++)); do
|
||||
openim::util::stop_services_on_ports ${OPENIM_API_PORT_LISTARIES[$i]}
|
||||
# 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}"
|
||||
|
||||
# Get the service and Prometheus ports.
|
||||
OPENIM_API_SERVICE_PORTS=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[$i]}) )
|
||||
|
||||
# TODO Only one port is supported. An error occurs on multiple ports
|
||||
if [ ${#OPENIM_API_SERVICE_PORTS[@]} -ne 1 ]; then
|
||||
openim::log::error_exit "Set only one port for ${OPENIM_API_SERVICE_LISTARIES[$i]} service."
|
||||
fi
|
||||
|
||||
for ((j = 0; j < ${#OPENIM_API_SERVICE_PORTS[@]}; j++)); do
|
||||
openim::log::info "Starting ${OPENIM_API_SERVICE_LISTARIES[$i]} service, port: ${OPENIM_API_SERVICE_PORTS[j]}, binary root: ${OPENIM_OUTPUT_HOSTBIN}/${OPENIM_API_SERVICE_LISTARIES[$i]}"
|
||||
openim::api::start_service "${OPENIM_API_SERVICE_LISTARIES[$i]}" "${OPENIM_API_PORT_LISTARIES[j]}"
|
||||
sleep 2
|
||||
done
|
||||
# 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
|
||||
done
|
||||
|
||||
OPENIM_API_PORT_STRINGARIES=( $(openim::util::list-to-string ${OPENIM_API_PORT_LISTARIES[@]}) )
|
||||
openim::util::check_ports ${OPENIM_API_PORT_STRINGARIES[@]}
|
||||
}
|
||||
|
||||
function openim::api::start_service() {
|
||||
@@ -83,7 +73,15 @@ function openim::api::start_service() {
|
||||
local prometheus_port="$3"
|
||||
|
||||
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_API_CONFIG}"
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
|
||||
# Append Prometheus port argument if specified
|
||||
if [ -n "${prometheus_port}" ]; then
|
||||
cmd+=" --prometheus_port ${prometheus_port}"
|
||||
fi
|
||||
|
||||
echo "Starting service with command: $cmd"
|
||||
|
||||
nohup $cmd >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
|
||||
|
||||
@@ -54,7 +54,7 @@ function openim::crontask::start() {
|
||||
|
||||
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
|
||||
|
||||
nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
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}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ function openim::msggateway::start() {
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
|
||||
fi
|
||||
|
||||
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") &
|
||||
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}
|
||||
|
||||
@@ -38,7 +38,7 @@ function openim::msgtransfer::start() {
|
||||
|
||||
# Message Transfer Prometheus port list
|
||||
MSG_TRANSFER_PROM_PORTS=(openim::util::list-to-string ${MSG_TRANSFER_PROM_PORT} )
|
||||
|
||||
|
||||
openim::log::status "OpenIM Prometheus ports: ${MSG_TRANSFER_PROM_PORTS[*]}"
|
||||
|
||||
openim::log::status "OpenIM Msggateway config path: ${OPENIM_MSGTRANSFER_CONFIG}"
|
||||
@@ -54,12 +54,14 @@ function openim::msgtransfer::start() {
|
||||
fi
|
||||
|
||||
for (( i=0; i<$OPENIM_MSGGATEWAY_NUM; i++ )) do
|
||||
openim::log::info "prometheus port: ${MSG_TRANSFER_PROM_PORTS[$i]}"
|
||||
PROMETHEUS_PORT_OPTION=""
|
||||
if [[ -n "${OPENIM_PROMETHEUS_PORTS[$i]}" ]]; then
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${OPENIM_PROMETHEUS_PORTS[$i]}"
|
||||
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") &
|
||||
openim::log::info "prometheus port: ${MSG_TRANSFER_PROM_PORTS[$i]}"
|
||||
PROMETHEUS_PORT_OPTION=""
|
||||
if [[ -n "${MSG_TRANSFER_PROM_PORTS[$i+1]}" ]]; then
|
||||
PROMETHEUS_MSG_TRANSFER_PORT="${MSG_TRANSFER_PROM_PORTS[$i+1]%,}"
|
||||
openim::util::stop_services_on_ports ${PROMETHEUS_MSG_TRANSFER_PORT}
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${PROMETHEUS_MSG_TRANSFER_PORT}"
|
||||
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}"
|
||||
|
||||
@@ -73,7 +73,7 @@ function openim::push::start() {
|
||||
|
||||
for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do
|
||||
openim::log::info "start push process, port: ${OPENIM_PUSH_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_PROM_PORTS_ARRAY[$i]}"
|
||||
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") &
|
||||
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
|
||||
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
|
||||
@@ -160,7 +160,7 @@ function openim::rpc::start_service() {
|
||||
printf "Specifying prometheus port: %s\n" "${prometheus_port}"
|
||||
cmd="${cmd} --prometheus_port ${prometheus_port}"
|
||||
fi
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE" >&2) &
|
||||
}
|
||||
|
||||
###################################### Linux Systemd ######################################
|
||||
|
||||
Reference in New Issue
Block a user