run.sh 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 " app - 移动端"
  27. echo -e "\n${YELLOW}管理命令:${NC}"
  28. echo " stopAll - 停止所有服务"
  29. echo " rmAll - 删除所有容器"
  30. echo " restart [module] [profile] - 重启指定模块"
  31. exit 1
  32. }
  33. # 网关模块
  34. gateway() {
  35. restart_service "ruoyi-gateway" "$1" "网关服务"
  36. }
  37. # 认证中心
  38. auth() {
  39. restart_service "ruoyi-auth" "$1" "认证中心"
  40. }
  41. # 系统模块
  42. system() {
  43. restart_service "ruoyi-modules-system" "$1" "系统模块"
  44. }
  45. # 定时任务
  46. job() {
  47. restart_service "ruoyi-modules-job" "$1" "定时任务"
  48. }
  49. # 文件服务
  50. file() {
  51. restart_service "ruoyi-modules-file" "$1" "文件服务"
  52. }
  53. # 文件服务
  54. gen() {
  55. restart_service "ruoyi-modules-gen" "$1" "代码生成服务"
  56. }
  57. # 监控中心
  58. monitor() {
  59. restart_service "ruoyi-visual-monitor" "$1" "监控中心"
  60. }
  61. # 考试服务
  62. exam() {
  63. restart_service "airport-exam" "$1" "考试服务"
  64. }
  65. # 管理前端
  66. airportWeb() {
  67. restart_service "airport-web" "$1" "管理前端"
  68. }
  69. # 移动端
  70. app() {
  71. restart_service "airport-app" "$1" "移动端"
  72. }
  73. # 核心重启逻辑
  74. restart_service() {
  75. local service=$1
  76. local profile=${2:-$DEFAULT_PROFILE}
  77. local service_name=$3
  78. echo -e "${YELLOW}>>> 重启 ${service_name} ${service} [环境: ${profile}]...${NC}"
  79. docker-compose stop $service
  80. docker-compose rm -f $service
  81. docker-compose build $service
  82. # 传递环境变量
  83. export PROFILE=$profile
  84. docker-compose up -d $service
  85. echo -e "${GREEN}✓ ${service_name} 启动完成${NC}"
  86. echo -e "环境: ${YELLOW}${profile}${NC} | 容器状态:"
  87. docker-compose ps | grep $service
  88. }
  89. # 停止所有服务
  90. stopAll() {
  91. echo -e "${RED}>>> 停止所有服务...${NC}"
  92. docker-compose stop
  93. }
  94. # 删除所有容器
  95. rmAll() {
  96. echo -e "${RED}>>> 删除所有容器...${NC}"
  97. docker-compose rm -f
  98. }
  99. # 重启指定模块
  100. restart() {
  101. case "$1" in
  102. "gateway") gateway "$2" ;;
  103. "auth") auth "$2" ;;
  104. "system") system "$2" ;;
  105. "job") job "$2" ;;
  106. "file") file "$2" ;;
  107. "gen") gen "$2" ;;
  108. "monitor") monitor "$2" ;;
  109. "exam") exam "$2" ;;
  110. "airportWeb") airportWeb "$2" ;;
  111. "app") app "$2" ;;
  112. *) echo -e "${RED}未知模块: $1${NC}"; usage ;;
  113. esac
  114. }
  115. # 主逻辑
  116. case "$1" in
  117. "gateway") gateway "$2" ;;
  118. "auth") auth "$2" ;;
  119. "system") system "$2" ;;
  120. "job") job "$2" ;;
  121. "file") file "$2" ;;
  122. "gen") gen "$2" ;;
  123. "exam") exam "$2" ;;
  124. "monitor") monitor "$2" ;;
  125. "airportWeb") airportWeb "$2" ;;
  126. "app") app "$2" ;;
  127. "stopAll") stopAll ;;
  128. "rmAll") rmAll ;;
  129. "restart") restart "$2" "$3" ;;
  130. *) usage ;;
  131. esac