IIS与ApplicationPool重启检测自动化解决方案

Friday, November 28, 2014

DA Hotfix Automatic IIS & Application Pool Check-Reset solution

1.右键tool,run as admin;需要联系我​:Tianyou.Lan

2.自动检测完成。

经历了一段时间的研究与学习,我终于完成了这个为检查打Hotfix之后agent端Application/IIS是否重启过的自动化解决方案,并且通过了几轮针对性的测试。如果大家在使用过程中遇到了问题请联系我lync:tianyou lan

需求说明:

  1. 在打完Hotfix之后,QA经常是需要检查IIS以及Application Pool是否重启过
  2. 检测IIS的重启往往是要通过在Event Viewer中查看system logs,手动的去查找source metadata含有IISCTLS字样的log然后分析时间,与打Hotfix开始的时间对比,去估计IIS是否在打Hotfix之后进行了重启。
  3. 检测Application Pool的重启是无法通过log进行判断,而以往QA是通过对比打Hotfix前后w3wp进程的PID值是否发生了改变,而这也需要手动进行完成前后的PID值记录,然后去人为的对比,进而判断Application pool是否在打Hotfix前后进行了重启。这也是开发所给提供的宝贵意见。

难点创新:

  1. 对于之前的自动化解决方案,我的想法是在多台server上开启权限,然后通过脚本判断多台server role,在WFE上检测log以判断IIS reset情况,而对于Application pool的检测则需要在打Hotfix前后分别收集一次数据从而才能判断Application pool是否重启。一共需要运行两次脚本。
  2. 本次的优化,最主要就是体现在对与Application pool的判断上,相对以往判断打Hotfix前后PID值的变化,这一次取而代之的是通过收集打Hotfix时所产生的AvePoint日志从而取到最近一次打Hotfix成功的时间,然后获取w3wp进程并收集它最近一次的StartTime,然后进行判断,若w3wp进程的StartTime晚于最近的Hotfix log的WrittenTime,则说明Application Pool在打Hotfix之后进行了重启。一共只需要运行一次Tool。

PowerShell Code:

#获取w3wp进程所对应的Application pool(这个函数是在网上搜的)

function global:get-apppools{

[regex]$pattern="-ap ""(.+)"""

gwmi win32_process -filter 'name="w3wp.exe"' | % {

$name=$_.name

$cmd = $pattern.Match($_.commandline).Groups[1].Value

$procid = $_.ProcessId

New-Object psobject | Add-Member -MemberType noteproperty -PassThru Name $name |

Add-Member -MemberType noteproperty -PassThru AppPoolID $cmd |

Add-Member -MemberType noteproperty -PassThru PID $procid

}

}

#最新W3Wp进程开启的时间

$global:W3WPSProcesses=Get-Process -Name w3wp -ErrorAction SilentlyContinue

if($global:W3WPSProcesses -is [array]){

#如果有很多的w3wp进程,取最新的那个。

$global:W3WPStartTime=0

for($j=0;$j -lt $global:W3WPSProcesses.length;$j++){

if($global:W3WPSProcesses[$j].StartTime -gt $global:W3WPStartTime){

$global:W3WPStartTime=$global:W3WPSProcesses[$j].StartTime

}

}

}else{

#只有一个w3wp进程时,获取到w3wp进程的starttime。

$global:W3WPStartTime=$global:W3WPSProcesses.StartTime

}

#最近一个Hotfix开始的时间

$global:HotfixLog=Get-EventLog avepoint|Where-Object {$_.Category -like "*Update Manager*"}

if($global:HotfixLog -is [array]){

#0位为最新的Hotfix时间

$global:HotfixTime=$global:HotfixLog[0].TimeWritten

}else{

$global:HotfixTime=$global:HotfixLog.TimeWritten

}

