写了个监控nginx进程的Python脚本

写了个监控nginx进程的Python脚本,第1张

写了个监控nginx进程的Python脚本 复制代码 代码如下:
#!/usr/bin/env python
import os, sys, time

while True:
time.sleep(3)
try:
ret = os.popen('ps -C nginx -o pid,cmd').readlines()
if len(ret) < 2:
print "nginx process killed, restarting service in 3 seconds."
time.sleep(3)
os.system("service nginx restart")
except:
print "Error", sys.exc_info()[1]

设置文件可执行属性,加入到/etc/rc.local,总算放心了。
这种方法还可以监控别的进程,我相信应该有现成的监控软件,但是我觉得写个脚本更方便。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/3339627.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-10-06
下一篇 2022-10-06

发表评论

登录后才能评论

评论列表(0条)

保存