run.bat 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. @echo off
  2. rem ============================================================================
  3. rem Guanlan run.bat - start / stop / restart / status
  4. rem
  5. rem ASCII ONLY ON PURPOSE (see docs 11.3): Chinese text inside a .bat is
  6. rem codepage dependent, and cmd.exe has been observed executing parts of it.
  7. rem
  8. rem Usage:
  9. rem run.bat start start all services (same as: python guanlan.py serve)
  10. rem run.bat stop stop all services
  11. rem run.bat restart stop then start
  12. rem run.bat status show service status (port / pid / alive)
  13. rem run.bat status --json machine readable status
  14. rem run.bat help this text
  15. rem
  16. rem Any extra arguments are passed through to guanlan.py, e.g.
  17. rem run.bat start --only algorithm,web
  18. rem run.bat status
  19. rem ============================================================================
  20. chcp 65001 >nul
  21. set PYTHONUTF8=1
  22. cd /d "%~dp0"
  23. set "PY=%~dp0.venv\Scripts\python.exe"
  24. if not exist "%PY%" (
  25. echo [X] Python runtime not found: %PY%
  26. echo Run install.bat first, or set up .venv in this folder.
  27. pause
  28. exit /b 2
  29. )
  30. set "SUB=%~1"
  31. if "%SUB%"=="start" goto do_start
  32. if "%SUB%"=="stop" goto do_stop
  33. if "%SUB%"=="restart" goto do_restart
  34. if "%SUB%"=="status" goto do_status
  35. if "%SUB%"=="help" goto do_help
  36. if "%SUB%"=="" goto do_help
  37. goto do_other
  38. :do_start
  39. shift
  40. "%PY%" guanlan.py serve %1 %2 %3 %4 %5 %6 %7 %8 %9
  41. goto done
  42. :do_stop
  43. "%PY%" guanlan.py stop
  44. goto done
  45. :do_restart
  46. "%PY%" guanlan.py stop
  47. "%PY%" guanlan.py serve
  48. goto done
  49. :do_status
  50. shift
  51. "%PY%" guanlan.py status %1 %2 %3 %4 %5
  52. goto done
  53. :do_other
  54. "%PY%" guanlan.py %*
  55. goto done
  56. :do_help
  57. echo Usage: run.bat ^<start^|stop^|restart^|status^|help^> [options]
  58. echo start start all services stop stop all services
  59. echo restart stop then start status service status
  60. echo help this text
  61. goto done
  62. :done
  63. pause