Java Tomcat 7 没有关闭,进程一直在运行?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24903954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:30:41  来源:igfitidea点击:

Tomcat 7 doesn't shut down, process keeps running?

javatomcat

提问by vishal

I started tomcat 7 using,

我开始使用 tomcat 7,

cd /opt/tomcat7/bin    
$/opt/tomcat7/bin ./startup.sh

It shows process running

它显示进程正在运行

root     23206  130  3.4 1323956 572880 pts/2  Sl   07:58   1:05 /usr/bin/java -Djava.util.logging.config.file=/opt/tomcat7/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dspring.profiles.active=mongo1,maxListenersAllowed -DST_SERVER=mongo1 -Djava.endorsed.dirs=/opt/tomcat7/endorsed -classpath /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar -Dcatalina.base=/opt/tomcat7 -Dcatalina.home=/opt/tomcat7 -Djava.io.tmpdir=/opt/tomcat7/temp org.apache.catalina.startup.Bootstrap start

If I shutdown it using

如果我关闭它使用

$/opt/tomcat7/bin ./shutdown.sh

It gives this message

它给出了这个消息

Using CATALINA_BASE:   /opt/tomcat7
Using CATALINA_HOME:   /opt/tomcat7
Using CATALINA_TMPDIR: /opt/tomcat7/temp
Using JRE_HOME:        /usr
Using CLASSPATH:       /opt/tomcat7/bin/bootstrap.jar:/opt/tomcat7/bin/tomcat-juli.jar

but if I check the above process, it still shows it running. Tomcat doesn't shut down. I tried it using root user as well but still no success.

但是如果我检查上述过程,它仍然显示它正在运行。Tomcat 不会关闭。我也使用 root 用户尝试过,但仍然没有成功。

Manully I can kill the process but I want to create deploy script so want to do it using shutdown.sh and startup.sh

Manully 我可以终止进程,但我想创建部署脚本,所以想使用 shutdown.sh 和 startup.sh 来完成

Same happens if I try using

如果我尝试使用,也会发生同样的情况

/opt/tomcat7/bin/catalina.sh start
/opt/tomcat7/bin/catalina.sh stop

Log

日志

Jul 23, 2014 8:26:17 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/i386:/lib:/usr/lib
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 361 ms
Jul 23, 2014 8:26:18 AM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Jul 23, 2014 8:26:18 AM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.53
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/docs
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/manager
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/ROOT
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/examples
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/host-manager
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.HostConfig deployDirectory
INFO: Deploying web application directory /opt/tomcat7/webapps/target
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:18 AM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:18 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 862 ms
Jul 23, 2014 8:26:42 AM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:42 AM org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol stop
INFO: Stopping ProtocolHandler ["ajp-bio-8009"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["http-bio-8081"]
Jul 23, 2014 8:26:42 AM org.apache.coyote.AbstractProtocol destroy
INFO: Destroying ProtocolHandler ["ajp-bio-8009"]

回答by vzamanillo

You can force the shutdown by PID.

您可以通过 PID 强制关机。

Edit

编辑

..tomcat/bin/catalina.sh

and set the

并设置

CATALINA_PID=path

variable to a local path.

变量到本地路径。

CATALINA_PID

(Optional) Path of the file which should contains the pid of the catalina startup java process, when start (fork) is used

CATALINA_PID

(可选)使用 start (fork) 时,应包含 catalina 启动 java 进程的 pid 的文件路径

then you can shutdown Tomcat with -forceflag

然后你可以用-force标志关闭Tomcat

../tomcat/bin/shutdown.sh -force

If the script can not stop Tomcat normally will use a killto stop the process by PID.

如果脚本不能正常停止 Tomcat 会使用 akill来通过 PID 停止进程。

Update:

更新:

According to Joshua Taylor comment, the recommended way to store additional variables for running tomcat is the setenv.* script.

根据 Joshua Taylor 的评论,为运行 tomcat 存储额外变量的推荐方法是 setenv.* 脚本。

Take a look at (3.4) Using the "setenv" script (optional, recommended)section in the tomcat running docs

看一看(3.4) Using the "setenv" script (optional,推荐)in the tomcat running docs 部分

https://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt

https://tomcat.apache.org/tomcat-7.0-doc/RUNNING.txt

回答by Alberto Perez

If you are in windows, and using the portable tomcat, you can use the nircmd program tool, and close by title console window, instead of stopping by PID. When you have downloaded this tool, just do:

如果你在windows下,使用可移植的tomcat,可以使用nircmd程序工具,通过标题控制台窗口关闭,而不是通过PID停止。下载此工具后,只需执行以下操作:

nircmd.exe win close title "Tomcat"

回答by JohannSig

I once had the misfortune of a page running infinite redirect loops due to a faulty authentication mechanism.

由于身份验证机制错误,我曾经遇到过运行无限重定向循环的页面的不幸。

It eventually slowed down the entire server, but also made it impossible for me to shut it down gracefully. In the end I had to employ brute force like vzamanillo describes.

它最终减慢了整个服务器的速度,但也让我无法正常关闭它。最后,我不得不像 vzamanillo 描述的那样使用蛮力。

The point being that something fishy might be running within your server's processes that won't finish properly.

关键是一些可疑的东西可能会在您的服务器进程中运行而无法正常完成。