网络编程
位置:首页>> 网络编程>> Python编程>> 写了个监控nginx进程的Python脚本

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

  发布时间:2021-12-21 12:48:54 

标签:nginx进程

#!/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
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com