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