install-service.bat 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. @echo off
  2. REM Register Bambuddy as a Windows service via NSSM.
  3. REM
  4. REM Called from Inno Setup's [Run] section. Arguments:
  5. REM %1 = install dir (e.g. C:\Program Files\Bambuddy)
  6. REM %2 = data dir (e.g. C:\ProgramData\Bambuddy)
  7. REM %3 = port (e.g. 8000)
  8. REM
  9. REM If the service already exists (re-install / upgrade), remove and
  10. REM re-create it so config changes from this build apply.
  11. setlocal
  12. set "INSTALL_DIR=%~1"
  13. set "DATA_ROOT=%~2"
  14. set "PORT=%~3"
  15. set "NSSM=%INSTALL_DIR%\bin\nssm.exe"
  16. set "PYTHON=%INSTALL_DIR%\python\python.exe"
  17. set "APP_DIR=%INSTALL_DIR%\app"
  18. set "BIN_DIR=%INSTALL_DIR%\bin"
  19. set "DATA_DIR=%DATA_ROOT%\data"
  20. set "LOG_DIR=%DATA_ROOT%\logs"
  21. REM Stop and remove any previous registration. Errors are non-fatal —
  22. REM "service not found" returns non-zero and we want to proceed.
  23. "%NSSM%" stop Bambuddy 2>nul
  24. "%NSSM%" remove Bambuddy confirm 2>nul
  25. REM Register the service. NSSM wraps uvicorn so Windows treats it as a
  26. REM proper service (autostart, recovery, supervised restart).
  27. "%NSSM%" install Bambuddy "%PYTHON%" "-m uvicorn backend.app.main:app --host 0.0.0.0 --port %PORT%"
  28. if errorlevel 1 (
  29. echo [install-service] nssm install failed
  30. exit /b 1
  31. )
  32. REM Service configuration
  33. "%NSSM%" set Bambuddy AppDirectory "%APP_DIR%"
  34. "%NSSM%" set Bambuddy DisplayName "Bambuddy"
  35. "%NSSM%" set Bambuddy Description "Bambuddy — local-first Bambu Lab printer manager"
  36. "%NSSM%" set Bambuddy Start SERVICE_AUTO_START
  37. REM Environment: point DATA_DIR + LOG_DIR at ProgramData, prepend our
  38. REM bin/ to PATH so ffmpeg/ffprobe are found by the shutil.which() lookup
  39. REM in backend/app/services/layer_timelapse.py.
  40. "%NSSM%" set Bambuddy AppEnvironmentExtra ^
  41. "DATA_DIR=%DATA_DIR%" ^
  42. "LOG_DIR=%LOG_DIR%" ^
  43. "PORT=%PORT%" ^
  44. "PATH=%BIN_DIR%;%PATH%"
  45. REM Stdout / stderr capture. Rotate at 10MB.
  46. "%NSSM%" set Bambuddy AppStdout "%LOG_DIR%\service-stdout.log"
  47. "%NSSM%" set Bambuddy AppStderr "%LOG_DIR%\service-stderr.log"
  48. "%NSSM%" set Bambuddy AppRotateFiles 1
  49. "%NSSM%" set Bambuddy AppRotateOnline 1
  50. "%NSSM%" set Bambuddy AppRotateBytes 10485760
  51. REM Run as LocalSystem (default). Required for binding 322/990/8883 if
  52. REM the user later enables the Virtual Printer feature. Most non-VP
  53. REM workloads would work as a less-privileged account, but service
  54. REM identity changes are disruptive — pick the broader one once.
  55. REM Start the service. If it fails to start, NSSM exits non-zero and
  56. REM Inno Setup will surface this to the user.
  57. "%NSSM%" start Bambuddy
  58. if errorlevel 1 (
  59. echo [install-service] nssm start failed — check %LOG_DIR%\service-stderr.log
  60. exit /b 1
  61. )
  62. echo [install-service] Bambuddy service registered and started on port %PORT%
  63. endlocal
  64. exit /b 0