start.bat 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. @echo off
  2. rem ============================================================================
  3. rem 观澜 start.bat
  4. rem 2026-09-16 用户令: 启动观澜系统时"弹出的命令窗口"改为不弹出方式。
  5. rem
  6. rem 默认 (双击本文件) : 走**无窗口**启动 —— 交给 start_hidden.vbs (窗口样式 0),
  7. rem 后台起服务、等就绪、自动打开浏览器, 不留任何命令窗口。
  8. rem start.bat console : 前台模式 (旧行为) —— 在当前窗口里跑 serve 并实时打印日志,
  9. rem 只在排障时用; 关掉这个窗口等于停掉 serve。
  10. rem start.bat help : 说明。
  11. rem
  12. rem 为什么分开: 各组件服务本来就是 DETACHED_PROCESS 起的 (不弹窗), 唯一会弹的就是
  13. rem "在控制台里前台跑 guanlan.py serve" 这件事本身。排障又确实需要看见实时输出,
  14. rem 所以保留一个显式的 console 档, 而不是把日志彻底藏掉。
  15. rem ============================================================================
  16. chcp 65001 >nul
  17. set PYTHONUTF8=1
  18. cd /d "%~dp0"
  19. if /i "%~1"=="help" goto help
  20. if /i "%~1"=="console" goto console
  21. if /i "%~1"=="-c" goto console
  22. if not exist ".venv\Scripts\pythonw.exe" (
  23. echo [X] Not installed yet: .venv\Scripts\pythonw.exe not found
  24. echo Run install.bat first.
  25. pause
  26. exit /b 2
  27. )
  28. rem 无窗口启动: wscript 以隐藏窗口方式调用 pythonw.exe 跑启动器, 本窗口立即退出。
  29. wscript.exe //nologo "%~dp0start_hidden.vbs"
  30. exit /b 0
  31. :console
  32. if not exist ".venv\Scripts\python.exe" (
  33. echo [X] Not installed yet: .venv\Scripts\python.exe not found
  34. echo Run install.bat first. If install printed errors, send that screen back
  35. echo instead of continuing - the server cannot start without .venv.
  36. pause
  37. exit /b 2
  38. )
  39. echo [i] Foreground mode - this window stays open and shows live logs.
  40. echo Close it to stop the server; for no-window start just run start.bat with no argument.
  41. echo.
  42. ".venv\Scripts\python.exe" guanlan.py serve
  43. if errorlevel 1 (
  44. rem serve exits 1 in two different cases: the gateway never came up, or the gateway is
  45. rem up with at least one degraded module, e.g. Ollama not running. Probe healthz to tell
  46. rem them apart, otherwise a working server gets reported as "did not start".
  47. ".venv\Scripts\python.exe" -c "import urllib.request,sys; sys.exit(0 if urllib.request.urlopen('http://127.0.0.1:28084/healthz',timeout=6).status==200 else 1)" 2>nul
  48. if errorlevel 1 (
  49. echo.
  50. echo [X] Gateway did not come up ^(reason above^). Not opening the browser -
  51. echo a "site cannot be reached" page would look like a network problem.
  52. echo See logs\gateway.log
  53. pause
  54. exit /b 1
  55. )
  56. echo.
  57. echo [!] Gateway is up, but at least one module is degraded ^(the [DOWN] lines above^).
  58. echo Usual cause: local Ollama is not running or has no models pulled, which only
  59. echo disables the Q^&A / local-review pages. Every other page works.
  60. echo Details: logs/ for the degraded module.
  61. )
  62. start "" http://127.0.0.1:28084/
  63. echo.
  64. echo [i] Ops console - stop/start services, rebuild, clear products:
  65. echo http://127.0.0.1:28084/ops
  66. echo It stays available while component services are stopped (only the gateway must be up);
  67. echo buttons follow real state and the backend refuses impossible actions (HTTP 409).
  68. exit /b 0
  69. :help
  70. echo Usage:
  71. echo start.bat no-window start (default, recommended): hidden services + browser
  72. echo start.bat console foreground start with live logs (troubleshooting)
  73. echo stop.bat stop everything
  74. echo check.bat self-check
  75. echo Logs: logs\serve.log (no-window mode), logs\start_hidden.log (launcher trace)
  76. exit /b 0