TOMCAT意外停止后自启动服务器监测
- 作者: 下一秒待續51364467
- 来源: 51数据库
- 2022-08-12
#-*-coding:utf-8-*-
#python3.3.5
import urllib.request,os,time,configparser
#==============================================
class AutoStar:
def connet(self,url,tpath):
status = 404
try:
status = urllib.request.urlopen(url).code
except Exception as err:
print ('request Exception 404')
if status > 299 :
self.error ('http_status. ' + str(status))
os.chdir(tpath)
self.error("shutdown. " + tpath)
os.system('shutdown.bat')
time.sleep(10)
self.error("startup. " + tpath)
os.system('startup.bat')
else:
self.debug ('http_status. ' + str(status))
os.chdir(pyPath)
self.debug ("-"*20)
def debug(self,msg):
print(msg)
self.mkLogDir()
output = open(pyPath + '/logs/debug.log', 'a')
output .write("\n" + strTime + ' ' + msg)
output .close()
def error(self,msg):
print(msg)
self.mkLogDir()
output = open(pyPath + '/logs/error.log', 'a')
output .write("\n" + strTime + ' ' + msg)
output .close()
def mkLogDir(self):
if os.path.isdir(pyPath +'/logs'):
pass
else:
os.mkdir(pyPath +'/logs')
#==============================================
aStar = AutoStar()
print(">"*50,"start")
conf = 'conf'
pyPath = os.getcwd()
strTime = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
while 1:
for dirpath, dirnames, filenames in os.walk(conf):
#print ('Directory', dirpath)
for filename in filenames:
aStar.debug ('read config file. ' + filename)
config=configparser.ConfigParser()
config.read(conf + '/' +filename)
url = config.get("global", "url")
tpath = config.get("global", "tomcat_path")
aStar.connet(url,tpath)
time.sleep(60)
aStar.debug("="*30 + ">")
推荐阅读
热点文章
Discord.py(重写)on_member_update 无法正常工作
0
Discord.py 在 vc 中获取用户分钟数
0
discord.py 重写 |为我的命令出错
0
Discord.py rewrite 如何 DM 命令?
0
播放音频时,最后一部分被切断.如何解决这个问题?(discord.py)
0
在消息删除消息 Discord.py
0
如何使 discord.py 机器人私人/直接消息不是作者的人?
0
(Discord.py) 如何获取整个嵌入内容?
0
Discord bot 尽管获得了许可,但不能提及所有人
0
Discord.py discord.NotFound 异常
0
