linux系统使用python监控apache服务器进程脚本分享

WBOY
Release: 2016-06-16 08:45:41
Original
1308 people have browsed it

crtrl.py监控Apache服务器进程的Python 脚本

复制代码 代码如下:

!/usr/bin/env Python
import os, sys, time

while True:
time.sleep(4)
try:
ret = os.popen('ps -C apache -o pid,cmd').readlines()
if len(ret) print "apache 进程异常退出, 4 秒后重新启动"
time.sleep(3)
os.system("service apache2 restart")
except:
print "Error", sys.exc_info()[1]

设置文件权限为执行属性(使用命令 chmod +x crtrl.py),然后加入到/etc/rc.local 即可,一旦 Apache 服务器进程异常退出,该脚本自动检查并且重启。 简单说明一下清单 5 这个脚本不是基于/proc 伪文件系统的,是基于 Python 自己提供的一些模块来实现的 。这里使用的是 Python 的内嵌 time 模板,time 模块提供各种操作时间的函数。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!