简体   繁体   English

如何在 Ubuntu 中关闭 Tomcat?

[英]How to SHUTDOWN Tomcat in Ubuntu?

I tried to shutdown tomcat as shown below, but tomcat still seems to be running (http://localhost:8080/)我试图关闭tomcat如下所示,但 tomcat 似乎仍在运行(http://localhost:8080/)

 vandegraff@vandegraff-laptop:~$ /usr/share/tomcat6/bin/shutdown.sh Using CATALINA_BASE: /usr/share/tomcat6 Using CATALINA_HOME: /usr/share/tomcat6 Using CATALINA_TMPDIR: /usr/share/tomcat6/temp Using JRE_HOME: /usr 1 Nov, 2010 11:41:40 PM org.apache.catalina.startup.Catalina stopServer SEVERE: Catalina.stop: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) at java.net.Socket.connect(Socket.java:529) at java.net.Socket.connect(Socket.java:478) at java.net.Socket.<init>(Socket.java:375) at java.net.Socket.<init>(Socket.java:189) at org.apache.catalina.startup.Catalina.stopServer(Catalina.java:422) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.catalina.startup.Bootstrap.stopServer(Bootstrap.java:337) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:415)

Why is that?这是为什么?


Update1 for @hvgotcodes: @hvgotcodes 的更新 1:

Output of ps -ax | Output 的ps -ax | grep java grep java

1597? 1597? Ss 0:00 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile SYSLOG -errfile SYSLOG -pidfile /var/run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap ss 0:00 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile /SYSpidvarLOG -errfile SYSLOG /run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/共享/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager= org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap

1598? 1598? S 0:00 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile SYSLOG -errfile SYSLOG -pidfile /var/run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap S 0:00 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile /SYSLOG -errfile SYSLOG /run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/共享/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager= org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap

1599? 1599? Sl 0:20 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile SYSLOG -errfile SYSLOG -pidfile /var/run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/share/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap sl 0:20 /usr/bin/jsvc -user tomcat6 -cp /usr/share/java/commons-daemon.jar:/usr/share/tomcat6/bin/bootstrap.jar -outfile /SYSLOG -errfile SYSLOG /run/tomcat6.pid -Djava.awt.headless=true -Xmx128M -Djava.endorsed.dirs=/usr/share/tomcat6/endorsed -Dcatalina.base=/var/lib/tomcat6 -Dcatalina.home=/usr/共享/tomcat6 -Djava.io.tmpdir=/tmp/tomcat6-temp -Djava.security.manager -Djava.security.policy=/var/lib/tomcat6/work/catalina.policy -Djava.util.logging.manager= org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file=/var/lib/tomcat6/conf/logging.properties org.apache.catalina.startup.Bootstrap

Should all these 3 processes - 1597, 1598, 1599 - be killed?是否应该杀死所有这 3 个进程 - 1597、1598、1599

Try试试

/etc/init.d/tomcat stop

(maybe you have to write something after tomcat , just press tab one time) (也许你必须在tomcat之后写一些东西,只需按一次 Tab 键)

Edit: And you also need to do it as root.编辑:而且您还需要以 root 身份执行此操作。

Van, in your case where tomcat won't shutdown normally, i would use Van,在您的情况下,tomcat 不会正常关闭,我会使用

ps ax | grep java

to find the java process number.找到java进程号。 If that command returns something, then run如果该命令返回某些内容,则运行

sudo kill -9 pid

where pid is the process number.其中 pid 是进程号。 The -9 option means 'just kill it', and normally you don't need this sort of thing, but since in your situation the process won't stop normally, you need it. -9 选项的意思是“杀死它”,通常你不需要这种东西,但由于在你的情况下进程不会正常停止,你需要它。

The output of the first command should look like第一个命令的输出应该如下所示

38678 s002  U      0:02.62 /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Home/bin/java -Djava.util.logging.config.file=/usr/share/apache-tomcat-6.0.26/conf/logging.properties -Xms2048m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=512m -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8086 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=xxxx -Djava.endorsed.dirs=/usr/share/apache-tomcat-6.0.26/endorsed -classpath /usr/share/apache-tomcat-6.0.26/bin/bootstrap.jar -Dcatalina.base=/usr/share/apache-tomcat-6.0.26 -Dcatalina.home=/usr/share/apache-tomcat-6.0.26 -Djava.io.tmpdir=/usr/share/apache-tomcat-6.0.26/temp org.apache.catalina.startup.Bootstrap start

38678 is the process number. 38678 是进程号。 Be aware that there might be other java processes running that you might not want to kill.请注意,可能还有其他您不想杀死的 Java 进程正在运行。 Also, this output is from a mac, so on ubuntu will look slightly different.此外,此输出来自 mac,因此在 ubuntu 上看起来会略有不同。

Try using this command : (this will stop tomcat servlet this really helps)尝试使用此命令:(这将停止 tomcat servlet 这确实有帮助)

sudo service tomcat7 stop须藤服务 tomcat7 停止

or

sudo tomcat7 restart (if you need a restart) sudo tomcat7 restart (如果需要重启)

