start.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/bash
  2. set -e
  3. SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
  4. APP_DIR="${SCRIPT_DIR}"
  5. CONFIG_DIR="${APP_DIR}/config"
  6. JAR_FILE="${APP_DIR}/target/cfc-backend-1.0.0.jar"
  7. DEBUG_FLAG=""
  8. ENV="dev"
  9. for arg in "$@"; do
  10. case "$arg" in
  11. --debug) DEBUG_FLAG="-Xdebug -Xrunjdwp:server=y,transport=dt_socket,address=5005,suspend=n" ;;
  12. dev) ENV="dev" ;;
  13. prod) ENV="prod" ;;
  14. local) ENV="local" ;;
  15. esac
  16. done
  17. if [ -z "$FORCE_PROFILE" ] && hostname | grep -qiE "dev|local|test|docker|container"; then
  18. ENV="local"
  19. fi
  20. case "$ENV" in
  21. prod)
  22. DB_HOST="${DB_HOST:-192.168.16.251}"
  23. DB_PORT="${DB_PORT:-3306}"
  24. DB_NAME="${DB_NAME:-zxyj}"
  25. DB_USER="${DB_USER:-zxyj}"
  26. DB_PASS="${DB_PASS:-zxyj@123}"
  27. ;;
  28. *)
  29. DB_HOST="${DB_HOST:-127.0.0.1}"
  30. DB_PORT="${DB_PORT:-3306}"
  31. DB_NAME="${DB_NAME:-zxyj}"
  32. DB_USER="${DB_USER:-root}"
  33. DB_PASS="${DB_PASS:-cfc123}"
  34. ;;
  35. esac
  36. DB_URL="jdbc:mysql://${DB_HOST}:${DB_PORT}/${DB_NAME}?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai&useSSL=false&allowPublicKeyRetrieval=true&createDatabaseIfNotExist=true"
  37. echo "[CFC] ENV=${ENV}, DB=${DB_HOST}:${DB_PORT}/${DB_NAME}"
  38. JAVA_OPTS="
  39. -Xms512m
  40. -Xmx2g
  41. -XX:+UseG1GC
  42. -XX:MaxGCPauseMillis=200
  43. -XX:+HeapDumpOnOutOfMemoryError
  44. -XX:HeapDumpPath=/tmp/cfc-heapdump.hprof
  45. -Dfile.encoding=UTF-8
  46. -Dspring.profiles.active=${ENV}
  47. -Dspring.datasource.url=\"${DB_URL}\"
  48. -Dspring.datasource.username=${DB_USER}
  49. -Dspring.datasource.password=${DB_PASS}
  50. "
  51. SPRING_CONFIG_LOC=""
  52. if [ -d "${CONFIG_DIR}" ] && [ "$(ls -A "${CONFIG_DIR}" 2>/dev/null)" ]; then
  53. SPRING_CONFIG_LOC="--spring.config.additional-location=file:${CONFIG_DIR}/"
  54. fi
  55. cd "${APP_DIR}"
  56. exec java ${DEBUG_FLAG} ${JAVA_OPTS} ${SPRING_CONFIG_LOC} -jar "${JAR_FILE}"