From 8b7153bf6aa12fc632d587e7fe9b09d840f1560a Mon Sep 17 00:00:00 2001 From: larssand Date: Mon, 24 Aug 2026 18:29:39 +0200 Subject: [PATCH] fix start and install bat --- README.md | 33 +++++++++++++++++---------------- README.sv.md | 33 +++++++++++++++++---------------- scripts/verify-install.js | 2 +- src/app.js | 12 ++++++------ windows/README.md | 28 +++++++++++++++------------- windows/install.bat | 3 ++- windows/restart_backend.bat | 24 ++++++++++++++++++++++++ windows/setup.ps1 | 13 +++++++------ 8 files changed, 89 insertions(+), 59 deletions(-) create mode 100644 windows/restart_backend.bat diff --git a/README.md b/README.md index 7541cfb..90b3803 100644 --- a/README.md +++ b/README.md @@ -359,31 +359,32 @@ Use 64-bit Windows 11 and Node.js 22 or 24 LTS. The easiest supported setup is: 1. Clone or extract the complete repository, preferably to `C:\\Live_RC`. 2. Double-click `windows\\install.bat`. -3. Start with `windows\\start_backend.bat` or `npm start`. +3. The installer runs `npm.cmd restart` and leaves the backend running. 4. Open `http://localhost:8081`. -The setup script can install Node.js LTS through `winget`, runs locked dependency installation with `npm ci`, verifies SQLite/Express, and checks the bundled AMMC runtime. Full instructions and troubleshooting: [`windows/README.md`](windows/README.md). +The setup script can install Node.js LTS through `winget`, runs locked dependency installation with `npm.cmd ci`, verifies SQLite/Express, and checks the bundled AMMC runtime. Full instructions and troubleshooting: [`windows/README.md`](windows/README.md). Common commands: ```powershell -npm start -npm stop -npm restart -npm run status -npm run start:fg +npm.cmd start +npm.cmd stop +npm.cmd restart +npm.cmd run status +npm.cmd run start:fg ``` -- `npm start` starts the backend in the background -- `npm stop` stops the process via `data/server.pid` -- `npm restart` restarts the backend -- `npm run status` shows whether the backend is running -- `npm run start:fg` runs in foreground for troubleshooting +- `npm.cmd start` starts the backend in the background +- `npm.cmd stop` stops the process via `data/server.pid` +- `npm.cmd restart` restarts the backend +- `npm.cmd run status` shows whether the backend is running +- `npm.cmd run start:fg` runs in foreground for troubleshooting ### Windows scripts The `windows/` folder includes: -- `windows\\install.bat` installs and verifies Node/npm dependencies +- `windows\\install.bat` installs dependencies and runs `npm.cmd restart` - `windows\\start_ammc.bat` starts AMMC in the background -- `windows\\start_backend.bat` starts `npm start` in the background +- `windows\\start_backend.bat` starts `npm.cmd start` in the background +- `windows\\restart_backend.bat` runs `npm.cmd restart` after updates - `windows\\start_all.bat` starts both AMMC + backend and opens the web page - `windows\\stop_all.bat` stops the managed backend and `ammc-amb.exe` @@ -399,7 +400,7 @@ There are two supported modes. ### A. Managed AMMC from the web UI Important: -- AMMC runs on the same host where `npm start` / `node server.js` runs +- AMMC runs on the same host where the backend was started with `npm.cmd start` - if you only browse from another laptop, no process starts there - the `AMMC executable` field in `Settings` is a path on the backend host, not the client browser machine @@ -436,7 +437,7 @@ sudo ufw allow 8081/tcp ## Auto reload during development - The server watches `index.html`, `src/app.js`, and `src/styles.css` - When files in `Live_RC` change, the client reloads automatically -- If backend code changes, run `npm restart` +- If backend code changes on Windows, run `npm.cmd restart` ## Verify SQLite persistence Latest passings via API: diff --git a/README.sv.md b/README.sv.md index fc74513..28579ef 100644 --- a/README.sv.md +++ b/README.sv.md @@ -348,31 +348,32 @@ Använd 64-bitars Windows 11 och Node.js 22 eller 24 LTS. Enklaste installatione 1. Klona eller packa upp hela repot, helst till `C:\\Live_RC`. 2. Dubbelklicka på `windows\\install.bat`. -3. Starta med `windows\\start_backend.bat` eller `npm start`. +3. Installationen kör `npm.cmd restart` och lämnar backend igång. 4. Öppna `http://localhost:8081`. -Installationsskriptet kan installera Node.js LTS med `winget`, kör en låst dependency-installation med `npm ci`, verifierar SQLite/Express och kontrollerar bundlad AMMC. Komplett guide och felsökning: [`windows/README.md`](windows/README.md). +Installationsskriptet kan installera Node.js LTS med `winget`, kör en låst dependency-installation med `npm.cmd ci`, verifierar SQLite/Express och kontrollerar bundlad AMMC. Komplett guide och felsökning: [`windows/README.md`](windows/README.md). Vanliga kommandon: ```powershell -npm start -npm stop -npm restart -npm run status -npm run start:fg +npm.cmd start +npm.cmd stop +npm.cmd restart +npm.cmd run status +npm.cmd run start:fg ``` -- `npm start` startar `live_event` i bakgrunden -- `npm stop` stoppar processen via `data/server.pid` -- `npm restart` startar om backend -- `npm run status` visar om backend kör -- `npm run start:fg` kör i foreground för felsökning +- `npm.cmd start` startar RaceController i bakgrunden +- `npm.cmd stop` stoppar processen via `data/server.pid` +- `npm.cmd restart` startar om backend +- `npm.cmd run status` visar om backend kör +- `npm.cmd run start:fg` kör i foreground för felsökning ### Windows scripts (bakgrundsstart) Det finns färdiga `.bat`-filer i mappen `windows/`: -- `windows\\install.bat` installerar och verifierar Node/npm-dependencies +- `windows\\install.bat` installerar dependencies och kör `npm.cmd restart` - `windows\\start_ammc.bat` startar AMMC i bakgrunden -- `windows\\start_backend.bat` startar `npm start` i bakgrunden +- `windows\\start_backend.bat` startar `npm.cmd start` i bakgrunden +- `windows\\restart_backend.bat` kör `npm.cmd restart` efter uppdateringar - `windows\\start_all.bat` startar både AMMC + backend och öppnar webbsidan - `windows\\stop_all.bat` stoppar den hanterade backendprocessen och `ammc-amb.exe` @@ -388,7 +389,7 @@ Det finns nu två sätt: ### A. Hanterad AMMC i webbgränssnittet Viktigt: -- AMMC körs på samma host där `npm start` / `node server.js` körs. +- AMMC körs på samma Windows-host där backend startades med `npm.cmd start`. - Om du öppnar sidan från en annan laptop startas ingen AMMC där. - Fältet `AMMC binär` i `Settings` är en sökväg på backend-hosten, inte på klienten som surfar in. @@ -425,7 +426,7 @@ sudo ufw allow 8081/tcp ## Auto reload vid uppdatering - Servern bevakar `index.html`, `src/app.js` och `src/styles.css`. - När du uppdaterar filer i `Live_RC` och sparar, laddar klienten om sidan automatiskt. -- Om backendkoden ändras, kör `npm restart`. +- Om backendkoden ändras i Windows, kör `npm.cmd restart`. ## Verifiera att SQLite sparar Hämta senaste passeringar via API: diff --git a/scripts/verify-install.js b/scripts/verify-install.js index 7bb2d8d..c2358f5 100644 --- a/scripts/verify-install.js +++ b/scripts/verify-install.js @@ -48,4 +48,4 @@ if (process.platform === "win32") { } console.log(`[verify] Express and SQLite: OK (${process.platform}/${process.arch}, Node ${process.version})`); -console.log("[verify] Installation is ready. Start with: npm start"); +console.log(`[verify] Installation is ready. Start with: ${process.platform === "win32" ? "npm.cmd start" : "npm start"}`); diff --git a/src/app.js b/src/app.js index d2c6bc8..5dc1ec0 100644 --- a/src/app.js +++ b/src/app.js @@ -1099,7 +1099,7 @@ const TRANSLATIONS = { "overlay.active_member": "Aktiv förare/bil", "overlay.top_three": "Topp 3", "guide.host_title": "Hur Managed AMMC körs", - "guide.host_1": "1. AMMC körs alltid på samma maskin som `npm start` eller `node server.js` körs på.", + "guide.host_1": "1. AMMC körs alltid på samma maskin som backend körs på (`npm.cmd start` i Windows eller `npm start` i Linux).", "guide.host_2": "2. Om du bara surfar in från en laptop/webbläsare startas ingen process där. Webbläsaren styr bara backend via HTTP.", "guide.host_3": "3. Kör backend på Linux-servern -> Linux-binären används: `AMMC/linux_x86-64/ammc-amb`.", "guide.host_4": "4. Kör backend på Windows-burken -> Windows-binären används: `AMMC/windows64/ammc-amb.exe`.", @@ -1108,9 +1108,9 @@ const TRANSLATIONS = { "guide.host_7": "7. OBS overlay finns nu som publik URL: `/public-overlay/obs` och kan konfigureras från Overlay-menyn.", "guide.host_8": "8. Sätt `PUBLIC_OVERLAY_TOKEN` på servern om du vill kräva `?token=...` för publika overlay-länkar.", "guide.windows_title": "Windows + AMMC + npm", - "guide.windows_1": "1. Använd 64-bitars Windows 11. Dubbelklicka på `windows/install.bat`; skriptet installerar vid behov Node.js LTS med winget och kör `npm ci`.", + "guide.windows_1": "1. Använd 64-bitars Windows 11. Dubbelklicka på `windows/install.bat`; skriptet installerar vid behov Node.js LTS med winget, kör `npm.cmd ci` och startar om backend.", "guide.windows_2": "2. Installationen kräver Node 22 eller 24 LTS och verifierar automatiskt Express, SQLite samt `AMMC/windows64`.", - "guide.windows_3": "3. Starta i bakgrunden med `npm start` eller `windows/start_backend.bat`. Kontrollera med `npm run status` och stoppa med `npm stop`.", + "guide.windows_3": "3. `windows/install.bat` kör `npm.cmd restart` automatiskt. Starta annars med `npm.cmd start` eller `windows/start_backend.bat`, kontrollera med `npm.cmd run status` och starta om med `npm.cmd restart`.", "guide.windows_4": "4. I Inställningar: `Decoder IP / host` = decoderns IP, t.ex. `192.168.1.10`. Managed AMMC körs på Windows-hosten.", "guide.windows_5": "5. Från andra enheter används `http://:8081` och `ws://:9000`. Se `windows/README.md` för brandvägg och felsökning.", "guide.linux_title": "Linux + npm", @@ -1993,7 +1993,7 @@ const TRANSLATIONS = { "overlay.active_member": "Active driver/car", "overlay.top_three": "Top 3", "guide.host_title": "How Managed AMMC Runs", - "guide.host_1": "1. AMMC always runs on the same machine where `npm start` or `node server.js` is running.", + "guide.host_1": "1. AMMC always runs on the backend host (`npm.cmd start` on Windows or `npm start` on Linux).", "guide.host_2": "2. If you only browse from a laptop/browser, no process is started there. The browser only controls the backend over HTTP.", "guide.host_3": "3. Run the backend on Linux -> the Linux binary is used: `AMMC/linux_x86-64/ammc-amb`.", "guide.host_4": "4. Run the backend on Windows -> the Windows binary is used: `AMMC/windows64/ammc-amb.exe`.", @@ -2002,9 +2002,9 @@ const TRANSLATIONS = { "guide.host_7": "7. The OBS overlay is available at `/public-overlay/obs` and can be configured from the Overlay menu.", "guide.host_8": "8. Set `PUBLIC_OVERLAY_TOKEN` on the server if public overlay links should require `?token=...`.", "guide.windows_title": "Windows + AMMC + npm", - "guide.windows_1": "1. Use 64-bit Windows 11. Double-click `windows/install.bat`; it installs Node.js LTS with winget when needed and runs `npm ci`.", + "guide.windows_1": "1. Use 64-bit Windows 11. Double-click `windows/install.bat`; it installs Node.js LTS with winget when needed, runs `npm.cmd ci`, and restarts the backend.", "guide.windows_2": "2. Setup requires Node 22 or 24 LTS and automatically verifies Express, SQLite, and `AMMC/windows64`.", - "guide.windows_3": "3. Start in the background with `npm start` or `windows/start_backend.bat`. Check with `npm run status` and stop with `npm stop`.", + "guide.windows_3": "3. `windows/install.bat` runs `npm.cmd restart` automatically. Otherwise start with `npm.cmd start` or `windows/start_backend.bat`, check with `npm.cmd run status`, and restart with `npm.cmd restart`.", "guide.windows_4": "4. In Settings, `Decoder IP / host` is the decoder address, for example `192.168.1.10`. Managed AMMC runs on the Windows host.", "guide.windows_5": "5. Other devices use `http://:8081` and `ws://:9000`. See `windows/README.md` for firewall and troubleshooting.", "guide.linux_title": "Linux + npm", diff --git a/windows/README.md b/windows/README.md index 6d62ace..23fee05 100644 --- a/windows/README.md +++ b/windows/README.md @@ -17,7 +17,7 @@ Node.js 18 and 20 are not supported by the current native SQLite dependency. 2. Double-click `windows\install.bat`. 3. Approve the Node.js LTS installation if Windows asks for it. 4. Wait until the script reports `Windows setup completed`. -5. Start with `windows\start_backend.bat` or `npm start`. +5. The installer runs `npm.cmd restart`, leaving the backend running in the background. 6. Open `http://localhost:8081`. The installer: @@ -25,11 +25,12 @@ The installer: - checks the Windows architecture - checks Node.js and installs current LTS with `winget` when needed - installs/checks Microsoft Visual C++ 2015-2022 x64 Runtime for bundled AMMC -- runs `npm ci` from `package-lock.json` +- runs `npm.cmd ci` from `package-lock.json` - verifies that Express loads - opens an in-memory SQLite database through `better-sqlite3` - verifies `ammc-amb.exe`, `ammc.dll`, and `MyLapsSDK.dll` - creates `data\` and `logs\` +- runs `npm.cmd restart` so both new installations and updates use the installed code immediately Run from PowerShell instead when you want options: @@ -54,9 +55,9 @@ npm.cmd run verify npm.cmd start ``` -`npm ci` installs exactly the dependency versions in `package-lock.json`. The install fails early with an actionable message if Node.js is unsupported. The post-install verification also fails if the native SQLite module cannot run. +`npm.cmd ci` installs exactly the dependency versions in `package-lock.json`. The install fails early with an actionable message if Node.js is unsupported. The post-install verification also fails if the native SQLite module cannot run. -The project intentionally uses `better-sqlite3` v12.11.x. That release provides a working prebuilt Windows binary for the supported Node.js versions. The package is explicitly listed in `allowScripts` so npm 12 may run its binary installer; do not use `npm ci --ignore-scripts`. +The project intentionally uses `better-sqlite3` v12.11.x. That release provides a working prebuilt Windows binary for the supported Node.js versions. The package is explicitly listed in `allowScripts` so npm 12 may run its binary installer; do not use `npm.cmd ci --ignore-scripts`. Use `npm.cmd` from PowerShell when local execution policy blocks `npm.ps1`. The plain `npm` command works normally from Command Prompt (`cmd.exe`). @@ -70,19 +71,20 @@ npm.cmd stop npm.cmd run start:fg ``` -- `npm start` starts `server.js` in the background. -- `npm run status` reads `data\server.pid` and reports process state. -- `npm restart` restarts the background process. -- `npm stop` stops it. -- `npm run start:fg` runs in the current terminal for troubleshooting. +- `npm.cmd start` starts `server.js` in the background. +- `npm.cmd run status` reads `data\server.pid` and reports process state. +- `npm.cmd restart` restarts the background process. +- `npm.cmd stop` stops it. +- `npm.cmd run start:fg` runs in the current terminal for troubleshooting. - stdout is written to `logs\server.out.log`. - stderr is written to `logs\server.err.log`. - SQLite data is written to `data\rc_timing.sqlite`. ## Windows helper scripts -- `windows\install.bat`: install and verify all runtime dependencies +- `windows\install.bat`: install, verify, and restart the backend - `windows\start_backend.bat`: start the Node backend in the background +- `windows\restart_backend.bat`: restart the Node backend after copied or pulled updates - `windows\start_ammc.bat`: start bundled AMMC manually - `windows\start_all.bat`: start AMMC, backend, and open the browser - `windows\stop_all.bat`: stop the backend and `ammc-amb.exe` @@ -111,14 +113,14 @@ windows\start_ammc.bat The recommended normal operation is to let the backend manage AMMC: -1. Start RaceController with `npm start`. +1. Start RaceController with `npm.cmd start`. 2. Open `Settings`. 3. Enable `Managed AMMC`. 4. Set the decoder IP and WebSocket port `9000`. 5. Save and click `Start AMMC`. 6. Use the server WebSocket URL and connect the decoder. -AMMC always runs on the computer that runs `npm start`. Opening the UI from a laptop does not start AMMC on that laptop. +AMMC always runs on the computer that runs `npm.cmd start`. Opening the UI from a laptop does not start AMMC on that laptop. ## Network access @@ -167,7 +169,7 @@ npm.cmd stop git pull npm.cmd ci npm.cmd run verify -npm.cmd start +npm.cmd restart ``` Keep `data\` when updating. It contains the SQLite database, saved state, PID file, and local AMMC configuration. diff --git a/windows/install.bat b/windows/install.bat index 4ab8aa5..6f400da 100644 --- a/windows/install.bat +++ b/windows/install.bat @@ -4,7 +4,8 @@ setlocal echo JMK RB RaceController - Windows 11 setup echo. -powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0setup.ps1" %* +rem setup.ps1 refreshes PATH after a Node installation and runs npm.cmd restart. +powershell.exe -NoProfile -ExecutionPolicy Bypass -File "%~dp0setup.ps1" -StartServer %* set "EXIT_CODE=%ERRORLEVEL%" echo. diff --git a/windows/restart_backend.bat b/windows/restart_backend.bat new file mode 100644 index 0000000..3b2d8db --- /dev/null +++ b/windows/restart_backend.bat @@ -0,0 +1,24 @@ +@echo off +setlocal + +for %%I in ("%~dp0..") do set "APP_DIR=%%~fI" +where node.exe >nul 2>&1 +if errorlevel 1 ( + echo [ERROR] Node.js was not found. Run windows\install.bat first. + exit /b 1 +) + +pushd "%APP_DIR%" +call npm.cmd restart +set "EXIT_CODE=%ERRORLEVEL%" +popd + +if not "%EXIT_CODE%"=="0" ( + echo [ERROR] Backend restart failed. + exit /b %EXIT_CODE% +) + +echo [OK] Backend restarted in background +echo URL: http://localhost:8081 +echo Logs: %APP_DIR%\logs\server.out.log +endlocal diff --git a/windows/setup.ps1 b/windows/setup.ps1 index 8031f5b..8390f42 100644 --- a/windows/setup.ps1 +++ b/windows/setup.ps1 @@ -128,16 +128,17 @@ if ($OpenFirewall) { } if ($StartServer) { - Write-Step "Starting RaceController" - & $npmCommand start + Write-Step "Restarting RaceController after installation" + & $npmCommand restart if ($LASTEXITCODE -ne 0) { - throw "RaceController did not start (exit code $LASTEXITCODE)." + throw "RaceController did not restart (exit code $LASTEXITCODE)." } } Write-Host "" Write-Host "Windows setup completed." -ForegroundColor Green -Write-Host "Start: npm start" -Write-Host "Status: npm run status" -Write-Host "Stop: npm stop" +Write-Host "Start: npm.cmd start" +Write-Host "Restart: npm.cmd restart" +Write-Host "Status: npm.cmd run status" +Write-Host "Stop: npm.cmd stop" Write-Host "Open: http://localhost:8081"