Discussion:
Tomcat stop and start using bash script
dhanesh1212121212
2018-06-27 14:51:13 UTC
Permalink
Hi All,

Trying to stop and start tomcat in production using bash script for war
deployment.

If tomcat not stopped properly then how we can kill the correct process and
make sure it's stopped correctly.

Regards,
Dhanesh M.
Leon Rosenberg
2018-06-27 15:02:48 UTC
Permalink
use -force option
bin/shutdown.sh -force

regards
Leon
Post by dhanesh1212121212
Hi All,
Trying to stop and start tomcat in production using bash script for war
deployment.
If tomcat not stopped properly then how we can kill the correct process and
make sure it's stopped correctly.
Regards,
Dhanesh M.
Luis Rodríguez Fernández
2018-06-28 18:13:10 UTC
Permalink
Hello Danesh

Perhaps you could look for any of your tomcat connector ports, ask for the
process that is listening and kill it:

$ ppid=`lsof -i:8080 -Fp | grep p`
$ pid=`echo ${ppid#p*}`
$ kill $pid

Probably you can find something more elegant but the idea could be this
one...

Hope it helps,

Luis
Post by Leon Rosenberg
use -force option
bin/shutdown.sh -force
regards
Leon
Post by dhanesh1212121212
Hi All,
Trying to stop and start tomcat in production using bash script for war
deployment.
If tomcat not stopped properly then how we can kill the correct process
and
Post by dhanesh1212121212
make sure it's stopped correctly.
Regards,
Dhanesh M.
--
"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."

- Samuel Beckett
André Warnier (tomcat)
2018-06-28 20:57:43 UTC
Permalink
Hi.

I have not followe3d this thread since the beginning, but

The standard tomcat distribution comes with a series of shell scripts in the "bin"
directory, which do just that : start or stop tomcat. They are conveniently called
"startup.sh" and "shutdown.sh". You could get inspiration from those.

Since you are talking about bash, it is to be presumed that you are on a Linux system.
If this Linux system has a package management system, it is very likely that there is a
tomcat package available. Such tomcat packages come with startup and stop scripts for
tomcat, which make it easy to start/stop tomcat via a shell command.

Furthermore, look at the on-line documentation. In
http://tomcat.apache.org/tomcat-9.0-doc/config/server.html#Common_Attributes, you will
find the "shutdown" attribute and its explanation. It basically means that if you open a
TCP/IP socket to the given port (which you can do with bash), and send the indicated
string on that connection, tomcat will initiate a shutdown.

And that's in fact what the standard shutdown.sh does, though using a roundabout way : it
starts another java jvm instance which runs another temporary instance of tomcat, which
just does one thing : send this shutdown string to the appropriate (main instance of
tomcat's) shutdown port (and then it shuts itself down).

So it looks like there are a lot of ways to achieve what you want, and you only need to
pick the right one for you.
Post by Luis Rodríguez Fernández
Hello Danesh
Perhaps you could look for any of your tomcat connector ports, ask for the
$ ppid=`lsof -i:8080 -Fp | grep p`
$ pid=`echo ${ppid#p*}`
$ kill $pid
Probably you can find something more elegant but the idea could be this
one...
Hope it helps,
Luis
Post by Leon Rosenberg
use -force option
bin/shutdown.sh -force
regards
Leon
Post by dhanesh1212121212
Hi All,
Trying to stop and start tomcat in production using bash script for war
deployment.
If tomcat not stopped properly then how we can kill the correct process
and
Post by dhanesh1212121212
make sure it's stopped correctly.
Regards,
Dhanesh M.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Jäkel, Guido
2018-06-29 06:28:07 UTC
Permalink
Hi also,

to archive a full graceful shutdown, it's also save to just send a SIGTERM to the JVM running the Tomcat. This will result in invoking exactly the same mechanisms as the official top-level methods described by André without the need to start an extra VM. The PID should be available by the operating systems standard mechanisms as the Application Controll Framework (initd, system), by Java tools like jps or by system tools like ps, pidof, ... . To invoke a forced shutdown, one may send SIGKILL to the JVM process.

The advantage of both is to have a very small footprint and follow the KISS pragma, which may especially important in a "out-of-resources" scenario when the Tomcat high level interfaces (HTTP/AJP/JMX connector) become disfunctional as a side effect.

BTW: If the Application/Tomcat/JVM is "in trouble", one may invoke the JVM thread dump facility by sending a SIGQUIT to the JVM, also. Again, this may be a "last resort" if you can't command the Tomcat/JVM in a other way.


Greetings

Guido
-----Original Message-----
Sent: Thursday, June 28, 2018 10:58 PM
Subject: Re: Tomcat stop and start using bash script
Hi.
I have not followe3d this thread since the beginning, but
The standard tomcat distribution comes with a series of shell scripts in the "bin"
directory, which do just that : start or stop tomcat. They are conveniently called
"startup.sh" and "shutdown.sh". You could get inspiration from those.
Since you are talking about bash, it is to be presumed that you are on a Linux system.
If this Linux system has a package management system, it is very likely that there is a
tomcat package available. Such tomcat packages come with startup and stop scripts for
tomcat, which make it easy to start/stop tomcat via a shell command.
Furthermore, look at the on-line documentation. In
http://tomcat.apache.org/tomcat-9.0-doc/config/server.html#Common_Attributes, you will
find the "shutdown" attribute and its explanation. It basically means that if you open a
TCP/IP socket to the given port (which you can do with bash), and send the indicated
string on that connection, tomcat will initiate a shutdown.
And that's in fact what the standard shutdown.sh does, though using a roundabout way : it
starts another java jvm instance which runs another temporary instance of tomcat, which
just does one thing : send this shutdown string to the appropriate (main instance of
tomcat's) shutdown port (and then it shuts itself down).
So it looks like there are a lot of ways to achieve what you want, and you only need to
pick the right one for you.
B�KKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKCB��[��X��ܚX�KK[XZ[�\�\��][��X��ܚX�P�X�] �\X�K�ܙ�B��܈Y][ۘ[��[X[��K[
Loading...