Skip to content

Commit

Permalink
Updated approach for restarting the instance on configuration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
MattDavies committed May 18, 2014
1 parent cc806ee commit b933b51
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions AzureWebFarm/Config/AzureConfig.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using System;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.AccessControl;
using System.Security.Principal;
using AzureWebFarm.Helpers;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.WindowsAzure.Storage;

namespace AzureWebFarm.Config
Expand All @@ -21,6 +23,18 @@ public static void ConfigureRole()
// Allow multiple simultaneous HTTP request threads
ServicePointManager.DefaultConnectionLimit = 12;

AzureRoleEnvironment.Changed += (sender, arg) =>
{
// Restart the instance on any configuration change given we need to reinitialise our services

// https://alexandrebrisebois.wordpress.com/2013/09/29/handling-cloud-service-role-configuration-changes-in-windows-azure/
// http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.changing.aspx
if ((arg.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)))

This comment has been minimized.

Copy link
@MattDavies

MattDavies May 18, 2014

Author Member

@robdmoore In the new SDK you don't have to use configuration publishing anymore, you instead use CloudConfigurationManager.GetSetting().

I've added back restarting on configuration changes - but using what's now considered a better approach.

{
arg.Cancel = true;
}
};

// Configure local resources
var localTempPath = GetLocalResourcePathAndSetAccess(TempLocalResource);
GetLocalResourcePathAndSetAccess(SitesLocalResource);
Expand Down
16 changes: 15 additions & 1 deletion AzureWebFarm/Helpers/AzureRoleEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,21 @@ public static class AzureRoleEnvironment
public static Action RequestRecycle = () => RoleEnvironment.RequestRecycle();
public static Func<string, string> GetLocalResourcePath = resourceName => RoleEnvironment.GetLocalResource(resourceName).RootPath.TrimEnd('\\');
public static Func<bool> HasWebDeployLease = () => CheckHasWebDeployLease();


static AzureRoleEnvironment()
{
RoleEnvironment.Changing += OnChanging;
}

public static event EventHandler<RoleEnvironmentChangingEventArgs> Changed;

public static void OnChanging(object caller, RoleEnvironmentChangingEventArgs args)
{
var handler = Changed;
if (handler != null)
handler(caller, args);
}

public static CloudBlockBlob WebDeployLeaseBlob()
{
var blob = CachedWebDeployLeaseBlob ?? GetWebDeployLeaseBlob();
Expand Down

7 comments on commit b933b51

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 61 is now running

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 61 is now running

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 61 is now running

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 61 outcome was FAILURE
Summary: Exit code 1 Build time: 0:0:0

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 61 outcome was FAILURE
Summary: Exit code 1 Build time: 0:0:0

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 61 outcome was FAILURE
Summary: Exit code 1 Build time: 0:0:0

@MRCollectiveCI
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TeamCity AzureWebFarm :: Continuous Integration Build 61 outcome was FAILURE
Summary: Exit code 1 Build time: 0:0:0

Please sign in to comment.