现场的同事遇到一个Tomcat僵死的问题,隔三差五的服务器就会挂掉,向我寻求解决方案,服务器正常,没有发现问题。可能是应用程序本身的问题导致,先取一个临时的办法,先服务器跑起来,然后慢慢找原因:

1、  编写一个重启tomcatshell脚本,脚本内容如下:restart.sh

vi restart.sh

注意“.”和 /etc/profile 之间有空格(. /etc/profile 注意, ".""/etc/profile" 之间有空格.)

#!/bin/sh

. /etc/profile

pid=`ps aux | grep tomcat | grep -vgrep | grep -v retomcat | awk '{print $2}'`

echo $pid

if [ -n "$pid" ]

then

{

  echo -------shutdown---------

  /opt/wstk/tomcat6/bin/shutdown.sh

  sleep 1

  pid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk'{print $2}'`

  if [ -n "$pid" ]

  then

   {

     sleep 1

     echo -------kill tomcat--------

     kill -9 $pid

   }

  fi

  sleep 1

  echo --------startup.sh----------

  /opt/wstk/tomcat6/bin/startup.sh

 }

else

echo --------startup.sh---------

/opt/wstk/tomcat6/bin/startup.sh

 

fi

2、  给脚本赋予权限

#chmod u+x restart.sh或者chmod 777 restart.sh

 

3、  编写定时任务脚本

#crontab  -e

添加如下脚本内容:

30 04 * * * /home/retwo/restart.sh >>/home/retwo/logs/restart.log 2>&1

4、重启定时任务脚本

1)查看定时任务状态

service crond status

2)停止定时任务  

service crond stop

3)启动定时任务

service crond start

4)或者使用service crond restart命令

这只是临时的解决办法,要从根本解决问,还要认真分析出现问题的原因。找出问题根源,开着水龙头拖地,永远是拖不干净的。