python 监控Tomcat 重启

1.监控脚本

#!/usr/local/python3/bin/python3.6
# -*-coding:utf-8-*-
import subprocess
import datetime
res = subprocess.Popen('ps -ef | grep tomcat',stdout=subprocess.PIPE,shell=True)
tomcats=res.stdout.readlines()
counts=len(tomcats)
if counts<4:
        dt=datetime.datetime.now()
        fp=open('/root/lin/log/tomcat.log','a')
        fp.write('tomcat6 stop at %s\n' % dt.strftime('%Y-%m-%d %H:%M:%S'))
        fp.close()
        subprocess.Popen('/root/lin/run/apache-tomcat-9.0.19/bin/startup.sh',shell=True)

2.定时任务

vim  /etc/crontab

#加入如下信息 每十分钟运行该脚本一次
 

*/10 * * * * root python /root/autorestart-tomcat.py

发布了55 篇原创文章 · 获赞 43 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq_21137441/article/details/89531031