Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shutdown tomcat using web application deployed in it

I've some doubt about tomcat operation which come across my webapp development:

  1. Is there any way to shutdown tomcat itself from the webapp deployed in it?
  2. Is tomcat is running all of its webapps/war inside one JVM or individual JVM or its configurable in some configuration file?
  3. Is it possible to increase the java heap size for particular webapp deployed inside tomcat?

Thanks a lot.

like image 586
SmartSolution Avatar asked Jan 10 '12 07:01

SmartSolution


People also ask

How do I stop a program from running in Tomcat?

Access Tomcat Manager via URL http://ip:8080/manager, you will see a list of running applications. And from this, you can stop any webapp which you want.

What is the use of shutdown port in Tomcat?

Tomcat listens on TCP port 8005 to accept shutdown requests. By connecting to this port and sending the SHUTDOWN command, all applications within Tomcat are halted. The shutdown port is not exposed to the network as it is bound to the loopback interface.

How do I know if WAR is deployed in Tomcat?

The definitive way to determine if a war has finished deploying and the webapp has started is to look in the catalina. out log. A message will be logged. In operational terms, Tomcat will respond to a request made to that webapp in various ways depending on how far along it is.


1 Answers

  1. Open TCP connection from some servlet and send "SHUTDOWN" to Tomcat's shutdown port (default: 8005).
  2. One Tomcat uses one JVM for all applications.
  3. No. Only for the entire JVM.

Here's code for point 1:

Socket clientSocket = new Socket("localhost", 8005);
clientSocket.getOutputStream().write("SHUTDOWN".getBytes());
clientSocket.getOutputStream().close();
clientSocket.close();
like image 64
Grzegorz Grzybek Avatar answered Oct 30 '22 12:10

Grzegorz Grzybek