fix: fix docker compose scripts (#1546)
* fix: fix docker compose scripts Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> * fix: fix scripts and rea Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
parent
60f4f67fb7
commit
bb6462647a
|
@ -11,7 +11,7 @@ OpenIM, an intricate project, requires a robust logging mechanism to diagnose is
|
|||
1. **Initialization**: The system begins by determining the verbosity level through the `OPENIM_VERBOSE` variable. If it's not set, a default value of 5 is assigned. This verbosity level dictates the depth of the log details.
|
||||
2. **Log File Setup**: Logs are stored in the directory specified by `OPENIM_OUTPUT`. If this variable isn't explicitly set, it defaults to the `_output` directory relative to the script location. Each log file is named based on the date to facilitate easy identification.
|
||||
3. **Logging Function**: The `echo_log()` function plays a pivotal role by writing messages to both the console (stdout) and the log file.
|
||||
4. **Logging to a file**: The `echo_log()` function writes to the log file by appending the message to the file. It also adds a timestamp to the message. path: `_output/logs/*`, Enable logging by default. Set to false to disable. If you wish to turn off output to log files set `ENABLE_LOGGING=flase`.
|
||||
4. **Logging to a file**: The `echo_log()` function writes to the log file by appending the message to the file. It also adds a timestamp to the message. path: `_output/logs/*`, Enable logging by default. Set to false to disable. If you wish to turn off output to log files set `export ENABLE_LOGGING=flase`.
|
||||
|
||||
### Key Functions & Their Usages
|
||||
|
||||
|
|
176
install_guide.sh
176
install_guide.sh
|
@ -1,176 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
echo "Welcome to the Open-IM-Server installation scripts."
|
||||
echo "Please select an deploy option:"
|
||||
echo "1. docker-compose install"
|
||||
echo "2. exit"
|
||||
|
||||
clear_openimlog() {
|
||||
rm -rf ./logs/*
|
||||
}
|
||||
|
||||
is_path() {
|
||||
if [ -e "$1" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
is_empty() {
|
||||
if [ -z "$1" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
is_directory_exists() {
|
||||
if [ -d "$1" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
edit_config() {
|
||||
echo "Is edit config.yaml?"
|
||||
echo "1. vi edit config"
|
||||
echo "2. do not edit config"
|
||||
read choice
|
||||
case $choice in
|
||||
1)
|
||||
vi config/config.yaml
|
||||
;;
|
||||
2)
|
||||
echo "do not edit config"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
edit_enterprise_config() {
|
||||
echo "Is edit enterprise config.yaml?"
|
||||
echo "1. vi edit enterprise config"
|
||||
echo "2. do not edit enterprise config"
|
||||
read choice
|
||||
case $choice in
|
||||
1)
|
||||
vi ./.docker-compose_cfg/config.yaml
|
||||
;;
|
||||
2)
|
||||
echo "Do not edit enterprise config"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
install_docker_compose() {
|
||||
echo "Please input the installation path, default is $(pwd)/Open-IM-Server, press enter to use default"
|
||||
read install_path
|
||||
is_empty $install_path
|
||||
if [ $? -eq 1 ]; then
|
||||
install_path="."
|
||||
fi
|
||||
echo "Installing Open-IM-Server to ${install_path}/Open-IM-Server..."
|
||||
is_path $install_path
|
||||
mkdir -p $install_path
|
||||
cd $install_path
|
||||
is_directory_exists "${install_path}/Open-IM-Server"
|
||||
if [ $? -eq 1 ]; then
|
||||
echo "WARNING: Directory $install_path/Open-IM-Server exist, please ensure your path"
|
||||
echo "1. delete the directory and install"
|
||||
echo "2. exit"
|
||||
read choice
|
||||
case $choice in
|
||||
1)
|
||||
rm -rf "${install_path}/Open-IM-Server"
|
||||
;;
|
||||
2)
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
rm -rf ./Open-IM-Server
|
||||
set -e
|
||||
git clone https://github.com/openimsdk/open-im-server.git --recursive;
|
||||
set +e
|
||||
cd ./Open-IM-Server
|
||||
git checkout errcode
|
||||
echo "======== git clone success ========"
|
||||
source .env
|
||||
if [ $DATA_DIR = "./" ]; then
|
||||
DATA_DIR=$(pwd)/components
|
||||
fi
|
||||
echo "Please input the components data directory, deault is ${DATA_DIR}, press enter to use default"
|
||||
read NEW_DATA_DIR
|
||||
is_empty $NEW_DATA_DIR
|
||||
if [ $? -eq 0 ]; then
|
||||
DATA_DIR=$NEW_DATA_DIR
|
||||
fi
|
||||
echo "Please input the user, deault is root, press enter to use default"
|
||||
read NEW_USER
|
||||
is_empty $NEW_USER
|
||||
if [ $? -eq 0 ]; then
|
||||
OPENIM_USER=$NEW_USER
|
||||
fi
|
||||
|
||||
echo "Please input the password, default is openIM123, press enter to use default"
|
||||
read NEW_PASSWORD
|
||||
is_empty $NEW_PASSWORD
|
||||
if [ $? -eq 0 ]; then
|
||||
PASSWORD=$NEW_PASSWORD
|
||||
fi
|
||||
|
||||
echo "Please input the minio_endpoint, default will detect auto, press enter to use default"
|
||||
read NEW_MINIO_ENDPOINT
|
||||
is_empty $NEW_MINIO_ENDPOINT
|
||||
if [ $? -eq 1 ]; then
|
||||
internet_ip=`curl ifconfig.me -s`
|
||||
MINIO_ENDPOINT="http://${internet_ip}:10005"
|
||||
else
|
||||
MINIO_ENDPOINT=$NEW_MINIO_ENDPOINT
|
||||
fi
|
||||
set -e
|
||||
export MINIO_ENDPOINT
|
||||
export OPENIM_USER
|
||||
export PASSWORD
|
||||
export DATA_DIR
|
||||
|
||||
cat <<EOF > .env
|
||||
OPENIM_USER=${OPENIM_USER}
|
||||
PASSWORD=${PASSWORD}
|
||||
MINIO_ENDPOINT=${MINIO_ENDPOINT}
|
||||
DATA_DIR=${DATA_DIR}
|
||||
EOF
|
||||
|
||||
edit_config
|
||||
edit_enterprise_config
|
||||
|
||||
cd scripts;
|
||||
chmod +x *.sh;
|
||||
./init-pwd.sh;
|
||||
./env_check.sh;
|
||||
cd ..;
|
||||
docker-compose up -d;
|
||||
cd scripts;
|
||||
./docker-check-service.sh;
|
||||
}
|
||||
|
||||
read choice
|
||||
|
||||
case $choice in
|
||||
1)
|
||||
install_docker_compose
|
||||
;;
|
||||
2)
|
||||
|
||||
;;
|
||||
3)
|
||||
;;
|
||||
4)
|
||||
echo "Exiting installation scripts..."
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Invalid option, please try again."
|
||||
;;
|
||||
esac
|
|
@ -16,14 +16,12 @@ package msg
|
|||
|
||||
import (
|
||||
"context"
|
||||
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||
|
||||
utils2 "github.com/OpenIMSDK/tools/utils"
|
||||
|
||||
"github.com/redis/go-redis/v9"
|
||||
|
||||
cbapi "github.com/openimsdk/open-im-server/v3/pkg/callbackstruct"
|
||||
"github.com/OpenIMSDK/protocol/constant"
|
||||
"github.com/OpenIMSDK/protocol/conversation"
|
||||
"github.com/OpenIMSDK/protocol/msg"
|
||||
"github.com/OpenIMSDK/protocol/sdkws"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
|
@ -92,7 +90,10 @@ func (m *msgServer) SetConversationHasReadSeq(
|
|||
return &msg.SetConversationHasReadSeqResp{}, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadReq) (resp *msg.MarkMsgsAsReadResp, err error) {
|
||||
func (m *msgServer) MarkMsgsAsRead(
|
||||
ctx context.Context,
|
||||
req *msg.MarkMsgsAsReadReq,
|
||||
) (resp *msg.MarkMsgsAsReadResp, err error) {
|
||||
if len(req.Seqs) < 1 {
|
||||
return nil, errs.ErrArgs.Wrap("seqs must not be empty")
|
||||
}
|
||||
|
@ -111,6 +112,7 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR
|
|||
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, req.Seqs); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
currentHasReadSeq, err := m.MsgDatabase.GetHasReadSeq(ctx, req.UserID, req.ConversationID)
|
||||
if err != nil && errs.Unwrap(err) != redis.Nil {
|
||||
return
|
||||
|
@ -128,7 +130,10 @@ func (m *msgServer) MarkMsgsAsRead(ctx context.Context, req *msg.MarkMsgsAsReadR
|
|||
return &msg.MarkMsgsAsReadResp{}, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkConversationAsReadReq) (resp *msg.MarkConversationAsReadResp, err error) {
|
||||
func (m *msgServer) MarkConversationAsRead(
|
||||
ctx context.Context,
|
||||
req *msg.MarkConversationAsReadReq,
|
||||
) (resp *msg.MarkConversationAsReadResp, err error) {
|
||||
conversation, err := m.Conversation.GetConversation(ctx, req.UserID, req.ConversationID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -137,34 +142,54 @@ func (m *msgServer) MarkConversationAsRead(ctx context.Context, req *msg.MarkCon
|
|||
if err != nil && errs.Unwrap(err) != redis.Nil {
|
||||
return nil, err
|
||||
}
|
||||
seqs := generateSeqs(hasReadSeq, req)
|
||||
var seqs []int64
|
||||
|
||||
if len(seqs) > 0 || req.HasReadSeq > hasReadSeq {
|
||||
err = m.updateReadStatus(ctx, req, conversation, seqs, hasReadSeq)
|
||||
if err != nil {
|
||||
log.ZDebug(ctx, "MarkConversationAsRead", "hasReadSeq", hasReadSeq,
|
||||
"req.HasReadSeq", req.HasReadSeq)
|
||||
if conversation.ConversationType == constant.SingleChatType {
|
||||
for i := hasReadSeq + 1; i <= req.HasReadSeq; i++ {
|
||||
seqs = append(seqs, i)
|
||||
}
|
||||
//avoid client missed call MarkConversationMessageAsRead by order
|
||||
for _, val := range req.Seqs {
|
||||
if !utils2.Contain(val, seqs...) {
|
||||
seqs = append(seqs, val)
|
||||
}
|
||||
}
|
||||
if len(seqs) > 0 {
|
||||
log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID)
|
||||
if err = m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if req.HasReadSeq > hasReadSeq {
|
||||
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hasReadSeq = req.HasReadSeq
|
||||
}
|
||||
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID,
|
||||
m.conversationAndGetRecvID(conversation, req.UserID), seqs, hasReadSeq); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return &msg.MarkConversationAsReadResp{}, nil
|
||||
}
|
||||
|
||||
func generateSeqs(hasReadSeq int64, req *msg.MarkConversationAsReadReq) []int64 {
|
||||
var seqs []int64
|
||||
for _, val := range req.Seqs {
|
||||
if val > hasReadSeq && !utils2.Contain(val, seqs...) {
|
||||
seqs = append(seqs, val)
|
||||
|
||||
} else if conversation.ConversationType == constant.SuperGroupChatType ||
|
||||
conversation.ConversationType == constant.NotificationChatType {
|
||||
if req.HasReadSeq > hasReadSeq {
|
||||
err = m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hasReadSeq = req.HasReadSeq
|
||||
}
|
||||
}
|
||||
return seqs
|
||||
}
|
||||
|
||||
func (m *msgServer) updateReadStatus(ctx context.Context, req *msg.MarkConversationAsReadReq, conversation *conversation.Conversation, seqs []int64, hasReadSeq int64) error {
|
||||
if conversation.ConversationType == constant.SingleChatType && len(seqs) > 0 {
|
||||
log.ZDebug(ctx, "MarkConversationAsRead", "seqs", seqs, "conversationID", req.ConversationID)
|
||||
if err := m.MsgDatabase.MarkSingleChatMsgsAsRead(ctx, req.UserID, req.ConversationID, seqs); err != nil {
|
||||
return err
|
||||
if err = m.sendMarkAsReadNotification(ctx, req.ConversationID, constant.SingleChatType, req.UserID,
|
||||
req.UserID, seqs, hasReadSeq); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
reqCall := &cbapi.CallbackGroupMsgReadReq{
|
||||
SendID: conversation.OwnerUserID,
|
||||
ReceiveID: req.UserID,
|
||||
|
@ -172,21 +197,10 @@ func (m *msgServer) updateReadStatus(ctx context.Context, req *msg.MarkConversat
|
|||
ContentType: int64(conversation.ConversationType),
|
||||
}
|
||||
if err := CallbackGroupMsgRead(ctx, reqCall); err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if req.HasReadSeq > hasReadSeq {
|
||||
if err := m.MsgDatabase.SetHasReadSeq(ctx, req.UserID, req.ConversationID, req.HasReadSeq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
recvID := m.conversationAndGetRecvID(conversation, req.UserID)
|
||||
if conversation.ConversationType == constant.SuperGroupChatType || conversation.ConversationType == constant.NotificationChatType {
|
||||
recvID = req.UserID
|
||||
}
|
||||
|
||||
return m.sendMarkAsReadNotification(ctx, req.ConversationID, conversation.ConversationType, req.UserID, recvID, seqs, req.HasReadSeq)
|
||||
return &msg.MarkConversationAsReadResp{}, nil
|
||||
}
|
||||
|
||||
func (m *msgServer) sendMarkAsReadNotification(
|
||||
|
@ -208,4 +222,4 @@ func (m *msgServer) sendMarkAsReadNotification(
|
|||
log.ZWarn(ctx, "send has read Receipt err", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
|
@ -24,12 +24,10 @@ OPENIM_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
|||
|
||||
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||
|
||||
# (en: Define a profile array that contains the name path of the profile to be generated.)
|
||||
readonly ENV_FILE=${ENV_FILE:-"${OPENIM_ROOT}/scripts/install/environment.sh"}
|
||||
|
||||
# (en: Defines an associative array where the keys are the template files and the values are the corresponding output files.)
|
||||
declare -A TEMPLATES=(
|
||||
["${OPENIM_ROOT}/deployments/templates/env_template.yaml"]="${OPENIM_ROOT}/.env"
|
||||
["${OPENIM_ROOT}/deployments/templates/env-template.yaml"]="${OPENIM_ROOT}/.env"
|
||||
["${OPENIM_ROOT}/deployments/templates/openim.yaml"]="${OPENIM_ROOT}/config/config.yaml"
|
||||
["${OPENIM_ROOT}/deployments/templates/prometheus.yml"]="${OPENIM_ROOT}/config/prometheus.yml"
|
||||
["${OPENIM_ROOT}/deployments/templates/alertmanager.yml"]="${OPENIM_ROOT}/config/alertmanager.yml"
|
||||
|
@ -37,6 +35,42 @@ declare -A TEMPLATES=(
|
|||
|
||||
openim::log::info "Read more configuration information: https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/environment.md"
|
||||
|
||||
# New variables for argument handling
|
||||
FORCE_OVERWRITE=false
|
||||
SKIP_EXISTING=false
|
||||
|
||||
# Function to display help
|
||||
show_help() {
|
||||
echo "Usage: $(basename "$0") [options]"
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message"
|
||||
echo " --force Overwrite existing files without prompt"
|
||||
echo " --skip Skip generation if file exists"
|
||||
}
|
||||
|
||||
# Parse command-line options
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
show_help
|
||||
exit 0
|
||||
;;
|
||||
--force)
|
||||
FORCE_OVERWRITE=true
|
||||
shift
|
||||
;;
|
||||
--skip)
|
||||
SKIP_EXISTING=true
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
echo "Unknown option: $1"
|
||||
show_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
for template in "${!TEMPLATES[@]}"; do
|
||||
if [[ ! -f "${template}" ]]; then
|
||||
openim::log::error_exit "Template file ${template} does not exist..."
|
||||
|
@ -48,14 +82,19 @@ for template in "${!TEMPLATES[@]}"; do
|
|||
IFS=';' read -ra OUTPUT_FILES <<< "${TEMPLATES[$template]}"
|
||||
for output_file in "${OUTPUT_FILES[@]}"; do
|
||||
if [[ -f "${output_file}" ]]; then
|
||||
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
|
||||
read -r -n 1 REPLY
|
||||
echo # Adds a line to wrap after user input
|
||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||
openim::log::info "Overwriting ${output_file}. Previous configuration will be lost."
|
||||
else
|
||||
openim::log::info "Skipping generation of ${output_file}."
|
||||
if [[ "${FORCE_OVERWRITE}" == true ]]; then
|
||||
openim::log::info "Force overwriting ${output_file}."
|
||||
elif [[ "${SKIP_EXISTING}" == true ]]; then
|
||||
openim::log::info "Skipping generation of ${output_file} as it already exists."
|
||||
continue
|
||||
else
|
||||
echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
|
||||
read -r -n 1 REPLY
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
openim::log::info "Skipping generation of ${output_file}."
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -72,5 +111,4 @@ for template in "${!TEMPLATES[@]}"; do
|
|||
done
|
||||
done
|
||||
|
||||
|
||||
openim::log::success "✨ All configuration files have been successfully generated!"
|
||||
|
|
|
@ -66,7 +66,7 @@ function openim::api::start() {
|
|||
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 1
|
||||
sleep 2
|
||||
done
|
||||
done
|
||||
|
||||
|
|
|
@ -138,7 +138,7 @@ function openim::rpc::start() {
|
|||
done
|
||||
done
|
||||
|
||||
sleep 0.5
|
||||
sleep 1
|
||||
|
||||
openim::util::check_ports ${OPENIM_RPC_PORT_TARGETS[@]}
|
||||
# openim::util::check_ports ${OPENIM_RPC_PROM_PORT_TARGETS[@]}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
OPENIM_VERBOSE="${OPENIM_VERBOSE:-5}"
|
||||
|
||||
# Enable logging by default. Set to false to disable.
|
||||
ENABLE_LOGGING=true
|
||||
ENABLE_LOGGING="${ENABLE_LOGGING:-true}"
|
||||
|
||||
# If OPENIM_OUTPUT is not set, set it to the default value
|
||||
if [[ ! -v OPENIM_OUTPUT ]]; then
|
||||
|
|
Loading…
Reference in New Issue