function CheckPool{

begin{

$global:NewOrOldProcess=0

$global:Old=0

$global:New=0

}

process{

if($_.starttime -gt $global:HotfixTime){

$global:NewOrOldProcess=$global:NewOrOldProcess+1

$global:Old=$global:Old+1

$global:New=$global:New+1

$global:process=$_

$global:nameofthepool=(global:get-apppools|Where-Object {$_.pid -eq  $global:process.id}).apppoolid

$global:IndexOfEnd=$global:nameofthepool.indexof('"')

$global:shortNameOfThePool=$global:nameofthepool.substring(0,$global:IndexOfEnd)

Write-Host "The application pool [ $global:shortNameOfThePool ] has reset or the w3wp process of it is new created after the 'Hotfix' updated."

Write-Host "-----------------------"

}else{

$global:Old=$global:Old+1

$global:process=$_

$global:nameofthepool=(global:get-apppools|Where-Object {$_.pid -eq  $global:process.id}).apppoolid

$global:IndexOfEnd=$global:nameofthepool.indexof('"')

$global:shortNameOfThePool=$global:nameofthepool.substring(0,$global:IndexOfEnd)

Write-Host "The application pool [ $global:shortNameOfThePool ] has not reset after the 'Hotfix' updated."

Write-Host "-----------------------"

}

}

end{

if($global:NewOrOldProcess -ne 0){

if($global:New -lt $global:Old){

Write-Host "Through the analysis from 'HotCheck':"

Write-Host "Not all the application pool(s) has been reset or new created after the 'Hotfix' updated."

}

if($global:New -eq $global:Old){

Write-Host "Through the analysis from 'HotCheck':"

Write-Host "All the application pool(s) has been reset or new created after the 'Hotfix' updated."

}

}else{

Write-Host "Through the analysis from 'HotCheck':"

Write-Host "No application pool has been reset or new created after the 'Hotfix' updated."

}

}

}

Get-Process -Name w3wp -ErrorAction SilentlyContinue|CheckPool

#判断IIS是否在打Hotfix之后重启过

#i和p都是IISReset标记,0代表没有重启过,否则代表重启过。i代表没有Hotfix,p代表有Hotfix。

$global:i=0

$global:p=0

#$global:IISLogs=Get-EventLog system -After ((get-date).addhours(-5))| where-object {$_.source -like "*IIS*"}

$global:IISLogs=Get-EventLog system| where-object {$_.source -like "*IIS*"}

#filter,判断每一条日志,总的结果输出为i或p。

filter IISCK{

if($global:HotfixTime){

if($_){

if($_.TimeWritten -gt $global:HotfixTime){

$global:p=$global:p+1

}

}

}else{

if($_){

$global:i=$global:i+1

}

}

}

#将IISLogs放入过滤器进行判断

$global:IISLogs|IISCK

#判断结果

if($global:i -ne 0){

Write-Host "Since there're no 'Hotfix' updated, we don't need to care about whether the IIS has been reset yet."

}

if($global:p -ne 0){

Write-Host "IIS has been reset after the 'Hotfix' updated."

}

if($global:i -eq 0){

if($global:p -eq 0){

Write-Host "IIS hasn't been reset after the 'Hotfix' updated."

}

}

Read-Host "Press any key to quit"

Tool:

Hotfix Automatic Check,简称Hot Check,"火柴"。

经历了:

  1. 在用需要重启IIS的Hotfix进行测试,通过测试;
  2. 在用只需要重启Application Pool的Hotfix测试,通过测试;
  3. 为克服在不支持大部分PowerShell指令,比如get-date和sort-object的机器上能正常运行,重写排序算法代替sort-object指令,通过功能测试。
  4. 在多台打Hotfix的WFE上进行测试,均能正确显示测试结果,通过测试。

下载地址:

感谢:

感谢Lardy 哥给予的支持;

感谢过程中得到的萌萌姐,Di Sun,Xue Pan在测试上的帮助;

另:感谢DL的Dora Liu强力打包的四个针对性测试patch和Zhenpeng Liu的各种支持。

