My server uses tomcat. From time to time, the Tomcat process will suddenly end, and I don't know why. From the log, there is nothing suspicious. It seems like this is suddenly gone, the following logs are printed after Tomcat is restarted. The cause cannot be found, but you need to find a work und. Do not go to the server to restart tomcat after the problem occurs. I plan to use the cron service of the system to automatically start Tomcat. It is very simple to check the Tomcat process once every minute. If not, start it. The script is as follows:
#!/bin/bashexport JRE_HOME=/usr/local/jreif [ `ps -ef | egrep ‘tomcat‘ | egrep -v egrep | wc -l` -gt 0 ]; thenexit 1fiecho `date`" tomcat restart" >> ~/shell/tomcat_restart.log/usr/local/tomcat/bin/startup.sh
Note the following when writing this script:Do not add spaces!Shell programming is not the same as other programming. spaces have special meanings. When the script starts tomcat, it prints a log ~ /Shell/tomcat_restart.log contains a time information to help me find the cause (although I still cannot find the cause ).
Next, configure crontab.
$ Crontab-e
Then edit the content as (If your shell file is saved in ~ /Shell/check_and_start_server.sh ):
*****~ /Shell/check_and_start_server.sh
Save and exit crontab editing, and then start the cron service:
/Etc/init. d/crond start
In this way, the cron Service performs a check every minute. It takes about 10 seconds to start Tomcat, so the worst case is that your server may be interrupted for more than one minute (considering that the server exited at 14:20:01, the cron service has just been checked. The next check is 14:21:00. At this time, Tomcat will be started, which will be completed around 14:21:10 ).
Write a script to automatically start Tomcat