View Full Version : Killing Tomcat...
kjkoster
06-10-2008, 11:00
Dear All,
What stop scripts do you guys use for Tomcat? On several occasions I found that killing Tomcat is not as easy as it sounds.
It is simple enough to run shutdown.sh, but sometimes my Tomcat instance won't die. What scripts do you guys use to make sure it is gone?
Kees Jan
sadovnikov
06-10-2008, 16:43
from my experience, if tomcat does not stop, there is a problem with one or more applications, which run within this tomcat - like an application quits, but it managed to forget to stop a running threat.
I used the script below to insure it gets stopped (directory and user has to be changed according to your situation).
# stop tomcat
su - tomcat -c "cd /apps/tomcat/bin; ./shutdown.sh >/dev/null 2>&1"
# give application 15 seconds to stop itself
sleep 15
# if application is still running kill it anyway
app_pid=$(ps axuw | grep -v grep | grep "apps/tomcat/bin" | awk '{print $2}')
[[ "x${app_pid}x" == "xx" ]] || kill -9 ${app_pid} >/dev/null 2>&1
Looking forward seeing better solutions here ;-)
kjkoster
07-10-2008, 09:10
Dear Sadovnikov,
That's a useful script to begin with, but I think bluntly waiting for 15 seconds is a bit long. :-) Perhaps I should wait in a loop and only kill it afterwards.
Now to address the actual problem: How can I detect what is causing Tomcat not to quit?
Kees Jan
sadovnikov
07-10-2008, 10:27
The script above was used as a part of deployment automation and had to insure the tomcat is gone without a person watching the process.
Google finds the following about the problem:
Most likely, a non-daemon thread is running. JVM's do not shutdown until there are 0 non-daemon threads. You will need to perform a thread dump [kill -3 pid for Unix or CTRL+Break for Windows] to determine the code which started the thread.
It's about web applications' code, which (for whatever reasons) started one or more threads and fail to shut them down on request from tomcat to quit the application
Kees de Kooter
07-10-2008, 20:06
How can I detect what is causing Tomcat not to quit?
You could try attaching a remote debugger and see which threads are still running after you tried to shut down tomcat.
Here is a description of how to enable remote debugging:
http://www.boplicity.nl/confluence/display/Tomcat/Remote+debugging+tomcat
dr_jerry
18-10-2008, 18:45
on mac ox (tiger), and sol a ris, sorry not win or lin available at home, I've jps which basically shows all java processes running.
jps -v is your friend..
regards,
Jeroen.
Kees de Kooter
18-10-2008, 21:15
Thanks Jeroen, great tip!
I can confirm that jps is available on linux and windows as well.
Some more info from the man pages:
The jps tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. The tool is limited to reporting information on JVMs for which it has the access permissions.
...
The jps command will report the local VM identifier, or lvmid, for each instrumented JVM found on the target system. The lvmid is typically, but not necessarily, the operating system's process identifier for the JVM process.
Kees
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.