Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

iis

azure

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.

like image 675
Digbyswift Avatar asked Mar 16 '12 09:03

Digbyswift


People also ask

How do I restart Azure IIS?

Click Start, Settings, Control Panel, Administrative Tools. Open Services. Right-click on the IIS Admin Service and select Stop, Start, or Restart.

Do I need to restart IIS after changing web config?

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.

Why does IIS need to be restarted?

The IIS restart command was needed for restarting the web server process to resolve performance issues that may have developed in the application.


1 Answers

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.

like image 115
dunnry Avatar answered Oct 19 '22 10:10

dunnry