转载

tomcat设置remote JVM debug后stop失败

最近突然出现执行 tomcat/bin/shutdown.sh 停止 tomcat 失败的情况,报错如下:

……
Using CATALINA_PID:    tomcat/bin/CATALINA_PID
ERROR: transport error 202: bind failed: 地址已在使用
ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
JDWP exit error AGENT_ERROR_TRANSPORT_INIT(197): No transports initialized [../../../src/share/back/debugInit.c:690]
FATAL ERROR in native method: JDWP No transports initialized, jvmtiError=AGENT_ERROR_TRANSPORT_INIT(197)
tomcat/bin/catalina.sh: line 365:  4589 已放弃 (core dumped) "jdk1.6.0_45/bin/java" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -server -Xms2048m -Xmx2048m -XX:PermSize=512M -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8697 -Djava.endorsed.dirs="tomcat/endorsed" -classpath xxx org.apache.catalina.startup.Bootstrap stop
The stop command failed. Attempting to signal the process to stop through OS signal.
Tomcat stopped.

看了一下 catalina.sh: line 365 就是 stop 那里执行失败了,然后调用系统的 kill -15 杀死进程

tomcat设置remote JVM debug后stop失败

再仔细看看报错,发现有端口被占用、 dt_socket failed to initialize 等提示,觉得应该是加了 debug 命令的原因,去掉就好了。

# tomcat/bin/catalina.sh
JAVA_OPTS="-server -Xms2048m -Xmx2048m -XX:PermSize=512M -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8697"

但这个感觉也不太好,不能因噎废食呀。搜了下相关情况,发现是 JAVA_OPTS 用的不对,应该用 CATALINA_OPTS,因为 CATALINA_OPTS 变量在 stop 的时候不会被使用(如上图)。

所以最优的做法是使用 CATALINA_OPTS 变量设置 remote debug 相关参数。

# tomcat/bin/catalina.sh
JAVA_OPTS="-server -Xms2048m -Xmx2048m -XX:PermSize=512M"
CATALINA_OPTS="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8697"

参考资料

解决tomcat shutdown时的地址被占用问题, https://my.oschina.net/u/1770666/blog/370620

https://stackoverflow.com/questions/11222365/catalina-opts-vs-java-opts-what-is-the-difference

原文  https://iyaozhen.com/tomcat-remote-jvm-debug-stop-failed.html
正文到此结束
Loading...