|
|
@@ -1,24 +1,67 @@
|
|
|
#!/bin/bash
|
|
|
|
|
|
-# 浠艾福(CFC) 后端启动脚本
|
|
|
-# JVM 参数: G1GC, 512m初始堆, 2g最大堆
|
|
|
-# 用法: ./start.sh [--debug]
|
|
|
+set -e
|
|
|
+
|
|
|
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
|
+APP_DIR="${SCRIPT_DIR}"
|
|
|
+CONFIG_DIR="${APP_DIR}/config"
|
|
|
+JAR_FILE="${APP_DIR}/target/cfc-backend-1.0.0.jar"
|
|
|
|
|
|
DEBUG_FLAG=""
|
|
|
-if [ "$1" = "--debug" ]; then
|
|
|
- DEBUG_FLAG="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n"
|
|
|
+ENV="dev"
|
|
|
+
|
|
|
+for arg in "$@"; do
|
|
|
+ case "$arg" in
|
|
|
+ --debug) DEBUG_FLAG="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n" ;;
|
|
|
+ dev) ENV="dev" ;;
|
|
|
+ prod) ENV="prod" ;;
|
|
|
+ local) ENV="local" ;;
|
|
|
+ esac
|
|
|
+done
|
|
|
+
|
|
|
+if [ -z "$FORCE_PROFILE" ] && hostname | grep -qiE "dev|local|test|docker|container"; then
|
|
|
+ ENV="local"
|
|
|
+fi
|
|
|
+
|
|
|
+case "$ENV" in
|
|
|
+ prod)
|
|
|
+ DB_HOST="${DB_HOST:-192.168.16.251}"
|
|
|
+ DB_PORT="${DB_PORT:-3306}"
|
|
|
+ DB_NAME="${DB_NAME:-zxyj}"
|
|
|
+ DB_USER="${DB_USER:-zxyj}"
|
|
|
+ DB_PASS="${DB_PASS:-zxyj@123}"
|
|
|
+ ;;
|
|
|
+ *)
|
|
|
+ DB_HOST="${DB_HOST:-127.0.0.1}"
|
|
|
+ DB_PORT="${DB_PORT:-3306}"
|
|
|
+ DB_NAME="${DB_NAME:-zxyj}"
|
|
|
+ DB_USER="${DB_USER:-root}"
|
|
|
+ DB_PASS="${DB_PASS:-cfc123}"
|
|
|
+ ;;
|
|
|
+esac
|
|
|
+
|
|
|
+DB_URL="jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true"
|
|
|
+
|
|
|
+echo "[CFC] ENV=${ENV}, DB=${DB_HOST}:${DB_PORT}/${DB_NAME}"
|
|
|
+
|
|
|
+JAVA_OPTS="
|
|
|
+ -Xms512m
|
|
|
+ -Xmx2g
|
|
|
+ -XX:+UseG1GC
|
|
|
+ -XX:MaxGCPauseMillis=200
|
|
|
+ -XX:+HeapDumpOnOutOfMemoryError
|
|
|
+ -XX:HeapDumpPath=/tmp/cfc-heapdump.hprof
|
|
|
+ -Dfile.encoding=UTF-8
|
|
|
+ -Dspring.profiles.active=${ENV}
|
|
|
+ -Dspring.datasource.url=\"${DB_URL}\"
|
|
|
+ -Dspring.datasource.username=${DB_USER}
|
|
|
+ -Dspring.datasource.password=${DB_PASS}
|
|
|
+"
|
|
|
+
|
|
|
+SPRING_CONFIG_LOC=""
|
|
|
+if [ -d "${CONFIG_DIR}" ] && [ "$(ls -A "${CONFIG_DIR}" 2>/dev/null)" ]; then
|
|
|
+ SPRING_CONFIG_LOC="--spring.config.additional-location=file:${CONFIG_DIR}/"
|
|
|
fi
|
|
|
|
|
|
-cd "$(dirname "$0")"
|
|
|
-
|
|
|
-exec java \
|
|
|
- $DEBUG_FLAG \
|
|
|
- -Xms512m \
|
|
|
- -Xmx2g \
|
|
|
- -XX:+UseG1GC \
|
|
|
- -XX:MaxGCPauseMillis=200 \
|
|
|
- -XX:+HeapDumpOnOutOfMemoryError \
|
|
|
- -XX:HeapDumpPath=/tmp/cfc-heapdump.hprof \
|
|
|
- -Dfile.encoding=UTF-8 \
|
|
|
- -Dspring.profiles.active=prod \
|
|
|
- -jar target/cfc-backend-1.0.0.jar
|
|
|
+cd "${APP_DIR}"
|
|
|
+exec java ${DEBUG_FLAG} ${JAVA_OPTS} ${SPRING_CONFIG_LOC} -jar "${JAR_FILE}"
|