系统是两个tomcat 做的负载均衡,最近经常由于JMagick 处理大量图片导致内存溢出,tomcat直接挂掉
目前还没有找到比较合适的图片处理方法,情急之下写了个脚本监控tomcat 如果宕掉立刻重启:
该脚本放到crontab 里 一分钟执行一次
*/1 * * * * root /home/autoStarttomcat.sh
#!/bin/sh
tomcat1=`ps -ef |grep apache-tomcat-6.0.20 | grep -v grep |wc -l`
tomcat2=`ps -ef |grep apache-tomcat-second-6.0.20 | grep -v grep |wc -l`
rq=`date +%Y-%m`autoStarttomcatLog=/home/autoStarttomcat.log
managerPath=/home/manager
if [ $tomcat1 -eq 1 ]
then
cd $managerPath
./tomcat1.sh restart
echo "tomcat1 has restart at $frq $minTime" >> $autoStarttomcatLog
else
echo "tomcat1 is ok $frq $minTime" >> $autoStarttomcatLog
fi
if [ $tomcat2 -eq 1 ]
then
cd $managerPath
./tomcat2.sh restart
echo "tomcat2 has restart at $frq $minTime" >> $autoStarttomcatLog
else
echo "tomcat2 is ok $frq $minTime" >> $autoStarttomcatLog
fi