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----- >From: André Warnier (tomcat) [mailto:a...@ice-sa.com] >Sent: Thursday, June 28, 2018 10:58 PM >To: users@tomcat.apache.org >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.