监听服务器 重启apache

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 \r\n" % time.strftime('%m-%d %H:%M:%S',time.localtime(time.time()))
    else:
        str = "status ok:%s \r\n" % time.strftime('%m-%d %H:%M:%S',time.localtime(time.time()))
    with open("/www/web/pythontask/count.txt","a+") as f:
        f.write(str)
posted @ 2018-02-08 19:10  geek程序员  阅读(324)  评论(0编辑  收藏  举报