清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
#-*-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 + ">")