feat: add openim env

Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com>
This commit is contained in:
Xinwei Xiong (cubxxw) 2023-12-13 15:59:14 +08:00
parent af54170cf2
commit f875f99dd8
4 changed files with 109 additions and 85 deletions

View File

@ -115,14 +115,14 @@ api:
# minio.signEndpoint is minio public network address # minio.signEndpoint is minio public network address
object: object:
enable: "minio" enable: "minio"
apiURL: "http://172.28.0.1:10002" apiURL: "http://14.155.64.202:10002"
minio: minio:
bucket: "openim" bucket: "openim"
endpoint: "http://172.28.0.1:10005" endpoint: "http://172.28.0.1:10005"
accessKeyID: "root" accessKeyID: "root"
secretAccessKey: "openIM123" secretAccessKey: "openIM123"
sessionToken: '' sessionToken: ''
signEndpoint: "http://172.28.0.1:10005" signEndpoint: "http://14.155.64.202:10005"
publicRead: false publicRead: false
cos: cos:
bucketURL: https://temp-1252357374.cos.ap-chengdu.myqcloud.com bucketURL: https://temp-1252357374.cos.ap-chengdu.myqcloud.com
@ -186,7 +186,7 @@ rpcRegisterName:
# Whether to output in json format # Whether to output in json format
# Whether to include stack trace in logs # Whether to include stack trace in logs
log: log:
storageLocation: ../logs/ storageLocation: /data/workspaces/open-im-server/logs/
rotationTime: 24 rotationTime: 24
remainRotationCount: 2 remainRotationCount: 2
remainLogLevel: 6 remainLogLevel: 6

View File

@ -16,11 +16,11 @@ MINIO_ENDPOINT=http://172.28.0.1:10005
# Base URL for the application programming interface (API). # Base URL for the application programming interface (API).
# Default: API_URL=http://172.28.0.1:10002 # Default: API_URL=http://172.28.0.1:10002
API_URL=http://172.28.0.1:10002 API_URL=http://14.155.64.202:10002
# Directory path for storing data files or related information. # Directory path for storing data files or related information.
# Default: DATA_DIR=./ # Default: DATA_DIR=./
DATA_DIR=./ DATA_DIR=/data/workspaces/open-im-server
# Choose the appropriate image address, the default is GITHUB image, # Choose the appropriate image address, the default is GITHUB image,
# you can choose docker hub, for Chinese users can choose Ali Cloud # you can choose docker hub, for Chinese users can choose Ali Cloud

View File

@ -28,6 +28,8 @@ openim::log::info "\n# Use Docker to start all openim service"
trap 'openim::util::onCtrlC' INT trap 'openim::util::onCtrlC' INT
"${OPENIM_ROOT}"/scripts/init-config.sh --skip
"${OPENIM_ROOT}"/scripts/start-all.sh "${OPENIM_ROOT}"/scripts/start-all.sh
sleep 5 sleep 5

View File

