Skip to content

Commit

Permalink
Optimizing Docker-related scripts and logs (#448)
Browse files Browse the repository at this point in the history
* Optimize the script

* Optimize the script

* Optimize the script

* Optimize the script

* delete wechat

* delete wechat
  • Loading branch information
skiffer-git committed Mar 7, 2024
1 parent 8c493e6 commit e21c252
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 82 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions scripts/check-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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



Expand Down Expand Up @@ -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
Expand All @@ -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
81 changes: 4 additions & 77 deletions scripts/docker-start-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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}
25 changes: 21 additions & 4 deletions scripts/start-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions scripts/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


0 comments on commit e21c252

Please sign in to comment.