NSSM - Install service from command line with many arguments
The command you are using now will end up passing all of the items after the path to your program (starting with AppDirectory
) as arguments to your program when it is executed. Obviously that is not the behaviour that you want.
To establish parameters that are meaningful to nssm
you must run a separate nssm set
command for each parameter. In this case you would use this command to create the service and define the path to your program:
nssm install MDHIS_WebClient "%MDHIS2_HOME%/MDHIS_WebClient.cmd"
followed by this series of commands to establish the various parameters:
nssm set MDHIS_WebClient AppDirectory %MDHIS2_HOME%
nssm set MDHIS_WebClient DisplayName MDHIS_WebClient
nssm set MDHIS_WebClient Start SERVICE_AUTO_START
nssm set MDHIS_WebClient DependOnService MSSQLSERVER
nssm set MDHIS_WebClient AppNoConsole 1
nssm set MDHIS_WebClient AppStopMethodConsole 30000
To be safe, I would move the Start
parameter to the end of that series in order to prevent the possibility of nssm
launching the service before the remaining parameters (DependOnService
, AppNoConsole
and AppStopMethodConsole
) have been established.
Martin
Updated on June 04, 2022Comments
-
Martin about 2 years
I am trying to make a batch file that will create my service and struggling with how exactly to list each parameter. I've researched this quite a bit and I can't seem to find the correct syntax. This is what i have right now :
nssm install MDHIS_WebClient "%MDHIS2_HOME%/MDHIS_WebClient.cmd" AppDirectory %MDHIS2_HOME% DisplayName MDHIS_WebClient Start SERVICE_AUTO_START DependOnService MSSQLSERVER AppNoConsole 1 AppStopMethodConsole 30000
This works but the arguments are ignored. Can anyone show me an example of the proper syntax?
-
Kevin Xiong almost 3 yearsMore detailed examples can be found in offical site nssm.cc/usage
-
-
Martin over 5 yearsThe nssm website made it seem like the first command would bring up the GUI which I didn't want since this script will be part of an installer but indeed this works just fine thanks!