anxin-ruoyi/docker/configs/startup.sh
2026-01-08 20:47:24 +08:00

72 lines
2.0 KiB
Bash
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 后端应用启动脚本
# 负责验证环境配置并启动Spring Boot应用
set -e
# 导入环境配置脚本
source /app/scripts/backend-env.sh
echo "=== 安信数字信贷系统后端启动 ==="
echo "启动时间: $(date)"
echo "时区: $TZ"
# 验证必需的环境变量
echo "正在验证环境配置..."
if ! validate_required_env; then
echo "环境配置验证失败,退出启动"
exit 1
fi
# 显示当前配置
show_config
# 等待数据库服务可用
echo "正在等待数据库服务可用..."
max_attempts=30
attempt=1
while [ $attempt -le $max_attempts ]; do
if nc -z "$DB_HOST" "$DB_PORT" 2>/dev/null; then
echo "数据库服务已可用 ($DB_HOST:$DB_PORT)"
break
fi
echo "等待数据库服务... (尝试 $attempt/$max_attempts)"
sleep 2
attempt=$((attempt + 1))
done
if [ $attempt -gt $max_attempts ]; then
echo "错误: 无法连接到数据库服务 $DB_HOST:$DB_PORT"
exit 1
fi
# 创建必要的目录
mkdir -p "$LOG_PATH" "$UPLOAD_PATH"
# 设置Spring Boot配置文件路径使用Docker专用配置
export SPRING_CONFIG_LOCATION="classpath:/application.yml,/app/config/application-docker.yml"
# 构建完整的Java启动命令
JAVA_CMD="java $JAVA_OPTS \
-Dserver.port=$SERVER_PORT \
-Dspring.profiles.active=$SPRING_PROFILES_ACTIVE \
-Dlogging.config=/app/config/logback-spring.xml \
-Dlog.path=$LOG_PATH \
-DLOG_PATH=$LOG_PATH \
-DLOG_LEVEL=$LOG_LEVEL \
-Dlogging.path=$LOG_PATH \
-Dlogging.file.path=$LOG_PATH \
-Druoyi.profile=$UPLOAD_PATH \
-Dspring.datasource.url=jdbc:mysql://$DB_HOST:$DB_PORT/$DB_NAME?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true \
-Dspring.datasource.username=$DB_USER \
-Dspring.datasource.password=$DB_PASSWORD \
-jar app.jar"
echo "启动命令: $JAVA_CMD"
echo "=== 应用启动中... ==="
# 启动应用
exec $JAVA_CMD