start.bat 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. @echo off
  2. rem ============================================================================
  3. rem 观澜 start.bat
  4. rem 2026-09-16 用户令: 启动观澜系统时"弹出的命令窗口"改为不弹出方式。
  5. rem 2026-09-16 用户令二: **把 VBScript 替换掉** —— 原先无窗口启动靠 start_hidden.vbs
  6. rem (WScript.Shell.Run 窗口样式 0)。现改为直接用 pythonw.exe(无控制台子系统的
  7. rem 解释器) 跑启动器: 不经过 Windows 脚本宿主, WSH 被组策略禁用/未安装的
  8. rem 服务器上照样能用。
  9. rem
  10. rem 默认 (双击本文件) : pythonw.exe 无窗口起服务 + 等就绪 + 自动开浏览器。
  11. rem ★ .bat 本身是控制台程序, 双击时 Windows 必定先开一个窗口; 本脚本会让它
  12. rem 在零点几秒内自己关掉 (脚本内无法消除这个闪窗)。要**完全不闪窗**:
  13. rem 用安装时生成的 `启动观澜.lnk`(目标 = .venv\Scripts\pythonw.exe),
  14. rem 它不经过 cmd.exe, 一个窗口都不会出现。
  15. rem start.bat console : 前台模式 (旧行为) —— 在当前窗口里跑 serve 并实时打印日志,
  16. rem 只在排障时用; 关掉这个窗口等于停掉 serve。
  17. rem start.bat help : 说明。
  18. rem
  19. rem 为什么分开: 各组件服务本来就是 DETACHED_PROCESS 起的 (不弹窗), 唯一会弹的就是
  20. rem "在控制台里前台跑 guanlan.py serve" 这件事本身。排障又确实需要看见实时输出,
  21. rem 所以保留一个显式的 console 档, 而不是把日志彻底藏掉。
  22. rem ============================================================================
  23. chcp 65001 >nul
  24. set PYTHONUTF8=1
  25. cd /d "%~dp0"
  26. if /i "%~1"=="help" goto help
  27. if /i "%~1"=="console" goto console
  28. if /i "%~1"=="-c" goto console
  29. if not exist ".venv\Scripts\pythonw.exe" (
  30. echo [X] Not installed yet: .venv\Scripts\pythonw.exe not found
  31. echo Run install.bat first.
  32. pause
  33. exit /b 2
  34. )
  35. if not exist "scripts\guanlan_start_hidden.py" (
  36. echo [X] Missing launcher: scripts\guanlan_start_hidden.py
  37. echo The package is incomplete - re-extract it ^(check.bat reports this too^).
  38. pause
  39. exit /b 3
  40. )
  41. rem 无窗口启动: pythonw.exe 无控制台子系统, 运行期间不出现任何窗口。
  42. rem (/min 是双保险; 启动器起完 serve 就退出, 不挂窗口。)
  43. start "" /min ".venv\Scripts\pythonw.exe" "scripts\guanlan_start_hidden.py"
  44. exit /b 0
  45. :console
  46. if not exist ".venv\Scripts\python.exe" (
  47. echo [X] Not installed yet: .venv\Scripts\python.exe not found
  48. echo Run install.bat first. If install printed errors, send that screen back
  49. echo instead of continuing - the server cannot start without .venv.
  50. pause
  51. exit /b 2
  52. )
  53. echo [i] Foreground mode - this window stays open and shows live logs.
  54. echo Close it to stop the server; for no-window start just run start.bat with no argument.
  55. echo.
  56. ".venv\Scripts\python.exe" guanlan.py serve
  57. if errorlevel 1 (
  58. rem serve exits 1 in two different cases: the gateway never came up, or the gateway is
  59. rem up with at least one degraded module, e.g. Ollama not running. Probe healthz to tell
  60. rem them apart, otherwise a working server gets reported as "did not start".
  61. ".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
  62. if errorlevel 1 (
  63. echo.
  64. echo [X] Gateway did not come up ^(reason above^). Not opening the browser -
  65. echo a "site cannot be reached" page would look like a network problem.
  66. echo See logs\gateway.log
  67. pause
  68. exit /b 1
  69. )
  70. echo.
  71. echo [!] Gateway is up, but at least one module is degraded ^(the [DOWN] lines above^).
  72. echo Usual cause: local Ollama is not running or has no models pulled, which only
  73. echo disables the Q^&A / local-review pages. Every other page works.
  74. echo Details: logs/ for the degraded module.
  75. )
  76. start "" http://127.0.0.1:28084/
  77. echo.
  78. echo [i] Ops console - stop/start services, rebuild, clear products:
  79. echo http://127.0.0.1:28084/ops
  80. echo It stays available while component services are stopped (only the gateway must be up);
  81. echo buttons follow real state and the backend refuses impossible actions (HTTP 409).
  82. exit /b 0
  83. :help
  84. echo Usage:
  85. echo start.bat no-window start (default): pythonw + browser (this cmd window blinks ~0.2s)
  86. echo <<shortcut>> 启动观澜.lnk - zero window at all (created by install; target = pythonw.exe)
  87. echo start.bat console foreground start with live logs (troubleshooting)
  88. echo stop.bat stop everything
  89. echo check.bat self-check
  90. echo Logs: logs\serve.log (no-window mode), logs\start_hidden.log (launcher trace)
  91. exit /b 0