25 Star 41 Fork 7

立冬/spiderkit

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
monitor.py 899 Bytes
一键复制 编辑 原始数据 按行查看 历史
立冬 提交于 2015-05-04 19:12 . add monitor
import os
import sys
import subprocess
import time
def monitor_process(key_word, cmd):
p1 = subprocess.Popen(['ps', '-e'], stdout=subprocess.PIPE)
p2 = subprocess.Popen(['grep', key_word], stdin=p1.stdout, stdout=subprocess.PIPE)
p3 = subprocess.Popen(['grep', '-v', 'grep'], stdin=p2.stdout, stdout=subprocess.PIPE)
lines = p3.stdout.readlines()
if len(lines) > 0:
return
sys.stderr.write('process[%s] is lost, run [%s]\n' % (key_word, cmd))
subprocess.call(cmd, shell=True)
def main():
while True:
pidstr = ""
try:
fp = open("spiderkit.pid", "r")
pidstr = fp.read()
pidstr = pidstr.replace("\n","").replace("\r","").replace(" ", "")
print pidstr
fp.close()
except:
break
monitor_process(pidstr, "./spiderkit-run.sh")
time.sleep(5)
main()
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/wangsihong/spiderkit.git
git@gitee.com:wangsihong/spiderkit.git
wangsihong
spiderkit
spiderkit
master

搜索帮助