TOMCAT意外停止后自启动服务器监测
发布时间:2020-05-24 23:23:18 所属栏目:Python 来源:互联网
导读:TOMCAT意外停止后自启动服务器监测
|
下面是脚本之家 jb51.cc 通过网络收集整理的代码片段。 脚本之家小编现在分享给大家,也给大家做个参考。 #-*-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 + ">")
以上是脚本之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。 如果觉得脚本之家网站内容还不错,欢迎将脚本之家网站推荐给程序员好友。 (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
