On linux systems the stop command in catalina.sh accepts a timeout parameter which forcibly kills tomcat after the supplied number of seconds. The catalina.bat however doesn't seem to have a parameter like that. We are experiencing problems with that our tomcat (running as a windows service) rejects to shutdown when a net stop tomcat is issued. What would be the best way to implement this behaviour on a windows box? I've seen posts about usning the taskkill, but how do I best find out it the process is still running in my script (powershell).


This example assumes both the service name and process name are 'tomcat'.

# Ask service, nicely, to stop
Stop-Service -Name 'tomcat'

# Give service a bit to tidy up.
Start-Sleep -Seconds 30

# If the service isn't stopped yet, end the process forcefully.
if ( (Get-Service -Name 'tomcat').Status -ne 'Stopped' ) {
     Stop-Process -ProcessName 'tomcat' -Force
  • Very nice! A crude puppy like me would just do the stop-process unconditionally... if it is running it gets the ax, if it is not running no harm done. – samsmith Oct 18 '13 at 4:24

Tomcat running as a windows service is controlled by the windows service manager.

When you do a net stop, I guesstimate that the stop command is sent to tomcat, but that it simply needs more time to fully stop. E.g. if you do a net stop and wait long enough, tomcat does eventually shut down. (FWIW, I manage a tomcat on windows server myself, so this is not made up, but is based on real experience, over several years.)

You can use taskkill, this will terminate it right away. You can use the process name. If code is still running in tomcat (writing to a db or such), that might be messy.

The best approach, normally, is to either do net stop and wait for it to really exit, or to ask the app developer to make the shutdown work properly (e.g. for the app to more quickly respond to the stop request so tomcat shuts down promptly).

Failing that, taskkill is ok if you are not worried about what the effect of termination will be.

  • Yeah its correct that it will finally stop, but this takes half an hour or more for some (non obvious) reason, I will implement a sleep for say 30 seconds (which should be enough) and then use taskkill to kill it, if it has not already stopped. This should be safe as far as I know tomcat. Thanks for your input. – Erik B Oct 17 '13 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.