linux系统使用python监控apache服务器进程脚本分享
时间:2021-10-15 00:15:41
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) < 2:
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 模块提供各种操作时间的函数。
标签:linux系统,apache服务器
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
JS+CSS实现的日本门户网站经典选项卡导航效果
2023-09-04 03:40:24
![](https://img.aspxhome.com/file/2023/7/56267_0s.png)
Oracle批量查询、删除、更新使用BULK COLLECT提高效率
2023-07-14 03:15:52
Oracle SecureFile的功能第1/4页
2009-06-19 18:07:00
图文详解laravel多对多关联模型
2023-06-12 22:21:34
![](https://img.aspxhome.com/file/2023/4/55544_0s.png)
Bootstrap 模态对话框只加载一次 remote 数据的完美解决办法
2023-08-06 15:58:18
![](https://img.aspxhome.com/file/2023/0/55970_0s.png)
es6函数之严格模式用法实例分析
2023-08-09 06:15:40
OpenCV实现去除背景识别的方法总结
2021-01-06 23:04:10
![](https://img.aspxhome.com/file/2023/0/83880_0s.jpg)
详解Python中@staticmethod和@classmethod区别及使用示例代码
2023-06-03 12:17:20
![](https://img.aspxhome.com/file/2023/5/70235_0s.png)
Python类的用法实例浅析
2023-07-31 11:17:18
python实现将json多行数据传入到mysql中使用
2022-12-28 06:41:51
ASP利用TCPIP.DNS组件实现域名IP查询
2010-02-26 11:25:00
Python项目跨域问题解决方案
2022-12-01 17:39:32
注册表单之电子邮箱
2008-08-19 17:58:00
![](https://img.aspxhome.com/file/UploadPic/20088/19/200881918833479s.jpg)
Python入门必须知道的11个知识点
2023-12-19 05:32:47
Python代码实现列表分组计数
2022-11-03 07:58:38
![](https://img.aspxhome.com/file/2023/7/83737_0s.jpg)
Python CSV模块使用实例
2022-02-04 18:56:36
Pandas对DataFrame单列/多列进行运算(map, apply, transform, agg)
2022-10-10 19:11:55
Python实现批量修改图片格式和大小的方法【opencv库与PIL库】
2021-10-08 09:04:29
![](https://img.aspxhome.com/file/2023/5/89055_0s.png)
按钮表状态还是表动作?
2009-03-23 18:21:00
![](https://img.aspxhome.com/file/UploadPic/20093/23/1-300x272-42s.jpg)
Python面向对象中类(class)的简单理解与用法分析
2021-01-05 00:07:37