start.bat 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. @echo off
  2. rem ============================================================================
  3. rem Guanlan start.bat
  4. rem
  5. rem ASCII ONLY ON PURPOSE. Chinese text inside a .bat is codepage-dependent
  6. rem (console cp936 / cp65001 / system locale), and cmd.exe has been seen to
  7. rem mis-parse such lines and then try to EXECUTE parts of them
  8. rem ("'...' is not recognized as an internal or external command").
  9. rem So every .bat in this package is pure ASCII; all Chinese guidance lives in
  10. rem README (see "README" text file at the install root) and docs\.
  11. rem The rule is enforced by src\entry_refs.py (check.bat reports it) and by the
  12. rem packer: a .bat with non-ASCII bytes never ships.
  13. rem
  14. rem Default (double-click) : no-window start via pythonw.exe + the launcher.
  15. rem A .bat is itself a console program, so Windows opens a window for a
  16. rem moment; this script exits at once and the window closes by itself.
  17. rem A .bat cannot avoid that flash. For a truly windowless start use the
  18. rem shortcut created by install.bat / install.ps1:
  19. rem [install dir]\start_guanlan.lnk (ASCII name: console / CI / scripts)
  20. rem [install dir] and Desktop: a .lnk with the Chinese product name
  21. rem Both point straight at .venv\Scripts\pythonw.exe, so neither cmd.exe nor
  22. rem Windows Script Host is involved.
  23. rem
  24. rem start.bat console : foreground mode (old behaviour). Keeps this window
  25. rem open and prints live logs; closing it stops serve.
  26. rem start.bat help : this text.
  27. rem
  28. rem Logs (docs section 11.2): logs\serve.log and logs\start_hidden.log.
  29. rem ============================================================================
  30. chcp 65001 >nul
  31. set PYTHONUTF8=1
  32. cd /d "%~dp0"
  33. if /i "%~1"=="help" goto help
  34. if /i "%~1"=="console" goto console
  35. if /i "%~1"=="-c" goto console
  36. if not exist ".venv\Scripts\pythonw.exe" (
  37. echo [X] Not installed yet: .venv\Scripts\pythonw.exe not found
  38. echo Run install.bat first.
  39. pause
  40. exit /b 2
  41. )
  42. if not exist "scripts\guanlan_start_hidden.py" (
  43. echo [X] Missing launcher: scripts\guanlan_start_hidden.py
  44. echo The package is incomplete - re-extract it. check.bat reports this too.
  45. pause
  46. exit /b 3
  47. )
  48. rem No-window start: pythonw.exe has no console subsystem, so no window appears
  49. rem while the services run. /min is a belt-and-braces flag; the launcher exits
  50. rem as soon as serve is up.
  51. start "" /min ".venv\Scripts\pythonw.exe" "scripts\guanlan_start_hidden.py"
  52. exit /b 0
  53. :console
  54. if not exist ".venv\Scripts\python.exe" (
  55. echo [X] Not installed yet: .venv\Scripts\python.exe not found
  56. echo Run install.bat first. If install printed errors, send that screen back
  57. echo instead of continuing - the server cannot start without .venv.
  58. pause
  59. exit /b 2
  60. )
  61. echo [i] Foreground mode - this window stays open and shows live logs.
  62. echo Close it to stop the server; for no-window start run start.bat with no argument.
  63. echo For a truly windowless start use the shortcut start_guanlan.lnk.
  64. echo.
  65. ".venv\Scripts\python.exe" guanlan.py serve
  66. if errorlevel 1 (
  67. rem serve exits 1 in two different cases: the gateway never came up, or the gateway is
  68. rem up with at least one degraded module, e.g. Ollama not running. Probe healthz to tell
  69. rem them apart, otherwise a working server gets reported as "did not start".
  70. ".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
  71. if errorlevel 1 (
  72. echo.
  73. echo [X] Gateway did not come up ^(reason above^). Not opening the browser -
  74. echo a "site cannot be reached" page would look like a network problem.
  75. echo See logs\gateway.log
  76. pause
  77. exit /b 1
  78. )
  79. echo.
  80. echo [!] Gateway is up, but at least one module is degraded ^(the [DOWN] lines above^).
  81. echo Usual cause: local Ollama is not running or has no models pulled, which only
  82. echo disables the Q^&A / local-review pages. Every other page works.
  83. echo Details: logs\ for the degraded module.
  84. )
  85. start "" http://127.0.0.1:28084/
  86. echo.
  87. echo [i] Ops console - stop/start services, rebuild, clear products:
  88. echo http://127.0.0.1:28084/ops
  89. echo It stays available while component services are stopped (only the gateway must be up);
  90. echo buttons follow real state and the backend refuses impossible actions (HTTP 409).
  91. exit /b 0
  92. :help
  93. echo Usage:
  94. echo start.bat no-window start (default): pythonw + browser. This cmd window
  95. echo blinks for a fraction of a second, then closes itself.
  96. echo start_guanlan.lnk zero window at all (created by install; target = pythonw.exe)
  97. echo start.bat console foreground start with live logs (troubleshooting)
  98. echo stop.bat stop everything
  99. echo check.bat self-check
  100. echo Logs: logs\serve.log (no-window mode), logs\start_hidden.log (launcher trace)
  101. echo Docs: README text file at the install root; docs\ folder (design, runbook, data placement)
  102. exit /b 0