简体   繁体   中英

Detect that a IIS Worker Process is deadlocked and recycle the Application Pool

Is it possible to use powershell to detect an IIS worker process thread deadlock and then trigger an Application Pool recycle?

The Reason: I have a website that calls an assembly in the GAC that sometimes just holds the thread in deadlock and the only fix is to recycle the Application Pool of the website in IIS, the annoying thing is that a user has to notice it before I am told, it would be good to automate this process.

This is how I would do it. First we have to find a way to detect if the thread is deadlocked. I am guessing that you can probably do that with something as simple as a ping. Then we have to Recycle the App Pool.

# 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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM