最近遇到比较奇葩的事情,某win服务器重启后 iis怎样都无法自动启动,系统又不想重装,所以写了以下Python脚本,备用同时分享下:
git:https://github.com/crx349/iis_auto_restart/
- # -*- coding: utf-8 -*-
- # Author:Crx349 www.xmspace.net
- import os
- def get_stop_service(designation):
- """To obtain a list of running the service name,
- check whether the monitoring server is present in the list.
- """
- lines = os.popen('net start').readlines()
- line = [item.strip() for item in [i for i in lines]]
- if designation in line:
- return True
- else:
- return False
-
- def main(sname):
- isDown = get_stop_service(sname)
- return isDown
-
- if __name__ == '__main__':
- name = 'World Wide Web Publishing Service'
- response = main(name)
- f = "iischeck_log.txt"
- file = open(f,"a")
- if response:
- file.write(str(name)+" "+str(response)+"\n")
- else:
- os.system('iisreset /start')
- file.write(str(name)+" start ok"+"\n")
复制代码
本脚本作用是,检查iis服务是否在启动列表,如果不在,自动启动脚本(可以设置为计划任务循环检查)
备注:
win2008的iis服务名称 叫:World Wide Web Publishing Service
win2016的iis服务名称叫:World Wide Web 发布服务
理论上支持任意win服务名称,灵活使用方法,自行探索~ |