检测IIS工作进程是否已死锁并重新启动应用程序池

时间:2014-03-25 03:43:34

标签: asp.net iis powershell deadlock application-pool

是否可以使用powershell检测IIS工作进程线程死锁,然后触发应用程序池回收?

原因:我有一个网站调用GAC中的程序集,有时只是将线程保持在死锁状态,唯一的解决方法是在IIS中回收网站的应用程序池,令人讨厌的是用户必须在我被告知之前注意它,自动化这个过程会很好。

1 个答案:

答案 0 :(得分:0)

我就是这样做的。首先,我们必须找到一种方法来检测线程是否死锁。我猜你可以用ping这么简单的东西来做。然后我们必须回收应用程序池。

# Load IIS module:
Import-Module WebAdministration

# Set a name of the site we want to recycle the pool for:
$site = "Default Web Site"

# Get pool name by the site name:
$pool = (Get-Item "IIS:\Sites\$site"| Select-Object applicationPool).applicationPool

#Check to see if the site is deadlocked.
if(!(Test-Connection -ComputerName Server -Quiet))
{
    #Site is Deadlocked. Recycle the application pool:
    Restart-WebAppPool $pool
}
相关问题