run.sh 3.1 KB

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