找回密码
 立即注册

QQ登录

只需一步,快速开始

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服务名称,灵活使用方法,自行探索~

本教程由无限星辰工作室CRX349独家整理和提供,转载请注明地址,谢谢。本文地址:https://www.xmspace.net/thread-830-1-1.html
无限星辰工作室  好集导航 Discuz全集下载  星辰站长网  集热爱361  一品文学  手机小游戏合集   海外空间网 星辰api  星辰支付二维码管理平台 阿里云服务器 腾讯云服务器
服务Discuz!建站|DiscuzQ配置|二开|小程序|APP|搬家|挂马清理|防护|Win/Linux环境搭建|优化|运维|
服务理念:专业 诚信 友好QQ842062626 服务项目 Q群315524225

发表于 2020-5-17 20:47:14 | 显示全部楼层 |阅读模式

回复 | 使用道具 举报

该帖共收到 0 条回复!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

美图秀

    • fastadmin 后台界面使用字段数组类型
    • Discuz!x3.5 修改标题高亮颜色
    • Discuz!x3.5 应用中心 下载应用一直下载中
    • 帖子定时显示
    • 论坛辅助审核
拖动客服框
Online Service
点击这里给我发消息
点击这里联系我们
微信扫一扫
在线客服
快速回复 返回顶部 返回列表