| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #!/bin/bash
- 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=""
- 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
- -Dhttps.protocols=TLSv1.2
- -Djdk.tls.client.protocols=TLSv1.2
- -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 "${APP_DIR}"
- exec java ${DEBUG_FLAG} ${JAVA_OPTS} ${SPRING_CONFIG_LOC} -jar "${JAR_FILE}"
|