简体   繁体   中英

Is it possible to restart IIS on a Azure web role without restarting the process?

I have a site running on an Azure web role and I can force restart the application by modifying the web.config but if I want to restart IIS I have been told that I should never do this manually via remote desktop and that instead I should restart the Azure hosted process.

This article seems to agree with this opinion.

My problem is that restarting a process can take nearly 10-15 minutes to restart. Is there a quicker way to achieve this?

I am currently using the windows.azure.com UI to do all deployments and management.

A couple things to point out here. When your role starts, it uses something called the IISConfigurator to call out programmatically to IIS and create apps, vdirs, app pools, etc. as defined in Service Definition. That is done once on startup.

Remember that the w3wp.exe process that hosts your website is completely separate from the RoleEntryPoint that you might use to run code. As such, you cannot just called RoleEntryPoint.RequestRecycle() and expect that IIS will restart (it won't).

One solution you might try if you must restart IIS is to programmatically do it. Here is my 3 line solution for restarting IIS on Windows Azure:

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

I am using the knowledge that application pools are GUIDs in Windows Azure to filter them down to the ones I am interested in.

Now, you just need a way to run that code from an elevated condition on demand across each instance. That is a common problem with lots of solutions. Perhaps have each instance poll a file or table for a signal to run that code whenever you need to restart IIS.

If you deploy your application as App Service "YourName" like

Azure应用服务

with url http://yourname.azurewebsites.net you should be able to connect to http://yourname.scm.azurewebsites.net using the same credentials as for Azure management. At this url you find Kudu for respective App Service.

If you select in menu Tools>Support and then select Analyze>Metrics then you should be able to click at "Restart w3wp".

Kudu UI

Time for application to be operational again wasn't unexpectedly long for 3 applications I tested.

If you need only to "observe" w3wp then you may check https://youname.scm.azurewebsites.net/ProcessExplorer/

Why do you need to restart the instance? Are you experiencing a memory leak or some other problem in your production deployment? In a production environment, the only truly safe way to restart an instance is via the Azure management portal or the Azure management REST API.

If you're working with a dev/test deployment, you can RDP in and take your instance offline using the Set-RoleInstanceStatus PowerShell Cmdlet. At this point you're free to run IISReset, restart the WWW publishing service, modify the web.config, copy new dlls to the bin folder, etc., etc. We do these things all time with our dev/test instances without a problem, but we never tinker with our production instances via RDP unless we need to troubleshoot an urgent issue.

您可以尝试远程桌面到实例并以这种方式回收IIS

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