I am trying to run springboot jar as window service and i was able to do using below script. It generates two process prunsrv.exe and java.exe. But on stopping the service it only stops prunsrv.exe(using //SS//Myservice) but i can see java.exe process still running which i have to end using task manager only. How to stop both the process at a time such that i dont have to search processin taskmanager to kill?
set "CLASSPATH=D:\temp-1.0.0.jar"
prunsrv.exe //IS//%SERVICE_NAME% ^
--Description "Myservice" ^
--DisplayName "%DISPLAYNAME%" ^
--Install "%EXECUTABLE%" ^
--LogPath "D:\MyService" ^
--Startup auto ^
--StdOutput auto ^
--StdError auto ^
--Classpath "%CLASSPATH%" ^
--Jvm "%JVM%" ^
--StartImage "%JAVA_HOME%\bin\java.exe" ^
--StartMethod start ^
--StopMethod stop ^
--StartMode exe ^
--StopMode java ^
--StartPath "D:\MyService" ^
--StopPath "D:\MyService" ^
--StartClass com.darth.MyService ^
--StopClass com.darth.MyService ^
--StartParams -jar#%CLASSPATH% ^
--StopParams stop ^
--JvmMs 1024 ^
--JvmMx 6144
Using Procrun in
Javamode almost certainly will not work:(source Procrun documentation).
The easiest way to stop your service is to use the jvm mode, in which case Procrun starts the JVM itself and can call an arbitrary static method with parameters
String[]inside the same JVM to shut it down. E.g. your can modify your application like this:and install it like this:
Alternative solution
An undocumented feature of Procrun (cf. source code) allows to call
System.exit(0)directly without any modification to the application. You just need to set the stop class tojava.lang.System: