shell script to kill tomcat service if it is not s

2020-05-08 06:31发布

问题:

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?

回答1:

./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

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

And then to stop it:

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

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.



回答2:

You can use: pkill -9 tomcatServiceName or killall -9 tomcatServiceName.