shell指令碼在程式更新時重啟程式

2021-08-30 05:14:02 字數 845 閱讀 6870

最近做伺服器端的開發,有乙個問題困擾了我很久。需要寫乙個在伺服器端執行的程式,長期駐留的那種,但是在程式更新的時候必要要具備重啟功能(因為伺服器實在太多,不可能一台一台登陸上去重新啟動的)。

初步的思路是:在乙個檔案中記錄程式中乙個經常改動檔案的最後更新時間,然後指令碼定期檢測檔案的最後更新時間和記錄的時間,如果不一樣則重新啟動程式,基本的指令碼如下:

[code="shell"]#!/bin/sh

time=`date -d now`

#check update

#檔案關鍵檔案最後更新時間

lastmodifytime=`stat /home/pplive/monitor/bin/log4j.properties|grep 'modify'|awk ''`

#記錄的最後更新時間

lastmodifyfile=`cat /home/pplive/monitor/lastmodifytime.txt`

if [ "$lastmodifytime" != "$lastmodifyfile" ]; then

pid=`ps -ef|grep open.mis.monitor.mainentrance|grep -v grep|awk ''`

kill -9 $pid

/home/monitor/monitor.sh &

echo $time" monitor.sh restart">>/home/pplive/tools/check_monitor.log

echo $lastmodifytime>/home/pplive/monitor/lastmodifytime.txt

else

echo 'ok'

fi[/code]

shell指令碼實現程式重啟

最近做的ipc端hls推流不穩定偶爾要死機,而雲伺服器又希望能隨時連上ipc。在ipc端有沒有supervisor這種工具,就需要自己想下怎麼然異常退出的程式重啟起來。經過查閱網路資料,通過shell即可實現。bin sh help 引數範圍檢查 if 1 then help fi 檢查程序例項是否...

shell指令碼重啟tomcat

1.新建shell空指令碼檔案,如 home tr.sh,並設定許可權 chmod 750 home tr.sh 2.設定檔案形式 sed e s m g home tr.sh home tr.sh 3.編輯指令碼 vi home tr.sh tomcat home home apache tomc...

uwsgi重啟shell指令碼

根據參考鏈結,修改了部分內容 定義了變數,修復了一些bug,增加了顏色輸出 bin bash ini www mysite1 uwsgi uwsgi.ini uwsgi virtualenvs venv bin uwsgi psid ps aux grep uwsgi grep v grep wc ...