![如果CPU達到100%,如何重新啟動Linux服務?](https://rvso.com/image/726829/%E5%A6%82%E6%9E%9CCPU%E9%81%94%E5%88%B0100%25%EF%BC%8C%E5%A6%82%E4%BD%95%E9%87%8D%E6%96%B0%E5%95%9F%E5%8B%95Linux%E6%9C%8D%E5%8B%99%EF%BC%9F%20.png)
我有帶有 saslauthd 的 postfix 電子郵件伺服器。 saslauthd 守護程式一次又一次地佔用 100% CPU。重新啟動這些服務即可恢復正常的 CPU 使用率。
是否有合適的腳本來確定 CPU 使用率高的服務並自動重新啟動它。
提前致謝。
答案1
您可能會想看一下monit
(官方網站)。
它可以輕鬆配置以監視高 CPU 使用率並在需要時重新啟動進程。
一個簡單的例子(您應該根據您的系統路徑和需求進行配置):
check process saslauth with pidfile /var/run/saslauthd/saslauthd.pid
group mail
start program = "/etc/init.d/saslauthd start"
stop program = "/etc/init.d/saslauthd stop"
if cpu > 90% for 2 cycles then restart
其中(摘自手冊):
CPU([user|system|wait]) is the percent of time the system spend in user or
kernel space and I/O. The user/system/wait modifier is optional, if not
used, the total system cpu usage is tested
還有一個循環is 等於配置選項中的秒數set daemon
。