1eeee1e292
Four simple .bat files — install / remove / start / stop-service — that manage the 'mbproxy' Windows service against the Mbproxy.exe in their own folder. publish.ps1 / publish.sh copy them into each win-* publish flavour, so a published Windows folder is self-managing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
51 lines
1.4 KiB
Batchfile
51 lines
1.4 KiB
Batchfile
@echo off
|
|
REM ---------------------------------------------------------------------------
|
|
REM Installs Mbproxy as a Windows service named "mbproxy", running the
|
|
REM Mbproxy.exe located in THIS folder. The service reads appsettings.json
|
|
REM from this same folder. Run this script as Administrator.
|
|
REM
|
|
REM For the fuller install (Windows Event Log source, ProgramData config /
|
|
REM log dirs, ACLs) use install\install.ps1 instead.
|
|
REM ---------------------------------------------------------------------------
|
|
setlocal
|
|
set "SVC=mbproxy"
|
|
set "BIN=%~dp0Mbproxy.exe"
|
|
|
|
net session >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo ERROR: this script must be run as Administrator.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
if not exist "%BIN%" (
|
|
echo ERROR: Mbproxy.exe was not found next to this script:
|
|
echo %BIN%
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
sc query %SVC% >nul 2>&1
|
|
if not errorlevel 1 (
|
|
echo Service "%SVC%" already exists. Run remove-service.bat first to reinstall.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo Installing service "%SVC%"
|
|
echo binary: %BIN%
|
|
sc create %SVC% binPath= "%BIN%" start= auto DisplayName= "Mbproxy - Modbus TCP BCD proxy"
|
|
if errorlevel 1 (
|
|
echo ERROR: sc create failed.
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
REM Auto-restart 60 s after each of the first two failures; nothing after that.
|
|
sc failure %SVC% reset= 86400 actions= restart/60000/restart/60000//0 >nul
|
|
|
|
echo.
|
|
echo Installed. Edit appsettings.json in this folder if needed, then run
|
|
echo start-service.bat to start it.
|
|
pause
|