startTools.bat 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. @echo off
  2. chcp 65001 > nul
  3. setlocal enabledelayedexpansion
  4. :: ================= Service Path Config =================
  5. set PROJECT_HOME=%~dp0
  6. set REDIS_HOME=E:\ServerSpace\Redis-7.2.13-Windows-x64-msys2
  7. set PG_HOME=E:\ServerSpace\pgsql
  8. :menu
  9. cls
  10. echo ==============================
  11. echo ZhAgentOS Service Manager
  12. echo ==============================
  13. echo Start Services:
  14. echo 1. Start All Services
  15. echo 2. Start Base Services (Redis + PostgreSQL)
  16. echo 3. Start Backend Services (Celery + Web)
  17. echo 4. Start Frontend Services (Admin + Builder + Chat)
  18. echo 5. Start Redis
  19. echo 6. Start PostgreSQL
  20. echo 7. Start Celery
  21. echo 8. Start Web
  22. echo 9. Start Admin UI (port 3000)
  23. echo 10. Start Builder UI (port 3002)
  24. echo 11. Start Chat UI (port 3001)
  25. echo.
  26. echo Restart Services:
  27. echo 20. Restart All Services
  28. echo 21. Restart Redis
  29. echo 22. Restart PostgreSQL
  30. echo 23. Restart Backend Services
  31. echo.
  32. echo Stop Services:
  33. echo 30. Stop All Services
  34. echo 31. Stop Redis
  35. echo 32. Stop PostgreSQL
  36. echo 33. Stop Backend Services
  37. echo 34. Stop Frontend Services
  38. echo.
  39. echo 0. Exit
  40. echo ==============================
  41. set /p choice=Enter choice:
  42. if "%choice%"=="1" call :start_all
  43. if "%choice%"=="2" call :start_base
  44. if "%choice%"=="3" call :start_backend
  45. if "%choice%"=="4" call :start_ui
  46. if "%choice%"=="5" call :start_redis
  47. if "%choice%"=="6" call :start_pg
  48. if "%choice%"=="7" call :start_celery
  49. if "%choice%"=="8" call :start_web
  50. if "%choice%"=="9" call :start_ui_admin
  51. if "%choice%"=="10" call :start_ui_builder
  52. if "%choice%"=="11" call :start_ui_chat
  53. if "%choice%"=="20" call :restart_all
  54. if "%choice%"=="21" call :restart_redis
  55. if "%choice%"=="22" call :restart_pg
  56. if "%choice%"=="23" call :restart_backend
  57. if "%choice%"=="30" call :stop_all
  58. if "%choice%"=="31" call :stop_redis
  59. if "%choice%"=="32" call :stop_pg
  60. if "%choice%"=="33" call :stop_backend
  61. if "%choice%"=="34" call :stop_ui
  62. if "%choice%"=="0" exit
  63. pause
  64. goto menu
  65. :: ================= Start =================
  66. :start_all
  67. call :start_redis
  68. call :start_pg
  69. call :start_backend
  70. call :start_ui
  71. goto :eof
  72. :start_base
  73. call :start_redis
  74. call :start_pg
  75. goto :eof
  76. :start_backend
  77. call :start_celery
  78. call :start_web
  79. goto :eof
  80. :start_ui
  81. call :start_ui_admin
  82. call :start_ui_builder
  83. call :start_ui_chat
  84. goto :eof
  85. :start_redis
  86. echo [Redis] Starting...
  87. tasklist | find /i "redis-server.exe" > nul
  88. if not errorlevel 1 (
  89. echo [Redis] Already running
  90. goto :eof
  91. )
  92. start "" /min cmd /k "cd /d %REDIS_HOME% && redis-server.exe"
  93. timeout /t 2 > nul
  94. echo [Redis] Started
  95. goto :eof
  96. :start_pg
  97. echo [PostgreSQL] Starting...
  98. pg_isready -h 127.0.0.1 > nul 2>&1
  99. if not errorlevel 1 (
  100. echo [PostgreSQL] Already running
  101. goto :eof
  102. )
  103. cd /d %PG_HOME%\bin
  104. pg_ctl -D %PG_HOME%\data start > nul
  105. timeout /t 3 > nul
  106. echo [PostgreSQL] Started
  107. goto :eof
  108. :start_celery
  109. echo [Celery] Starting...
  110. start "" cmd /k "cd /d %PROJECT_HOME% && call .venv\Scripts\activate && python main.py dev celery"
  111. echo [Celery] Started
  112. goto :eof
  113. :start_web
  114. echo [Web] Starting...
  115. start "" cmd /k "cd /d %PROJECT_HOME% && call .venv\Scripts\activate && python main.py dev web"
  116. echo [Web] Started
  117. goto :eof
  118. :start_ui_admin
  119. echo [Admin UI] Starting...
  120. if not exist "%PROJECT_HOME%\ui\admin\node_modules" (
  121. echo [Admin UI] Installing dependencies...
  122. start "" cmd /k "cd /d %PROJECT_HOME%\ui\admin && npm install && npm run dev"
  123. ) else (
  124. start "" cmd /k "cd /d %PROJECT_HOME%\ui\admin && npm run dev"
  125. )
  126. echo [Admin UI] Started (port 3000)
  127. goto :eof
  128. :start_ui_builder
  129. echo [Builder UI] Starting...
  130. if not exist "%PROJECT_HOME%\ui\builder\node_modules" (
  131. echo [Builder UI] Installing dependencies...
  132. start "" cmd /k "cd /d %PROJECT_HOME%\ui\builder && npm install && npm run dev"
  133. ) else (
  134. start "" cmd /k "cd /d %PROJECT_HOME%\ui\builder && npm run dev"
  135. )
  136. echo [Builder UI] Started (port 3002)
  137. goto :eof
  138. :start_ui_chat
  139. echo [Chat UI] Starting...
  140. if not exist "%PROJECT_HOME%\ui\chat\node_modules" (
  141. echo [Chat UI] Installing dependencies...
  142. start "" cmd /k "cd /d %PROJECT_HOME%\ui\chat && npm install && npm run dev"
  143. ) else (
  144. start "" cmd /k "cd /d %PROJECT_HOME%\ui\chat && npm run dev"
  145. )
  146. echo [Chat UI] Started (port 3001)
  147. goto :eof
  148. :: ================= Stop =================
  149. :stop_all
  150. call :stop_ui
  151. call :stop_backend
  152. call :stop_pg
  153. call :stop_redis
  154. goto :eof
  155. :stop_redis
  156. echo [Redis] Stopping...
  157. %REDIS_HOME%\redis-cli shutdown > nul 2>&1
  158. taskkill /f /im redis-server.exe > nul 2>&1
  159. echo [Redis] Stopped
  160. goto :eof
  161. :stop_pg
  162. echo [PostgreSQL] Stopping...
  163. cd /d %PG_HOME%\bin
  164. pg_ctl -D %PG_HOME%\data stop -m fast > nul
  165. echo [PostgreSQL] Stopped
  166. goto :eof
  167. :stop_backend
  168. echo [Backend] Stopping...
  169. wmic process where "CommandLine like '%%main.py dev%%'" delete > nul
  170. echo [Backend] Stopped
  171. goto :eof
  172. :stop_ui
  173. echo [Frontend] Stopping...
  174. taskkill /f /im node.exe > nul
  175. echo [Frontend] Stopped
  176. goto :eof
  177. :: ================= Restart =================
  178. :restart_all
  179. echo Restarting all services...
  180. call :stop_all
  181. timeout /t 3 > nul
  182. call :start_all
  183. goto :eof
  184. :restart_redis
  185. call :stop_redis
  186. timeout /t 2 > nul
  187. call :start_redis
  188. goto :eof
  189. :restart_pg
  190. call :stop_pg
  191. timeout /t 3 > nul
  192. call :start_pg
  193. goto :eof
  194. :restart_backend
  195. call :stop_backend
  196. timeout /t 2 > nul
  197. call :start_backend
  198. goto :eof