如何在發生崩潰時在 Monit 中重新啟動服務之前執行 shell 腳本

如何在發生崩潰時在 Monit 中重新啟動服務之前執行 shell 腳本

我在我的 Linux 機器上使用 Monit 5.3.2。我正在使用 Monit 監控一些服務。我想在運行重新啟動命令之前運行腳本。我已經使用了以下條件。

if does not exist for 2 times within 3 cycles then exec  "/bin/bash -c 'touch /tmp/somefile'" as uid someuser and gid someuser

if does not exist for 10 cycles then restart

不幸的是,只有重新啟動操作被執行。

誰能幫我確定為什麼第一條規則沒有執行?有其他方法可以解決問題嗎?

答案1

這不是一個明確的答案,因為我是目前正在追尋類似問題的新手。

我目前懷疑最後一條規則會覆蓋之前的所有規則。

如果是這樣,請嘗試:

if does not exist for 2 times within 3 cycles 
then exec  "/bin/bash -c 'touch /tmp/somefile'" as uid someuser and gid someuser 
ELSE if does not exist for 10 cycles then restart

相關內容