The last two days on-line version, always found that the tomcat restarts within one hours of service shutdown, has been excluded is a memory leak problem, on how to eliminate the suspicion of memory leaks, please see my side of the diary of the sister: Production environment-linux-tomcat downtime solution.
In fact, can not be summed up as Tomcat service outage, although the Web Access is not, the Tomcat service is still running normally, but the log appears this prompt:
2015-3-16 16:24:41 Org.apache.coyote.http11.Http11NioProtocol Pause info: Pausing coyote http/1.1 on http-88**2015-3-16 16:24:42 Org.apache.catalina.core.StandardService Stop info: Stopping service catalina2015-3-16 16:24:42 Org.apache.catalina.loader.WebappClassLoader CLEARREFERENCESJDBC
No additional information, has been suspected of a system-induced problem or tomcat process problems, when the development of colleagues in the test found a problem, using SECURECRT to connect the server, with my script restart, Directly close the Securecrt,tomcat access page will not be accessible, my side has been repeatedly tested, found that the problem does appear on the script:
#!/bin/sh#auther: gushao#date: 2014-12-23#aim: tomcat restarttomcat_home=/home/resin/ Tomcattomcat_pid= ' ps -ef | grep java | grep $tomcat _home | grep -v ' grep ' | awk ' {print $2} ' Remove_log () { test -d $tomcat _home/logs/catalina | | mkdir $tomcat _home/logs/catalina mv $ tomcat_home/logs/catalina2* $tomcat _HOME/LOGS/CATALINA        MV $tomcat _home/logs/catalina.2* $tomcat _home/logs/catalina test -f $ tomcat_home/logs/catalina.out && mv $tomcat _home/logs/catalina.out $ Tomcat_home/logs/catalina ' date +%y-%m-%d_%h%m%s '. out | | echo "$tomcat _home/logs/catalina.out is not exist" #test  -F&NBsp; $tomcat _home/tnx/tnx.web.log && mv $tomcat _home/tnx/tnx.web.log $tomcat _home/tnx/tnx.web ' date +%y-%m-%d_%h%m%s '. log | | echo "$tomcat _home/tnx/tnx.web.log is not exist"}case $1 instop) if [ -z $tomcat _pid ];then remove_log echo " tomcat is already a stopped state" exitelse kill -9 $tomcat _pid remove_logfi;; Start) if [ -z $tomcat _pid ];then $tomcat _ home/bin/catalina.sh start tail -f $tomcat _home/logs/catalina.out else kill -9 $tomcat_pid sleep 6 remove_log $tomcat _home/bin/catalina.sh start tail -f $tomcat _home/logs/catalina.outfi;; Restart) if [ -z $tomcat _pid ];then remove_ logelse kill -9 $tomcat _pid sleep 6 remove_logfi$tomcat_home/ bin/catalina.sh start tail -f $tomcat _home/logs/catalina.out ;; *) echo "Your input is wrong";; Esac
In order to facilitate the restart after viewing the log, after the restart is the direct output of the log, and usually I look at the boot log is normal, CTRL + C exit tail, this is no problem, but in retrospect the problem of the several times it is likely that I have not closed tail, until the SECURECRT timeout automatically shut down, or without first exiting the tail log directly off the SECURECRT.
As to why shutting down SECURECRT directly will cause Tomcat to actually pause the Web service and port ?
When you log in to Linux, the system is assigned to a terminal (Session) of the logged-on user. All programs running at this terminal, including the foreground process group and the background process group, usually belong to this Session. When the user exits the Linux login, the system sends a SIGHUP signal to all processes associated with the session, and the foreground process group and background to the terminal output will receive the SIGHUP signal. The default action for this signal is to terminate the process, so the foreground process group and the process that has terminal output in the background will be aborted.
I'm skeptical about this, but that's not the point, but on the script I wrote, here's the modified script:
#!/bin/sh#auther: gushao#date: 2014-12-23#aim: tomcat restarttomcat_home=/home/resin/ Tomcattomcat_pid= ' ps -ef | grep java | grep $tomcat _home | grep -v ' grep ' | awk ' {print $2} ' Remove_log () { test -d $tomcat _home/logs/catalina | | mkdir $tomcat _home/logs/catalina mv $ tomcat_home/logs/catalina2* $tomcat _HOME/LOGS/CATALINA        MV $tomcat _home/logs/catalina.2* $tomcat _home/logs/catalina test -f $ tomcat_home/logs/catalina.out && mv $tomcat _home/logs/catalina.out $ Tomcat_home/logs/catalina ' date +%y-%m-%d_%h%m%s '. out | | echo "$tomcat _home/logs/catalina.out is not exist" #test  -F&NBsp; $tomcat _home/tnx/tnx.web.log && mv $tomcat _home/tnx/tnx.web.log $tomcat _home/tnx/tnx.web ' date +%y-%m-%d_%h%m%s '. log | | echo "$tomcat _home/tnx/tnx.web.log is not exist"}case $1 instop) if [ -z $tomcat _pid ];then remove_log echo " tomcat is already a stopped state" exitelse kill -9 $tomcat _pid remove_logfi;; Start) if [ -z $tomcat _pid ];then $tomcat _ Home/bin/catalina.sh start & tail -f $tomcat _home/logs/catalina.out else kill -9 $tomcat _pid sleep 6 remove_log $tomcat _home/bin/catalina.sh Startfi;; Restart) if [ -z $tomcat _pid ];then remove_ logelse kill -9 $tomcat _pid sleep 6 remove_logfi$tomcat_home/ bin/catalina.sh start &;; *) echo "Your input is wrong";; Esacexit 0
It can be said that the exit caused the murder Ah, need to highlight a few points:
1.shell script after the end plus must add exit, otherwise it is definitely pit ah, not happen to develop encounter, brain want to break also can't think out ah ...
2.shell single function as simple as possible, do not take too much useless function, can be divided into modules, but do not all heap together, or each other to affect, it is dead upturned
3. Do operation, as far as possible, less lazy, the real-time manual operations may be more than written script, but the error when the pit dead, write more automation scripts Yes
Summary, this is the author of a small summary of the pit, hoping to meet similar situations of friends some inspiration, sometimes a lot of good experience are many people have stepped on the pit after summing up, or to hold an open-minded attitude to learn more, cultivate good internal strength Ah, the author this is to retreat cultivation also ~ ~ ~
This article is from the "Ops Road" blog, please be sure to keep this source http://vekergu.blog.51cto.com/9966832/1621189
Production environment-linux-tomcat down-oolong events