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.
Click Start, Settings, Control Panel, Administrative Tools. Open Services. Right-click on the IIS Admin Service and select Stop, Start, or Restart.
The core IIS services (Http. sys, W3SVC, WAS) never need to be restarted. Instead, they automatically detect any relevant configuration changes (e.g. new website being created, or a change in your application pool settings) and apply them on the fly.
The IIS restart command was needed for restarting the web server process to resolve performance issues that may have developed in the application.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With