Skip to content
Advertisement

shell script to kill tomcat service if it is not stopped by stop command after certain amount of time?

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?

Advertisement

Answer

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

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement