shell指令碼 自啟動tomcat,nginx

2022-03-20 18:13:08 字數 1045 閱讀 3794

分為2步走

1. 指令碼檔案 : /usr/local

2. crontab -e : */5 * * * * /bin/sh /usr/local/restart.sh

注意事項:可能使用者許可權會影響指令碼的部署

指令碼檔案

echo "指令碼正在啟動..." >> /home/restart.log

tomcat_dir=/usr/local/tomcat

count_tomcat=$(ps -ef|grep tomcat |grep -v tail |grep -v grep | wc -l)

test_flag=$(curl localhost:8080/card-business/demo/returntwo)

echo $count_tomcat >> /home/restart.log

echo $test_flag >> /home/restart.log

if [ $count_tomcat -eq 0 ] || [ $test_flag -ne 2 ] || [ $test_flag -eq ] # 注意,這個條件是根據返回值判斷的,

then

$tomcat_dir/bin/startup.sh

echo "tomcat服務正在啟動..." >> /home/restart.log

ficount_tomcat_1=$(ps -ef|grep tomcat |grep -v tail |grep -v grep | wc -l)

echo $count_tomcat_1 >> /home/restart.log

if [ $count_tomcat_1 -ne 0 ]

then

echo "tomcat服務啟動完成" >> /home/restart.log

fi注:count_tomcat 是做個統計,wc -l 是統計 tomcat 的個數,

-eq :等於

-ne : 不等於,

test_flag :是專案中的測試介面,返回2,根據結果判斷是否啟動tomcat

注:可參考

linux如何編寫自啟動shell指令碼

在很多情況下,程式設計師都做著重複枯燥的工作,雖然這些工作也是必須的,其實這些重複性的工作可以執行指令碼替代 今天筆者就如何編寫自啟動shell指令碼減少程式設計師開啟伺服器後的環境開啟工作 linux版本 centos 6.3 jdk 1.8 tomcat 9.0 抒寫指令碼 bin sh chk...

linux中編寫自啟動shell指令碼

下面以tomcat與redis的開機自啟動為列子 vim start.sh bin sh chkconfig 2345 80 90 description hello.sh echo start redis server usr local redis bin redis server usr lo...

shell開機自啟動

本人測試使用centos7映象。進入目錄,新建指令碼autostart.sh 使用chkconfig 新增開機自啟動指令碼 chkconfig add autostart.sh chkconfig autostart.sh on 以上是乙個最基本的開機啟動指令碼。注意事項較多 3 將指令碼啟動放在 ...