IIS与ApplicationPool重启检测自动化解决方案的更多相关文章

  1. C# 因IIS回收导致定时器失效的解决方案

    首先不要设置iis自动回收,一般设置凌晨1-2点左右回收一次,当凌晨iis回收应用程序池的时候,会调用Application_End,执行里面的代码, 重新启动网站,建议定时器的代码放在Session ...

  2. Windows+.Net Framework+svn+IIS在Jenkins上的自动化部署入门

    关于Jenkins的使用及安装,上一篇文章我已经介绍过了,Windows+.NetCore+git+IIS在Jenkins上的自动化部署入门.这篇主要是在jenkins如何安装SVN和MSBuild. ...

  3. Linux配置完iptables后,重启失效的解决方案

    Linux配置完iptables后,重启失效的解决方案 因为只有root用户才可访问1024以下的端口,非root用户登陆是不能启用80端口的.web service 往往启动1024以上的端口,并通 ...

  4. iis 部署webapi常见错误及解决方案

    iis 部署webapi常见错误及解决方案 错误一: 原因:asp.net web api部署在Windows服务器上后,按照WebAPI定义的路由访问,老是出现404,但定义一个静态文件从站点访问, ...

  5. 本号讯 | 微软被 Forrester 评为销售服务自动化解决方案领导者

    2017年第二季度独立研究机构 Forrester Research 在最新发布的 The Forrester Wave™: 销售服务自动化(Sales Force Automation Soluti ...

  6. 关键CSS和Webpack: 减少阻塞渲染的CSS的自动化解决方案

    原文地址: Critical CSS and Webpack: Automatically Minimize Render-Blocking CSS 原文作者: Anthony Gore 译者: 蜗牛 ...

  7. APP自动化之Hybrid自动化解决方案(七)

    基于UIAutomator+ChromeDriver模式(UIAutomator安卓原生引擎) 原理:native(原生)部分使用UIAutomator,webview部分使用ChromeDriver ...

  8. 翻译 | 关键CSS和Webpack: 减少阻塞渲染的CSS的自动化解决方案

    原文地址: Critical CSS and Webpack: Automatically Minimize Render-Blocking CSS 原文作者: Anthony Gore 译者: 蜗牛 ...

  9. 摘-BMC自动化解决方案产品概览

    以下内容摘自BMC解决方案白皮书 BMC 解决方案助力您的企业快速享受自动化带来的快速效益,并随时间推移实现这些优势的最大化. BMC 自动化技术可帮助您优化敏捷性,同时保持必要的治理和合规性控制.无 ...

随机推荐

  1. Leetcode: Alien Dictionary && Summary: Topological Sort

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  2. Nginx简单配置

    Nginx 配置文件结构如果你下载好啦,你的安装文件,不妨打开 conf 文件夹的 nginx.conf 文件,Nginx 服务器的基础配置,默认的配置也存放在此.在 nginx.conf 的注释符号 ...

  3. Hdu-3487 Splay树,删除,添加,Lazy延迟标记操作

    HDU_3487 题意:给出n和q,n代表1-n的序列,接下来q有两种操作,Cut a b c:表示把区间[a,b]截掉然后放在第c个数的后面,Flip a b 表示把区间[a,b]反转,经过一系列的 ...

  4. DO.NET操作数据库

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. UVA 10498 Happiness(线性规划-单纯形)

    Description Prof. Kaykobad has given Nasa the duty of buying some food for the ACM contestents. Nasa ...

  6. ANDROID模拟火花粒子的滑动喷射效果

    转载请注明本文出自大苞米的博客(http://blog.csdn.net/a396901990),谢谢支持! 开篇废话: 年前换了一个手机,SONY的Z3C.这个手机在解锁屏幕时有一个滑动动画,类似火 ...

  7. paper 53 :深度学习(转载)

    转载来源:http://blog.csdn.net/fengbingchun/article/details/50087005 这篇文章主要是为了对深度学习(DeepLearning)有个初步了解,算 ...

  8. app_field.clear_dependent_fields

    可以调用APP_FIELD.clear_dependent_fields和APP_FIELD.set_dependent_field来将两个(或多个)Item建立关联,当一个为空时,另一个不可录入,反 ...

  9. 自动开票-不能获取汇款地址 Cannot get remit to address

    1. Cannot get remit to address 1. 查看客户Bill-to Address的Country信息; 2. 选择Receivable Manager职责,通过路径Setup ...

  10. 夺命雷公狗---Thinkphp----6之管理员的增删改查之-未验证

    首先我们创建多一个控制器UserController.class.php,主要用于管理员的增删改查操作: 代码如下所示: <?php namespace Admin\Controller; us ...