@ -1,17 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Copyright © 2023 OpenIM. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# This script automatically initializes various configuration files and can generate example files. # This script automatically initializes various configuration files and can generate example files.
@ -48,7 +35,8 @@ declare -A EXAMPLES=(
FORCE_OVERWRITE=false FORCE_OVERWRITE=false
SKIP_EXISTING=false SKIP_EXISTING=false
GENERATE_EXAMPLES=false GENERATE_EXAMPLES=false
CLEAN_ENV_EXAMPLES=false CLEAN_CONFIG=false
CLEAN_EXAMPLES=false
# Function to display help information # Function to display help information
show_help() { show_help() {
@ -58,26 +46,21 @@ show_help() {
echo " --force Overwrite existing files without prompt" echo " --force Overwrite existing files without prompt"
echo " --skip Skip generation if file exists" echo " --skip Skip generation if file exists"
echo " --examples Generate example files" echo " --examples Generate example files"
echo " --clean-env-examples Generate example files in a clean environment" echo " --clean-config Clean all configuration files"
echo " --clean-examples Clean all example files"
} }
# Function to generate configuration files # Function to generate configuration files
generate_config_files() { generate_config_files() {
# Loop through each template in TEMPLATES
for template in "${!TEMPLATES[@]}"; do for template in "${!TEMPLATES[@]}"; do
# Read the corresponding output files for the template local output_file="${TEMPLATES[$template]}"
IFS=';' read -ra OUTPUT_FILES <<< "${TEMPLATES[$template]}"
for output_file in "${OUTPUT_FILES[@]}"; do
# Check if the output file already exists
if [[ -f "${output_file}" ]]; then if [[ -f "${output_file}" ]]; then
# Handle existing file based on command-line options
if [[ "${FORCE_OVERWRITE}" == true ]]; then if [[ "${FORCE_OVERWRITE}" == true ]]; then
openim::log::info "Force overwriting ${output_file}." openim::log::info "Force overwriting ${output_file}."
elif [[ "${SKIP_EXISTING}" == true ]]; then elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Skipping generation of ${output_file} as it already exists." openim::log::info "Skipping generation of ${output_file} as it already exists."
continue continue
else else
# Ask user for confirmation to overwrite
echo -n "File ${output_file} already exists. Overwrite? (Y/N): " echo -n "File ${output_file} already exists. Overwrite? (Y/N): "
read -r -n 1 REPLY read -r -n 1 REPLY
echo echo
@ -86,9 +69,12 @@ generate_config_files() {
continue continue
fi fi
fi fi
else
if [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Generating ${output_file} as it does not exist."
fi
fi fi
# Process the template file to generate the output file
openim::log::info "⌚ Working with template file: ${template} to generate ${output_file}..." openim::log::info "⌚ Working with template file: ${template} to generate ${output_file}..."
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
openim::log::error "genconfig.sh script not found" openim::log::error "genconfig.sh script not found"
@ -100,40 +86,62 @@ generate_config_files() {
} }
sleep 0.5 sleep 0.5
done done
done
} }
# Function to generate example files # Function to generate example files
generate_example_files() { generate_example_files() {
for template in "${!EXAMPLES[@]}"; do for template in "${!EXAMPLES[@]}"; do
local example_file="${EXAMPLES[$template]}" local example_file="${EXAMPLES[$template]}"
if [[ ! -f "${example_file}" ]]; then if [[ -f "${example_file}" ]]; then
openim::log::info "Generating example file: ${example_file} from ${template}..." if [[ "${FORCE_OVERWRITE}" == true ]]; then
cp "${template}" "${example_file}" openim::log::info "Force overwriting example file: ${example_file}."
elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Skipping generation of example file: ${example_file} as it already exists."
continue
else
echo -n "Example file ${example_file} already exists. Overwrite? (Y/N): "
read -r -n 1 REPLY
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
openim::log::info "Skipping generation of example file: ${example_file}."
continue
fi
fi
elif [[ "${SKIP_EXISTING}" == true ]]; then
openim::log::info "Generating example file: ${example_file} as it does not exist."
fi
openim::log::info "⌚ Working with template file: ${template} to generate example file: ${example_file}..."
if [[ ! -f "${OPENIM_ROOT}/scripts/genconfig.sh" ]]; then
openim::log::error "genconfig.sh script not found"
exit 1
fi
"${OPENIM_ROOT}/scripts/genconfig.sh" "${ENV_FILE}" "${template}" > "${example_file}" || {
openim::log::error "Error processing template file ${template}"
exit 1
}
sleep 0.5
done
}
# Function to clean configuration files
clean_config_files() {
for output_file in "${TEMPLATES[@]}"; do
if [[ -f "${output_file}" ]]; then
rm -f "${output_file}"
openim::log::info "Removed configuration file: ${output_file}"
fi fi
done done
} }
declare -A env_vars=( # Function to clean example files
["OPENIM_IP"]="172.28.0.1" clean_example_files() {
["DATA_DIR"]="./" for example_file in "${EXAMPLES[@]}"; do
["LOG_STORAGE_LOCATION"]="../logs/" if [[ -f "${example_file}" ]]; then
) rm -f "${example_file}"
openim::log::info "Removed example file: ${example_file}"
generate_clean_environment_examples() { fi
env_cmd="env -i"
for var in "${!env_vars[@]}"; do
env_cmd+=" $var='${env_vars[$var]}'"
done
for template in "${!EXAMPLES[@]}"; do
local example_file="${EXAMPLES[$template]}"
openim::log::info "Generating example file: ${example_file} from ${template}..."
eval "$env_cmd ${OPENIM_ROOT}/scripts/genconfig.sh '${ENV_FILE}' '${template}' > '${example_file}'" || {
openim::log::error "Error processing template file ${template}"
exit 1
}
done done
} }
@ -155,8 +163,12 @@ while [[ $# -gt 0 ]]; do
GENERATE_EXAMPLES=true GENERATE_EXAMPLES=true
shift shift
;; ;;
--clean-env-examples) --clean-config)
CLEAN_ENV_EXAMPLES=true CLEAN_CONFIG=true
shift
;;
--clean-examples)
CLEAN_EXAMPLES=true
shift shift
;; ;;
*) *)
@ -167,19 +179,29 @@ while [[ $# -gt 0 ]]; do
esac esac
done done
# Clean configuration files if --clean-config option is provided
if [[ "${CLEAN_CONFIG}" == true ]]; then
clean_config_files
fi
# Clean example files if --clean-examples option is provided
if [[ "${CLEAN_EXAMPLES}" == true ]]; then
clean_example_files
fi
# Generate configuration files if requested # Generate configuration files if requested
if [[ "${FORCE_OVERWRITE}" == true || "${SKIP_EXISTING}" == false ]]; then if [[ "${FORCE_OVERWRITE}" == true || "${SKIP_EXISTING}" == false ]] && [[ "${CLEAN_CONFIG}" == false ]]; then
generate_config_files
fi
# Generate configuration files if requested
if [[ "${SKIP_EXISTING}" == true ]]; then
generate_config_files generate_config_files
fi fi
# Generate example files if --examples option is provided # Generate example files if --examples option is provided
if [[ "${GENERATE_EXAMPLES}" == true ]]; then if [[ "${GENERATE_EXAMPLES}" == true ]] && [[ "${CLEAN_EXAMPLES}" == false ]]; then
generate_example_files generate_example_files
fi fi
# Generate example files in a clean environment if --clean-env-examples option is provided openim::log::success "Configuration and example files operation complete!"
if [[ "${CLEAN_ENV_EXAMPLES}" == true ]]; then
generate_clean_environment_examples
fi
openim::log::success "Configuration and example files generation complete!"