手机
当前位置:查字典教程网 >脚本专栏 >python >写了个监控nginx进程的Python脚本
写了个监控nginx进程的Python脚本
摘要:复制代码代码如下:#!/usr/bin/envpythonimportos,sys,timewhileTrue:time.sleep(3)t...

复制代码 代码如下:

#!/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,总算放心了。

这种方法还可以监控别的进程,我相信应该有现成的监控软件,但是我觉得写个脚本更方便。

【写了个监控nginx进程的Python脚本】相关文章:

python使用cookielib库示例分享

一个小示例告诉你Python语言的优雅之处

python实现的防DDoS脚本

重命名批处理python脚本

可用于监控 mysql Master Slave 状态的python代码

Python查看多台服务器进程的脚本分享

下载糗事百科的内容_python版

Python常用正则表达式符号浅析

如何运行Python程序的方法

用Python脚本生成Android SALT扰码的方法

精品推荐
分类导航