From e21c25246a42d5049f6f868c93ed605a3a5cecf9 Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Thu, 7 Mar 2024 16:59:16 +0800 Subject: [PATCH] Optimizing Docker-related scripts and logs (#448) * Optimize the script * Optimize the script * Optimize the script * Optimize the script * delete wechat * delete wechat --- README.md | 10 ++++- scripts/check-all.sh | 7 ++++ scripts/docker-start-all.sh | 81 ++----------------------------------- scripts/start-all.sh | 25 ++++++++++-- scripts/util.sh | 11 +++++ 5 files changed, 52 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index ff654cd1b..d0bf6aef9 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,15 @@ You may use the OpenIM source code to create compiled versions not originally pr 3. User related part includes some regular functions like user login, user register, user info update, etc. 4. Background management provides api for admin to manage the im system containing functions like user management, message mangement,group management,etc. +## :busts_in_silhouette: Community + ++ ๐Ÿ’ฌ [Follow our Twitter account](https://twitter.com/founder_im63606) ++ ๐Ÿ‘ซ [Join our Reddit](https://www.reddit.com/r/OpenIMessaging) ++ ๐Ÿš€ [Join our Slack community](https://join.slack.com/t/openimsdk/shared_invite/zt-22720d66b-o_FvKxMTGXtcnnnHiMqe9Q) ++ :eyes: [Join our wechat (ๅพฎไฟก็พค)](https://openim-1253691595.cos.ap-nanjing.myqcloud.com/WechatIMG20.jpeg) ++ ๐Ÿ“š [OpenIM Community](https://github.com/OpenIMSDK/community) ++ ๐Ÿ’• [OpenIM Interest Group](https://github.com/Openim-sigs) + ## ๐Ÿ›ซ Quick start > **Note**: You can get started quickly with OpenIM Chat. @@ -201,7 +210,6 @@ We take notes of each [biweekly meeting](https://github.com/openimsdk/open-im-se ## Who are using open-im-server The [user case studies](https://github.com/openimsdk/community/blob/main/ADOPTERS.md) page includes the user list of the project. You can leave a [๐Ÿ“comment](https://github.com/openimsdk/open-im-server/issues/379) to let us know your use case. -![avatar](https://github.com/openimsdk/OpenIM-Docs/blob/main/docs/images/WechatIMG20.jpeg) ## ๐Ÿšจ License diff --git a/scripts/check-all.sh b/scripts/check-all.sh index 69da02f7e..f6b3da133 100755 --- a/scripts/check-all.sh +++ b/scripts/check-all.sh @@ -17,8 +17,13 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) OPENIM_ROOT=$(dirname "${SCRIPTS_ROOT}")/.. +source $SCRIPTS_ROOT/util.sh +DOCKER_LOG_FILE="$logs_dir/chat-docker.log" +if is_running_in_container; then + exec >> ${DOCKER_LOG_FILE} 2>&1 +fi @@ -54,6 +59,7 @@ for binary_path in "${binary_full_paths[@]}"; do # Print the binary path in red for not running services echo -e "\033[0;31mService not running: $binary_path\033[0m" fi + exit 1 done if $all_services_running; then @@ -62,4 +68,5 @@ if $all_services_running; then else # Print the number of services that are not running echo -e "\033[0;31m$not_running_count chat service(s) are not running.\033[0m" + exit 1 fi diff --git a/scripts/docker-start-all.sh b/scripts/docker-start-all.sh index 35a47c0f0..61bb5aa87 100755 --- a/scripts/docker-start-all.sh +++ b/scripts/docker-start-all.sh @@ -21,82 +21,9 @@ SCRIPTS_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -source "$SCRIPTS_ROOT/style-info.sh" -source "$SCRIPTS_ROOT/path-info.sh" -source "$SCRIPTS_ROOT/function.sh" +logs_dir="$SCRIPTS_ROOT/../_output/logs" +DOCKER_LOG_FILE="$logs_dir/chat-docker.log" -bin_dir="$BIN_DIR" -logs_dir="$SCRIPTS_ROOT/../logs" -if [ ! -d "$logs_dir" ]; then - echo "mkdir -p $logs_dir" - mkdir -p "$logs_dir" -fi - - -# Service filenames -service_filenames=( - chat-api - admin-api - #rpc - admin-rpc - chat-rpc -) - -# Service config port names -service_port_names=( - openImChatApiPort - openImAdminApiPort - #api port name - openImAdminPort - openImChatPort -) - -service_prometheus_port_names=() - -${OPENIM_ROOT}/scripts/init-config.sh --skip - -cd "$SCRIPTS_ROOT" - -# Function to kill a service -kill_service() { - local service_name=$1 - local pid=$(pgrep -f "$service_name") - if [ -n "$pid" ]; then - killall "$service_name" - sleep 0.5 - fi -} - -for ((i = 0; i < ${#service_filenames[*]}; i++)); do - service_name="${service_filenames[$i]}" - kill_service "$service_name" - cd "$SCRIPTS_ROOT" - - # Get the rpc ports from the configuration file - readarray -t portList < "$config_path" - service_ports=() - for line in "${portList[@]}"; do - if [[ $line == *"${service_port_names[$i]}"* ]]; then - port=$(echo "$line" | awk -F '[ ]+' '{print $4} ') - service_ports+=("$port") - fi - done - - # Start related rpc services based on the number of ports - for port in "${service_ports[@]}"; do - # Start the service in the background - cmd="$bin_dir/$service_name -port $port --config_folder_path $config_path" - if [[ $i -eq 0 || $i -eq 1 ]]; then - cmd="$bin_dir/$service_name -port $port --config_folder_path $config_path" - fi - echo "$cmd" - nohup $cmd >> "${logs_dir}/chat_$(date '+%Y%m%d').log" 2>&1 & - sleep 1 - done -done - -sleep 50 -${OPENIM_ROOT}/scripts/check-all.sh - -tail -f ${logs_dir}/chat_$(date '+%Y%m%d').log +"${OPENIM_ROOT}"/scripts/start-all.sh +tail -f ${DOCKER_LOG_FILE} diff --git a/scripts/start-all.sh b/scripts/start-all.sh index eac65f6b3..811a2a58a 100755 --- a/scripts/start-all.sh +++ b/scripts/start-all.sh @@ -35,10 +35,28 @@ source $SCRIPTS_ROOT/util.sh bin_dir="$BIN_DIR" logs_dir="$SCRIPTS_ROOT/../_output/logs" +DOCKER_LOG_FILE="$logs_dir/chat-docker.log" # Define the path to the configuration file CONFIG_FILE="${OPENIM_ROOT}/config/config.yaml" +# Automatically created when there is no bin, logs folder +if [[ ! -d "$logs_dir" ]]; then + mkdir -p "$logs_dir" +fi + +if [[ ! -f "$DOCKER_LOG_FILE" ]]; then + touch "$DOCKER_LOG_FILE" +fi + + + + +if is_running_in_container; then + exec > ${DOCKER_LOG_FILE} 2>&1 +fi + + # Check if the configuration file exists if [ -f "$CONFIG_FILE" ]; then # The file exists @@ -136,10 +154,9 @@ fi -# Automatically created when there is no bin, logs folder -if [ ! -d $logs_dir ]; then - mkdir -p $logs_dir -fi + + + cd $SCRIPTS_ROOT rm -rf ${logs_dir}/chat_tmp_$(date '+%Y%m%d').log diff --git a/scripts/util.sh b/scripts/util.sh index 75cc48826..2326668b0 100755 --- a/scripts/util.sh +++ b/scripts/util.sh @@ -106,3 +106,14 @@ print_red() { # Replace "/full/path/to/binary" with the actual full path of the binary you want to check # check_services_with_name "/full/path/to/binary" + + +function is_running_in_container() { + if grep -qE 'docker|kubepods' /proc/1/cgroup || [ -f /.dockerenv ]; then + return 0 + else + return 1 + fi +} + +