苍天有泪 发表于 2015-8-9 12:36:50

Linux下定时重启Tomcat(修改)

  1.写一个shell脚本test.sh,重新启动tomcat
  
  



view plaincopy

[*]   #!/bin/sh
[*]
[*]. /etc/profile
[*]
[*]pid=`ps aux | grep tomcat | grep -v grep | grep -v retomcat | awk '{print $2}'`
[*]echo $pid
[*]
[*]if [ -n "$pid" ]
[*]then
[*]{
[*]   echo ===========shutdown================
[*]   /opt/tomcat/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/tomcat/bin/startup.sh
[*] }
[*]else
[*]echo ===========startup.sh==============
[*]/opt/tomcat/bin/startup.sh
[*]
[*]fi
  
  
  2.把test.sh文件放到root目录下
  3.提高权限
  
  chmod a+x test.sh
  4.在控制台上输入以下命令
crontab -e
5.按i键编辑这个文本文件,输入以下内容,每天凌晨4:30重启tomcat
30 04 * * * /root/test.sh

  
  按esc键退出编辑,输入wq回车保存
  6.启动定时服务
  # service crond stop
  # service crond start
  
  
  查看日志
  /var/log/cron
  
  参考http://blog.iyunv.com/xiyuan1999/article/details/8160998
页: [1]
查看完整版本: Linux下定时重启Tomcat(修改)