Analysis of the problem of the Tomcat process exiting unexpectedly

Source: Internet
Author: User

1) Tomcat is not properly shut down via script (viaport: Shutdown command sent via 8005 Port)

Because normal shutdown (Viaport) will have such a sentence before pause warn log:

    org.apache.catalina.core.StandardServer await    A valid shutdown command was received via the shutdown port. Stopping the Server instance.    
2) Tomcat's shutdownhook is triggered and the destruction logic is executed.

And there are two cases, one is that there is a place in the application code System.exit to exit the JVM, and the other is the signal from the system ( kill -9 except that the Sigkill signal JVM will not have a chance to execute Shutdownhook)

By troubleshooting code, both the application and the middleware team have been able to troubleshoot the System.exit use of this application. That leaves only the signal; After some troubleshooting, it is found that each time tomcat unexpectedly exits coincides with the time at which the SSH session ended.

With this clue, silver when the classmate immediately looked at the other side of the test environment script, simplified as follows:

$ cat test.sh#!/bin/bashcd /data/server/tomcat/bin/./catalina.sh starttail -f /data/server/tomcat/logs/catalina.out

After Tomcat is started, the current shell process does not exit, but instead hangs over the tail process, outputting the log content to the terminal. In this case, the Java process exits if the user directly closes the SSH Terminal's window (with a mouse or shortcut). The ctrl-c Java process does not exit if the test.sh process is terminated before the SSH terminal is closed.

This is an interesting phenomenon, the catalina.sh start way that Tomcat launches the Java process to the init (Process ID 1) Under the parent process, has been test.sh divorced from the current process of the parent-child relationship, and is not related to the SSH process, why close the SSH terminal window will cause the Java process to exit?

If we set the open job control in the test.sh, we won't let the Java process out.

#!/bin/bashset -m  cd /home/admin/tt/tomcat/bin/./catalina.sh starttail -f /home/admin/tt/tomcat/logs/catalina.out

At this point the Java background process inherits the Pgid of the parent process catalina.sh, and catalina.sh no longer uses the TEST.SH process group, but its own PID as the pgid,catalina.sh process after execution exits, the Java process hangs under Init, Java and test The. SH process is completely out of the relationship, and bash no longer sends a signal to it.

Detailed reference: http://hongjiang.info/why-kill-2-cannot-stop-tomcat/, written in very detail.

Analysis of the problem of the Tomcat process exiting unexpectedly

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.