本文介绍了Shell脚本杀死tomcat服务,如果它在一定时间后没有被stop命令停止吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想编写shell脚本来启动和停止tomcat服务器.要停止tomcat,我使用以下命令"./bin/shudown.sh"或"./bin/catalina.sh stop".在大多数情况下,这是行不通的,tomcat仍在运行.因此,我想在发出shutdown命令后杀死该tomcat,并等待一段时间(例如5分钟).有人可以帮我怎么做吗?

I would like to write shell script to start and stop tomcat server.For stopping the tomcat I am using this command "./bin/shudown.sh" or "./bin/catalina.sh stop". This is not working most of the times, tomcat is still running.So I would like to kill the tomcat after giving shutdown command and wait for sometime(say 5min). Can anybody help me how to do it?

推荐答案

./bin/catalina.sh应该支持这一点.如果您不带任何选项运行该命令,它将打印出其用法,描述如下:

./bin/catalina.sh should support this. If you run that command without any options, it will print out its usage, which describes:

stop n -force    Stop Catalina, wait up to n seconds and then use kill -KILL if still running

为使此工作有效,您需要将环境变量CATALINA_PID设置为将用于保存Tomcat进程ID的文件名.要启动Tomcat,请使用:

In order to make this work, you need to set the environment variable CATALINA_PID to a file name that will be used to hold the Tomcat process ID. To start Tomcat, use:

export CATALINA_PID=/tmp/catalina.pid
./bin/catalina.sh start

然后停止它:

export CATALINA_PID=/tmp/catalina.pid
./bin/catalina.sh stop 600 -force

这将尝试将其停止,等待5分钟,然后在必要时将其杀死.请注意,默认情况下,它将在前台运行(锁定终端实例).使用结尾的&在后台运行命令.

This will try to stop it, wait for 5 minutes, then kill it if necessary. Note that this will run in the foreground by default (locking up the terminal instance); use a trailing & to run the command in the background.

这篇关于Shell脚本杀死tomcat服务,如果它在一定时间后没有被stop命令停止吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 02:19