1

如果 Azure 站点的应用程序池由于快速故障保护而关闭,是否可以自动重新启动它?

这个问题提出了几乎相同的问题,但与 azure ASP.NET 应用程序池关闭问题无关

可能使用 WebRole 来监视和修改此页面上的代码是否可以在 Azure Web 角色上重新启动 IIS 而无需重新启动进程?

var mgr = new ServerManager();
var azurePools = mgr.ApplicationPools.Where(p => Guid.TryParse(p.Name));
azurePools.ToList().ForEach(p => p.Recycle());
4

1 回答 1

2

您可以从启动任务运行以下脚本(确保创建提升的后台任务):

Timeout= 30000
set events = GetObject("winmgmts:{impersonationLevel=impersonate}").ExecNotificationQuery("select * from __instancecreationevent where targetinstance isa 'Win32_NTLogEvent' and TargetInstance.LogFile='System' and TargetInstance.EventCode=5002") 
Do
    WScript.Echo "==========================================================================="
    WScript.Echo "Listening for IIS Rapid Fail Protection Events"
    Set objLatestEvent = events.NextEvent
    Wscript.Echo objLatestEvent.TargetInstance.Message
    ' get the AppPool name from the Eventlog message
    appPool = objLatestEvent.TargetInstance.InsertionStrings(0)
    WScript.Echo "Restarting Application Pool '" & appPool & "' in " & Timeout & " milliseconds"
    WScript.Sleep(Timeout)
    'construct ADSI path to failed AppPool and start by setting AppPoolCommand to 1
    set pool = GetObject("IIS://localhost/w3svc/AppPools/" & appPool)
    pool.AppPoolCommand = 1
    pool.SetInfo
    WScript.Echo "AppPool " & appPool & " restarted"
    WScript.Echo "==========================================================================="
    WScript.Echo
Loop

使用 WMI 它将侦听 IIS RFP 事件。这是通过与 结合来完成ExecNotificationQueryNextEvent。调用NextEvent将阻塞,直到新事件到达。发生这种情况时,脚本会等待 30 秒并重新启动应用程序池。

无论如何,如果 RFP 启动,可能更适合了解您的流程为何一次又一次地崩溃。

于 2012-11-21T13:26:29.603 回答