linux環境定時重啟tomcat
阿新 • • 發佈:2019-01-25
1.寫一個shell指令碼test.sh,重新啟動tomcat
- #!/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.啟動定時服務
[[email protected]]# service crond stop
[[email protected]]# service crond start