To stop apache process try this command要停止 apache 进程试试这个命令

ps aux | ps辅助| grep tomcat | grep tomcat | awk '{print $2}' | awk '{print $2}' | xargs kill -9 xargs kill -9

For a more graceful way, try the following:要获得更优雅的方式,请尝试以下操作:

Caveat: I'm running Debian 7, not Ubuntu, though it is a Debian derivative警告:我运行的是 Debian 7,而不是 Ubuntu,尽管它是 Debian 的衍生版本

If you're running Tomcat as a service, you can get a list of all running services by typing:如果您将 Tomcat 作为服务运行,则可以通过键入以下内容获取所有正在运行的服务的列表:

sudo service --status-all须藤服务 --status-all

I'm running Tomcat 7, which is displayed as tomcat7 in said list.我正在运行 Tomcat 7,它在上述列表中显示为tomcat7 Then, to shut it down just type:然后,要关闭它,只需键入:

sudo service tomcat7 stop须藤服务 tomcat7 停止

如果您手动安装了tomcat ,请从终端运行shutdown.sh(/.../tomcat/bin)以轻松关闭它

I had a similar problem and found the following command to work:我遇到了类似的问题,发现以下命令可以工作:

sudo systemctl stop tomcat须藤 systemctl 停止 tomcat

After running this command you can type the following to verify that it is "disabled":运行此命令后,您可以键入以下内容以验证它是否已“禁用”:

systemctl list-units systemctl 列表单位

systemctl 列表单元的输出

if you are run this command如果你运行这个命令

 debian@debian:~$  /usr/share/tomcat7/bin/shutdown.sh
 then your server will not stop and you will get o/p like that you provided if you use in 
 super user mode then effect will appear o/p will come like this

 debian@debian:~$ sudo /usr/share/tomcat7/bin/shutdown.sh
 [sudo] password for debian: 
 Using CATALINA_BASE:   /var/lib/tomcat
 Using CATALINA_HOME:   /var/lib/tomcat
 Using CATALINA_TMPDIR: /var/lib/tomcat/temp
 Using JRE_HOME:        /usr/lib/jvm/java-1.6.0-openjdk
 Using CLASSPATH:   /var/lib/tomcat/bin/bootstrap.jar:/var/lib/tomcat/bin/tomcat-juli.jar

如果您安装了 tomcat,则可以执行以下操作:

sh path2tomcat/bin/shutdown.sh

When running Tomcat under jsvc, it will not respond to the shutdown signal on the specified shutdown port which is sent from the shutdown.sh script.在jsvc下运行Tomcat时,不会响应shutdown.sh脚本发送的指定关闭端口的关闭信号。 The only way that I'm aware of is to kill the process, however you'll need to kill the ones listed as jsvc, not java.我知道的唯一方法是终止进程,但是您需要终止列为 jsvc 的进程,而不是 java。

To check whether the environment variable for Tomcat is set or not use the following command in the terminal:要检查Tomcat环境变量是否设置,请在终端中使用以下命令:

echo $CATALINA_HOME

To Start Tomcat:启动 Tomcat:

$CATALINA_HOME/bin/startup.sh

To Stop Tomcat:停止 Tomcat:

$CATALINA_HOME/bin/shutdown.sh

To check Tomcat started or stopped: http://localhost:8080/检查 Tomcat 启动或停止: http://localhost:8080/

SCREENSHOTS:截图: 1.终端 2.Tomcat启动 3.Tomcat停止

for tomcat 9, Use following commands对于 tomcat 9,使用以下命令

For stop对于停止

sudo systemctl stop tomcat.service

For Start开始

sudo systemctl start tomcat.service

For reload tomcat java opts用于重新加载 tomcat java 选择

sudo systemctl daemon-reload

None of the suggested solutions worked for me.没有一个建议的解决方案对我有用。

I had run tomcat restart before completing the deployment which messed up my web app.我在完成部署之前运行了tomcat restart ,这弄乱了我的 Web 应用程序。

EC2 ran tomcat automatically and tomcat was stuck trying to connect to a database connection which was not configured properly. EC2 自动运行 tomcat,而 tomcat 在尝试连接到未正确配置的数据库连接时卡住了。

I just needed to remove my customized context in server.xml, restart tomcat and add the context back in.我只需要在 server.xml 中删除我的自定义上下文,重新启动 tomcat 并重新添加上下文。

Caveat: I'm running Ubuntu警告:我正在运行 Ubuntu

sudo service --status-all

you can get a list of all running services by typing this command,您可以通过键入此命令来获取所有正在运行的服务的列表,

If you're running Tomcat as a service it will showes up as ("tomcat"), so run :如果您将 Tomcat 作为服务运行,它将显示为 ("tomcat"),因此请运行:

sudo service tomcat7 stop

(tomcat7 or 8 or depending to the name that you have in the list of running services ) (tomcat7 或 8 或取决于您在正在运行的服务列表中的名称)

else and if you are using apache tomcat you will see ("apache2") showing up with the list of services then run :否则,如果您使用的是 apache tomcat,您将看到 ("apache2") 显示服务列表,然后运行:

sudo service apache2 stop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM