views:

229

answers:

4

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.

A: 

Use cygwin and netstat to look for the process listening to that port, then kill it by PID would be my approach.

BZ
A: 

Tomcat hotdeploys. Is there any particular reason you cannot just drop in new WAR files?

Thorbjørn Ravn Andersen
This works great in development and for an extremely periodic update - but for as long as I've been around, there have been permgen leaks in Tomcat's hot deploy stuff. I'd love to be proven wrong, though.
Jared
+1  A: 

if youre after the name of the service from within the Vm running the tomcat, you may want to look into the ManagementBean stuff, the following post on sun goes into some details;

Sun forums

Whatever you do is going to be quite hacky, since its all OS dependant! I would definately advise sticking to the Tomcat control & deployment services, you dont even need to kill the Tomcat process, you should be able to reploy your webapp using the tomcat hot deploy facility - either from the control panel, or from the ant libraries provided with tomcat.

simon622
we've had some issues with running out of permgen space when we hot deploy. There are also some known issues with updating DB drivers, which we do on occasion (albeit rarely).The ManagementBean stuff does definitely look hackish, but I'll look into it and see what I can come up with. Thanks.
For as long as I've been around, there have been permgen leaks involved in hot deployment.
Jared
A: 

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.