import requests
import os
import time
url = 'http://www.ydyigo.com/findPwd.php'
def get_server_status(url):
try:
res = requests.head(url,timeout=30)
return res.status_code
except:
print 'timeout'
if __name__ == '__main__':
if get_server_status(url) != 200:
os.system("service httpd restart")
str = "restart :%s
" % time.strftime('%m-%d %H:%M:%S',time.localtime(time.time()))
else:
str = "status ok:%s
" % time.strftime('%m-%d %H:%M:%S',time.localtime(time.time()))
with open("/www/web/pythontask/count.txt","a+") as f:
f.write(str)