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

What if Tomcat in Linux environment cannot be shut down normally by shutdown.sh

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

The purpose of this article is to share with you what to do if Tomcat in the Linux environment cannot be shut down normally by shutdown.sh. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Analysis of problems

In the Linux environment, when you use the shutdown.sh script to shut down Tomcat, you will often fail to close it normally. Use the ps-ef command to check the processes that still have tomcat.

Check the linux log and source code. The problem lies in WebappClassLoaderBase. This is the parent class of the Context class loader. When the container is closed, its stop method is called, and the stop method calls the clearReferencesThreads method.

Private boolean clearReferencesStopThreads = false;private void clearReferencesThreads () {Thread [] threads = getThreads (); List executorThreadsToStop = new ArrayList (); / / Iterate over the set of threads for (Thread thread: threads) {if (thread! = null) {... Omit other code. / / Don't try and stop the threads unless explicitly / / configured to do so if (! clearReferencesStopThreads) {continue;}. Omit other code.}

If there are threads that are still running, no processing will take place according to the default configuration of the code, so the tomcat process will still exist.

Solution

The idea to solve this problem is to kill the process forcibly through the kill command. This article provides two solutions.

1. Write your own shell script

The idea is to first query the process ID of tomcat, and then kill the process. The specific shell script is as follows:

#! / bin/bash#TOMCAT_BASE is the bin directory path export TOMCAT_BASE=/usr/local/tomcat/7.0/binecho'> deploy start'# of tomcat on the server. Still run the shutdown.sh script to close the tomcatsh $TOMCAT_BASE/shutdown.sh# query tomcat process ID and kill the process pidList=$ (ps aux | grep $TOMCAT_BASE | grep-v grep | awk'{print $2}') for pid in $pidListdokill-9$ pidecho 'kill pid' $piddone# start tomcatsh $TOMCAT_BASE/startup.shecho'> > deploy end'

With the above script, you can restart Tomcat. The risk of this approach is to find out whether the process ID of tomcat is accurate, but you can also kill processes that have not been shut down due to human manipulation of shutdown.sh.

Window reserved by 2.Tomcat

A window for handling this issue is reserved in the catalina.sh of Tomcat, and the following configuration is required:

Create a file in the bin directory with the file name CATALINA_PID

Add the parameter-force in shutdown.sh

Exec "$PRGDIR" / "$EXECUTABLE" stop-force "$@"

Add the following code at the top of the catalina.sh to point the variable $CATALINA_PID to the created CATALINA_PID file, where the process ID is stored when Tomcat starts.

If [- z "$CATALINA_PID"]; thenCATALINA_PID=$PRGDIR/CATALINA_PIDfi Thank you for reading! This is the end of the article on "what to do if the Tomcat in the Linux environment cannot be shut down normally by shutdown.sh". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out 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

Development

Wechat

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

12
Report