run.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/sh
  2. # 颜色定义
  3. RED='\033[0;31m'
  4. GREEN='\033[0;32m'
  5. YELLOW='\033[0;33m'
  6. NC='\033[0m' # No Color
  7. # 默认环境配置
  8. DEFAULT_PROFILE="prod"
  9. # 使用说明
  10. usage() {
  11. echo -e "${GREEN}Usage: sh run.sh [module] [profile]"
  12. echo -e "示例:"
  13. echo -e " sh run.sh system # 启动系统模块(默认 ${DEFAULT_PROFILE} 环境)"
  14. echo -e " sh run.sh gateway dev # 启动网关模块(dev 环境)"
  15. echo -e " sh run.sh stopAll # 停止所有服务${NC}"
  16. echo -e "\n${YELLOW}可用模块:${NC}"
  17. echo " gateway - API网关"
  18. echo " auth - 认证中心"
  19. echo " system - 系统模块"
  20. echo " job - 系统模块"
  21. echo " file - 文件服务"
  22. echo " gen - 代码生成服务"
  23. echo " monitor - 监控中心"
  24. echo " exam - 考试服务"
  25. echo " airportWeb - 管理前端"
  26. echo -e "\n${YELLOW}管理命令:${NC}"
  27. echo " stopAll - 停止所有服务"
  28. echo " rmAll - 删除所有容器"
  29. echo " restart [module] [profile] - 重启指定模块"
  30. exit 1
  31. }
  32. # 网关模块
  33. gateway() {
  34. restart_service "ruoyi-gateway" "$1" "网关服务"
  35. }
  36. # 认证中心
  37. auth() {
  38. restart_service "ruoyi-auth" "$1" "认证中心"
  39. }
  40. # 系统模块
  41. system() {
  42. restart_service "ruoyi-modules-system" "$1" "系统模块"
  43. }
  44. # 定时任务
  45. job() {
  46. restart_service "ruoyi-modules-job" "$1" "定时任务"
  47. }
  48. # 文件服务
  49. file() {
  50. restart_service "ruoyi-modules-file" "$1" "文件服务"
  51. }
  52. # 文件服务
  53. gen() {
  54. restart_service "ruoyi-modules-gen" "$1" "代码生成服务"
  55. }
  56. # 监控中心
  57. monitor() {
  58. restart_service "ruoyi-visual-monitor" "$1" "监控中心"
  59. }
  60. # 考试服务
  61. exam() {
  62. restart_service "airport-exam" "$1" "考试服务"
  63. }
  64. # 管理前端
  65. airportWeb() {
  66. restart_service "airport-web" "$1" "管理前端"
  67. }
  68. # 核心重启逻辑
  69. restart_service() {
  70. local service=$1
  71. local profile=${2:-$DEFAULT_PROFILE}
  72. local service_name=$3
  73. echo -e "${YELLOW}>>> 重启 ${service_name} ${service} [环境: ${profile}]...${NC}"
  74. docker-compose stop $service
  75. docker-compose rm -f $service
  76. docker-compose build $service
  77. # 传递环境变量
  78. export PROFILE=$profile
  79. docker-compose up -d $service
  80. echo -e "${GREEN}✓ ${service_name} 启动完成${NC}"
  81. echo -e "环境: ${YELLOW}${profile}${NC} | 容器状态:"
  82. docker-compose ps | grep $service
  83. }
  84. # 停止所有服务
  85. stopAll() {
  86. echo -e "${RED}>>> 停止所有服务...${NC}"
  87. docker-compose stop
  88. }
  89. # 删除所有容器
  90. rmAll() {
  91. echo -e "${RED}>>> 删除所有容器...${NC}"
  92. docker-compose rm -f
  93. }
  94. # 重启指定模块
  95. restart() {
  96. case "$1" in
  97. "gateway") gateway "$2" ;;
  98. "auth") auth "$2" ;;
  99. "system") system "$2" ;;
  100. "job") job "$2" ;;
  101. "file") file "$2" ;;
  102. "gen") gen "$2" ;;
  103. "monitor") monitor "$2" ;;
  104. "exam") exam "$2" ;;
  105. "airportWeb") airportWeb "$2" ;;
  106. *) echo -e "${RED}未知模块: $1${NC}"; usage ;;
  107. esac
  108. }
  109. # 主逻辑
  110. case "$1" in
  111. "gateway") gateway "$2" ;;
  112. "auth") auth "$2" ;;
  113. "system") system "$2" ;;
  114. "job") job "$2" ;;
  115. "file") file "$2" ;;
  116. "gen") gen "$2" ;;
  117. "exam") exam "$2" ;;
  118. "monitor") monitor "$2" ;;
  119. "airportWeb") airportWeb "$2" ;;
  120. "stopAll") stopAll ;;
  121. "rmAll") rmAll ;;
  122. "restart") restart "$2" "$3" ;;
  123. *) usage ;;
  124. esac