@echo off chcp 65001 > nul setlocal enabledelayedexpansion :: ================= Service Path Config ================= set PROJECT_HOME=%~dp0 set REDIS_HOME=E:\ServerSpace\Redis-7.2.13-Windows-x64-msys2 set PG_HOME=E:\ServerSpace\pgsql :menu cls echo ============================== echo ZhAgentOS Service Manager echo ============================== echo Start Services: echo 1. Start All Services echo 2. Start Base Services (Redis + PostgreSQL) echo 3. Start Backend Services (Celery + Web) echo 4. Start Frontend Services (Admin + Builder + Chat) echo 5. Start Redis echo 6. Start PostgreSQL echo 7. Start Celery echo 8. Start Web echo 9. Start Admin UI (port 3000) echo 10. Start Builder UI (port 3002) echo 11. Start Chat UI (port 3001) echo. echo Restart Services: echo 20. Restart All Services echo 21. Restart Redis echo 22. Restart PostgreSQL echo 23. Restart Backend Services echo. echo Stop Services: echo 30. Stop All Services echo 31. Stop Redis echo 32. Stop PostgreSQL echo 33. Stop Backend Services echo 34. Stop Frontend Services echo. echo 0. Exit echo ============================== set /p choice=Enter choice: if "%choice%"=="1" call :start_all if "%choice%"=="2" call :start_base if "%choice%"=="3" call :start_backend if "%choice%"=="4" call :start_ui if "%choice%"=="5" call :start_redis if "%choice%"=="6" call :start_pg if "%choice%"=="7" call :start_celery if "%choice%"=="8" call :start_web if "%choice%"=="9" call :start_ui_admin if "%choice%"=="10" call :start_ui_builder if "%choice%"=="11" call :start_ui_chat if "%choice%"=="20" call :restart_all if "%choice%"=="21" call :restart_redis if "%choice%"=="22" call :restart_pg if "%choice%"=="23" call :restart_backend if "%choice%"=="30" call :stop_all if "%choice%"=="31" call :stop_redis if "%choice%"=="32" call :stop_pg if "%choice%"=="33" call :stop_backend if "%choice%"=="34" call :stop_ui if "%choice%"=="0" exit pause goto menu :: ================= Start ================= :start_all call :start_redis call :start_pg call :start_backend call :start_ui goto :eof :start_base call :start_redis call :start_pg goto :eof :start_backend call :start_celery call :start_web goto :eof :start_ui call :start_ui_admin call :start_ui_builder call :start_ui_chat goto :eof :start_redis echo [Redis] Starting... tasklist | find /i "redis-server.exe" > nul if not errorlevel 1 ( echo [Redis] Already running goto :eof ) start "" /min cmd /k "cd /d %REDIS_HOME% && redis-server.exe" timeout /t 2 > nul echo [Redis] Started goto :eof :start_pg echo [PostgreSQL] Starting... pg_isready -h 127.0.0.1 > nul 2>&1 if not errorlevel 1 ( echo [PostgreSQL] Already running goto :eof ) cd /d %PG_HOME%\bin pg_ctl -D %PG_HOME%\data start > nul timeout /t 3 > nul echo [PostgreSQL] Started goto :eof :start_celery echo [Celery] Starting... start "" cmd /k "cd /d %PROJECT_HOME% && call .venv\Scripts\activate && python main.py dev celery" echo [Celery] Started goto :eof :start_web echo [Web] Starting... start "" cmd /k "cd /d %PROJECT_HOME% && call .venv\Scripts\activate && python main.py dev web" echo [Web] Started goto :eof :start_ui_admin echo [Admin UI] Starting... if not exist "%PROJECT_HOME%\ui\admin\node_modules" ( echo [Admin UI] Installing dependencies... start "" cmd /k "cd /d %PROJECT_HOME%\ui\admin && npm install && npm run dev" ) else ( start "" cmd /k "cd /d %PROJECT_HOME%\ui\admin && npm run dev" ) echo [Admin UI] Started (port 3000) goto :eof :start_ui_builder echo [Builder UI] Starting... if not exist "%PROJECT_HOME%\ui\builder\node_modules" ( echo [Builder UI] Installing dependencies... start "" cmd /k "cd /d %PROJECT_HOME%\ui\builder && npm install && npm run dev" ) else ( start "" cmd /k "cd /d %PROJECT_HOME%\ui\builder && npm run dev" ) echo [Builder UI] Started (port 3002) goto :eof :start_ui_chat echo [Chat UI] Starting... if not exist "%PROJECT_HOME%\ui\chat\node_modules" ( echo [Chat UI] Installing dependencies... start "" cmd /k "cd /d %PROJECT_HOME%\ui\chat && npm install && npm run dev" ) else ( start "" cmd /k "cd /d %PROJECT_HOME%\ui\chat && npm run dev" ) echo [Chat UI] Started (port 3001) goto :eof :: ================= Stop ================= :stop_all call :stop_ui call :stop_backend call :stop_pg call :stop_redis goto :eof :stop_redis echo [Redis] Stopping... %REDIS_HOME%\redis-cli shutdown > nul 2>&1 taskkill /f /im redis-server.exe > nul 2>&1 echo [Redis] Stopped goto :eof :stop_pg echo [PostgreSQL] Stopping... cd /d %PG_HOME%\bin pg_ctl -D %PG_HOME%\data stop -m fast > nul echo [PostgreSQL] Stopped goto :eof :stop_backend echo [Backend] Stopping... wmic process where "CommandLine like '%%main.py dev%%'" delete > nul echo [Backend] Stopped goto :eof :stop_ui echo [Frontend] Stopping... taskkill /f /im node.exe > nul echo [Frontend] Stopped goto :eof :: ================= Restart ================= :restart_all echo Restarting all services... call :stop_all timeout /t 3 > nul call :start_all goto :eof :restart_redis call :stop_redis timeout /t 2 > nul call :start_redis goto :eof :restart_pg call :stop_pg timeout /t 3 > nul call :start_pg goto :eof :restart_backend call :stop_backend timeout /t 2 > nul call :start_backend goto :eof