From f3d4c8dc5608067c4df17b4f283fcb08e41a0671 Mon Sep 17 00:00:00 2001 From: "Xinwei Xiong (cubxxw)" <3293172751nss@gmail.com> Date: Fri, 2 Feb 2024 16:13:08 +0800 Subject: [PATCH] feat: support openim readme docs Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> --- pkg/common/cmd/root.go | 1 - scripts/check-all.sh | 10 ++++++++++ scripts/install/openim-api.sh | 3 +-- scripts/install/openim-crontask.sh | 3 ++- scripts/install/openim-msggateway.sh | 2 +- scripts/install/openim-msgtransfer.sh | 4 +++- scripts/install/openim-push.sh | 4 +++- scripts/install/openim-rpc.sh | 2 +- scripts/lib/logging.sh | 4 ++++ 9 files changed, 25 insertions(+), 8 deletions(-) diff --git a/pkg/common/cmd/root.go b/pkg/common/cmd/root.go index 66bec61a7..98ca8f892 100644 --- a/pkg/common/cmd/root.go +++ b/pkg/common/cmd/root.go @@ -20,7 +20,6 @@ import ( config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config" "github.com/spf13/cobra" - _ "go.uber.org/automaxprocs" "github.com/OpenIMSDK/protocol/constant" "github.com/OpenIMSDK/tools/log" diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 1f6b740e6..062605ae1 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -49,6 +49,14 @@ 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 @@ -94,3 +102,5 @@ else fi set -e + +trap - ERR \ No newline at end of file diff --git a/scripts/install/openim-api.sh b/scripts/install/openim-api.sh index 2c3c19afb..631a0ee3a 100755 --- a/scripts/install/openim-api.sh +++ b/scripts/install/openim-api.sh @@ -80,8 +80,7 @@ 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>&1 & + nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") & if [ $? -ne 0 ]; then openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}." diff --git a/scripts/install/openim-crontask.sh b/scripts/install/openim-crontask.sh index cc9e686ff..c8d46c5ce 100755 --- a/scripts/install/openim-crontask.sh +++ b/scripts/install/openim-crontask.sh @@ -50,8 +50,9 @@ function openim::crontask::start() { 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>&1 & + nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") & openim::util::check_process_names ${SERVER_NAME} + } ###################################### Linux Systemd ###################################### diff --git a/scripts/install/openim-msggateway.sh b/scripts/install/openim-msggateway.sh index d9fec4928..641eaf02e 100755 --- a/scripts/install/openim-msggateway.sh +++ b/scripts/install/openim-msggateway.sh @@ -61,7 +61,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>&1 & + nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") & done openim::util::check_process_names ${SERVER_NAME} diff --git a/scripts/install/openim-msgtransfer.sh b/scripts/install/openim-msgtransfer.sh index 1cead3a9a..0e2622d5d 100755 --- a/scripts/install/openim-msgtransfer.sh +++ b/scripts/install/openim-msgtransfer.sh @@ -56,7 +56,9 @@ function openim::msgtransfer::start() { 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>&1 & + nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") & + PID=$! + wait $PID done openim::util::check_process_names "${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}" diff --git a/scripts/install/openim-push.sh b/scripts/install/openim-push.sh index d43743e4f..f7bd58649 100755 --- a/scripts/install/openim-push.sh +++ b/scripts/install/openim-push.sh @@ -70,7 +70,9 @@ 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>&1 & + nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") & + PID=$! + wait $PID done openim::util::check_process_names ${SERVER_NAME} diff --git a/scripts/install/openim-rpc.sh b/scripts/install/openim-rpc.sh index 966eef928..87a315841 100755 --- a/scripts/install/openim-rpc.sh +++ b/scripts/install/openim-rpc.sh @@ -157,7 +157,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>&1 & + nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") & } ###################################### Linux Systemd ###################################### diff --git a/scripts/lib/logging.sh b/scripts/lib/logging.sh index c520850e8..2fa77dd83 100755 --- a/scripts/lib/logging.sh +++ b/scripts/lib/logging.sh @@ -26,10 +26,14 @@ fi # Set the log file path LOG_FILE="${OPENIM_OUTPUT}/logs/openim_$(date '+%Y%m%d').log" +STDERR_LOG_FILE="${OPENIM_OUTPUT}/logs/openim_error_$(date '+%Y%m%d').log" +TMP_LOG_FILE="${OPENIM_OUTPUT}/logs/openim_tmp_$(date '+%Y%m%d').log" if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then mkdir -p "${OPENIM_OUTPUT}/logs" touch "$LOG_FILE" + touch "$STDERR_LOG_FILE" + touch "$TMP_LOG_FILE" fi # Define the logging function