【问题标题】:How to programmatically restart Application Pool when 503 occurs from Azure Web Role从 Azure Web 角色发生 503 时如何以编程方式重新启动应用程序池
【发布时间】:2012-11-21 13:12:47
【问题描述】:

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

这个问题问的问题几乎相同,但与 azure 无关 ASP.NET application pool shutdown problem

可能使用 WebRole 来监控和修改此页面上的代码Is it possible to restart IIS on a Azure web role without restarting the process?

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

【问题讨论】:

    标签: asp.net iis azure azure-web-roles


    【解决方案1】:

    您可以从启动任务中运行the following script(确保创建提升的后台任务):

    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 启动,可能更适合了解您的流程为何一次又一次地崩溃。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多