无限星辰工作室-客户无限互联网动力之源

标题: Win环境下 IIS服务检查 自动启动脚本(适用任意win服务检查) [打印本页]

作者: crx349    时间: 2020-5-17 20:47
标题: Win环境下 IIS服务检查 自动启动脚本(适用任意win服务检查)
最近遇到比较奇葩的事情,某win服务器重启后 iis怎样都无法自动启动,系统又不想重装,所以写了以下Python脚本,备用同时分享下:
git:https://github.com/crx349/iis_auto_restart/
  1. # -*- coding: utf-8 -*-
  2. # Author:Crx349 www.xmspace.net
  3. import os

  4. def get_stop_service(designation):
  5.     """To obtain a list of running the service name,
  6.     check whether the monitoring server is present in the list.
  7.     """
  8.     lines = os.popen('net start').readlines()
  9.     line = [item.strip() for item in [i for i in lines]]
  10.     if designation in line:
  11.         return True
  12.     else:
  13.         return False
  14.                
  15. def main(sname):
  16.         isDown = get_stop_service(sname)
  17.         return isDown
  18.         
  19. if __name__ == '__main__':

  20.     name = 'World Wide Web Publishing Service'
  21.     response = main(name)
  22.     f = "iischeck_log.txt"
  23.     file = open(f,"a")
  24.     if response:
  25.         file.write(str(name)+" "+str(response)+"\n")
  26.     else:
  27.             os.system('iisreset /start')
  28.             file.write(str(name)+" start ok"+"\n")
复制代码


本脚本作用是,检查iis服务是否在启动列表,如果不在,自动启动脚本(可以设置为计划任务循环检查)
备注:

win2008的iis服务名称 叫:World Wide Web Publishing Service

win2016的iis服务名称叫:World Wide Web 发布服务

理论上支持任意win服务名称,灵活使用方法,自行探索~




欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://www.xmspace.net/) Powered by Discuz! X3.4