Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to check whether the status of Tomcat is UP or DOWN

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces how to detect the status of Tomcat is UP or DOWN, the content is very detailed, interested friends can refer to, hope to be helpful to you.

As an engineer, there are times when deployed Web applications do not respond or have unequal status.

When we check whether a process exists, we don't directly check the corresponding Web application. We usually check whether the corresponding Java process of Tomcat exists. If the application does not respond, observe the thread stack separately.

So here's a question: how do we look at the status of Tomcat when the Tomcat process is around?

After all, as an Java application, processes are created as soon as they are started. This can not be used as the real basis for Tomcat's work. Is there any way to judge the current working status of Tomcat at this time?

Generally, the same problem will be encountered when testing the heartbeat state of containers in the cluster.

In this case, if the Tomcat deploys the ROOT application, you can confirm the status of the Tomcat by visiting its specified page to determine whether the request is reachable.

Another way is to confirm the status of the Tomcat by connecting to its MBeanServer. Generally speaking, if Tomcat goes down, MBeanServer will also fail to connect.

In the previous article, we introduced how JMX connects to MBeanServer provided by Tomcat (do you know anything about the application of JMX in Tomcat?) and can perform a series of container-related operations, even seemingly "dangerous" operations such as starting and stopping Connector.

Of course, to connect to Tomcat MBeanServer through JMX URL, you need to configure the parameter to enable it in the startup script. In addition, you can also connect to each JVM process in a way similar to JConsole, which is obtained after attach to VirtualMachine. In this way, we will write an article later and talk about it alone.

In the official FQA, a way to detect status is also mentioned.

Friends who are familiar with Tomcat configuration know that port conflicts often occur when multiple Tomcat are deployed on a single machine, because multiple ports are configured in server.xml for instance use. In addition to the port that Connector listens on, there is also a port used by the Server component, which defaults to 8005. Among multiple instances, in addition to the Connector port, this SHUTDOWN port also conflicts.

The way to detect Tomcat status here is by connecting to this "port".

When it comes to ports, your first impression must be Socket, which is exactly connected to the ServerSocket corresponding to this port. If you can connect normally, it means that Tomcat is running. If you can't connect to Socket, naturally Tomcat is not available.

What else can the port do besides getting the status? You can also stop the Tomcat process. After all, this port is called a SHUTDOWN port.

It is also relatively easy to implement. Next to the SHUTDOWN port of Tomcat, there is also an attribute, which is used as a token to identify the command to turn off Tomcat. When Server receives a command with this token, it exits the instance.

For a complete implementation, according to the specified Tomcat installation directory, parse the configuration file, obtain the SHUTDOWN port, and the corresponding token, connect the corresponding ServerSocket, get the status, and execute the command.

On how to detect the status of Tomcat is UP or DOWN to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report