startTools.bat 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. @echo off
  2. chcp 936 > nul
  3. setlocal enabledelayedexpansion
  4. :: ================= 路径配置 =================
  5. set REDIS_HOME=E:\ServerSpace\Redis-7.2.13-Windows-x64-msys2
  6. set PG_HOME=E:\ServerSpace\pgsql
  7. set PROJECT_HOME=E:\ProductSpcae\ZhAgentOS1.0
  8. :menu
  9. cls
  10. echo ==============================
  11. echo 服务控制面板
  12. echo ==============================
  13. echo 【启动服务】
  14. echo 1. 启动全部服务
  15. echo 2. 启动基础服务(Redis + PostgreSQL)
  16. echo 3. 启动后端服务(Celery + Web)
  17. echo 4. 启动前端服务(UI)
  18. echo 5. 启动 Redis
  19. echo 6. 启动 PostgreSQL
  20. echo 7. 启动 Celery
  21. echo 8. 启动 Web
  22. echo 9. 启动 UI
  23. echo.
  24. echo 【重启服务】
  25. echo 10. 重启全部服务
  26. echo 11. 重启 Redis
  27. echo 12. 重启 PostgreSQL
  28. echo 13. 重启后端服务
  29. echo.
  30. echo 【停止服务】
  31. echo 20. 停止全部服务
  32. echo 21. 停止 Redis
  33. echo 22. 停止 PostgreSQL
  34. echo 23. 停止后端服务
  35. echo 24. 停止前端服务
  36. echo.
  37. echo 0. 退出
  38. echo ==============================
  39. set /p choice=请输入选项:
  40. if "%choice%"=="1" call :start_all
  41. if "%choice%"=="2" call :start_base
  42. if "%choice%"=="3" call :start_backend
  43. if "%choice%"=="4" call :start_ui
  44. if "%choice%"=="5" call :start_redis
  45. if "%choice%"=="6" call :start_pg
  46. if "%choice%"=="7" call :start_celery
  47. if "%choice%"=="8" call :start_web
  48. if "%choice%"=="9" call :start_ui
  49. if "%choice%"=="10" call :restart_all
  50. if "%choice%"=="11" call :restart_redis
  51. if "%choice%"=="12" call :restart_pg
  52. if "%choice%"=="13" call :restart_backend
  53. if "%choice%"=="20" call :stop_all
  54. if "%choice%"=="21" call :stop_redis
  55. if "%choice%"=="22" call :stop_pg
  56. if "%choice%"=="23" call :stop_backend
  57. if "%choice%"=="24" call :stop_ui
  58. if "%choice%"=="0" exit
  59. pause
  60. goto menu
  61. :: ================= 启动 =================
  62. :start_all
  63. call :start_redis
  64. call :start_pg
  65. call :start_backend
  66. call :start_ui
  67. goto :eof
  68. :start_base
  69. call :start_redis
  70. call :start_pg
  71. goto :eof
  72. :start_backend
  73. call :start_celery
  74. call :start_web
  75. goto :eof
  76. :start_ui
  77. call :start_ui_only
  78. goto :eof
  79. :start_redis
  80. echo [Redis] 正在启动...
  81. tasklist | find /i "redis-server.exe" > nul
  82. if not errorlevel 1 (
  83. echo [Redis] 已在运行
  84. goto :eof
  85. )
  86. start "" /min cmd /k "cd /d %REDIS_HOME% && redis-server.exe"
  87. timeout /t 2 > nul
  88. echo [Redis] 启动完成
  89. goto :eof
  90. :start_pg
  91. echo [PostgreSQL] 正在启动...
  92. pg_isready -h 127.0.0.1 > nul 2>&1
  93. if not errorlevel 1 (
  94. echo [PostgreSQL] 已在运行
  95. goto :eof
  96. )
  97. cd /d %PG_HOME%\bin
  98. pg_ctl -D %PG_HOME%\data start > nul
  99. timeout /t 3 > nul
  100. echo [PostgreSQL] 启动完成
  101. goto :eof
  102. :start_celery
  103. echo [Celery] 正在启动...
  104. start "" cmd /k "cd /d %PROJECT_HOME% && call venv\Scripts\activate && python main.py dev celery"
  105. echo [Celery] 启动完成
  106. goto :eof
  107. :start_web
  108. echo [Web] 正在启动...
  109. start "" cmd /k "cd /d %PROJECT_HOME% && call venv\Scripts\activate && python main.py dev web"
  110. echo [Web] 启动完成
  111. goto :eof
  112. :start_ui_only
  113. echo [前端 UI] 正在启动...
  114. start "" cmd /k "cd /d %PROJECT_HOME%\ui && npm run dev"
  115. start "" cmd /k "cd /d %PROJECT_HOME%\ui && npm run chat"
  116. echo [前端 UI] 启动完成
  117. goto :eof
  118. :: ================= 停止 =================
  119. :stop_all
  120. call :stop_ui
  121. call :stop_backend
  122. call :stop_pg
  123. call :stop_redis
  124. goto :eof
  125. :stop_redis
  126. echo [Redis] 正在停止...
  127. %REDIS_HOME%\redis-cli shutdown > nul 2>&1
  128. taskkill /f /im redis-server.exe > nul 2>&1
  129. echo [Redis] 已停止
  130. goto :eof
  131. :stop_pg
  132. echo [PostgreSQL] 正在停止...
  133. cd /d %PG_HOME%\bin
  134. pg_ctl -D %PG_HOME%\data stop -m fast > nul
  135. echo [PostgreSQL] 已停止
  136. goto :eof
  137. :stop_backend
  138. echo [后端] 正在停止...
  139. wmic process where "CommandLine like '%%main.py dev%%'" delete > nul
  140. echo [后端] 已停止
  141. goto :eof
  142. :stop_ui
  143. echo [前端 UI] 正在停止...
  144. taskkill /f /im node.exe > nul
  145. echo [前端 UI] 已停止
  146. goto :eof
  147. :: ================= 重启 =================
  148. :restart_all
  149. echo 正在重启全部服务...
  150. call :stop_all
  151. timeout /t 3 > nul
  152. call :start_all
  153. goto :eof
  154. :restart_redis
  155. call :stop_redis
  156. timeout /t 2 > nul
  157. call :start_redis
  158. goto :eof
  159. :restart_pg
  160. call :stop_pg
  161. timeout /t 3 > nul
  162. call :start_pg
  163. goto :eof
  164. :restart_backend
  165. call :stop_backend
  166. timeout /t 2 > nul
  167. call :start_backend
  168. goto :eof