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

2020-03-20 10:53:52 浏览数 (1)

代码语言:javascript复制
#!/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,总算放心了。

0 人点赞