@echo off
setlocal

rem
rem NSSM Lightstreamer NT service install script
rem

REM the service display name
set SERVICE_DISPLAY_NAME="Lightstreamer Server"

REM the service description
set SERVICE_DESCRIPTION="Delivers real-time data over the Web"

REM the service start type. Allowed values: SERVICE_AUTO_START, SERVICE_DELAYED_AUTO_START, SERVICE_DEMAND_START, SERVICE_DISABLED
set SERVICE_START_TYPE=SERVICE_AUTO_START

REM the action upon process exit. Allowed values: Restart, Ignore, Exit, Suicide
set APP_EXIT_ACTION=Restart
REM With the "Restart" action, NSSM will restart Lightstreamer Server upon exit;
REM if you prefer to have Windows handle the restarts, for instance to take advantage
REM of more configuration options or in case of any issues with the restarts,
REM it is possible to set the "Suicide" action here;
REM with this option, upon exit of LS Server, the NSSM service will also close.

REM Note: NSSM supports other kinds of settings; for instance, to specify dependencies
REM from other services, like services needed to setup the network interfaces.
REM You can take advantage of these facilities by adding "set" commands below.
REM See the NSSM documentation at https://nssm.cc/ for details.



if "%OS%"=="Windows_NT" goto nt
echo This script only works with NT-based versions of Windows.
goto :end

:nt

echo This script must be run as Administrator.
echo Once the service is installed, do not move nssm*.exe files!
echo ...
echo Please check the output below
echo ...

rem Install the service
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" goto amd64nssm
goto x86nssm

:x86nssm
set NSSM_EXE="%~dp0\nssm.exe"
goto :instserv

:amd64nssm
set NSSM_EXE="%~dp0\nssm_x64.exe"
goto :instserv

:instserv
%NSSM_EXE% install Lightstreamer "%~dp0\LS.bat" silent

%NSSM_EXE% set Lightstreamer DisplayName %SERVICE_DISPLAY_NAME%
%NSSM_EXE% set Lightstreamer Description %SERVICE_DESCRIPTION%
%NSSM_EXE% set Lightstreamer Start %SERVICE_START_TYPE%

%NSSM_EXE% set Lightstreamer AppExit Default %APP_EXIT_ACTION%

if NOT "%SERVICE_START_TYPE%" == "SERVICE_AUTO_START" goto end
net start Lightstreamer

:end
pause
