I am running a tomcat server and am attempting to update code on that server. To do this I need to shut down the server reliably in a Windows environment. To the best of my knowledge, the tomcat shutdown.bat script can have issues with runaway threads, and I need this to work even if I accidentally create a thread that will keep the .bat script from working. The approach I have been attempting is to run a NET STOP command with the service name – however I have multiple tomcats running on one machine in some instances (which means multiple services). Is there a way to get the name of the service that is related to the tomcat that is running my code? Are there any other good solutions to my problem that I should look into?
I have many clients and so would prefer a solution that does not involve installing additional software or hard-coding the name of the service.
Just found that the services are listed in the windows registry with keys like “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\” and the service name. The Image Path contains the full path name of the executable. If I scan through the registry I can match the tomcat home url to the path of the executable and get the service name from the key. Then I can just run a net stop on that.