Skip to content

Commit 52afd09

Browse files
johnkattenhornrobdmoore
authored andcommitted
CHANGED: PurgeDefaultIISSite now removes all existing sites and so renamed to PurgeAllSites.
CHANGED: Made PurgeAllSites optional by accepting override on WebFarmRole constructor.
1 parent f5310d0 commit 52afd09

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

AzureWebFarm.OctopusDeploy/Infrastructure/IisEnvironment.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,24 @@ public static void WaitForAllHttpRequestsToEnd()
2323
}
2424
}
2525

26-
public static void PurgeAllDefaultSites()
26+
public static void PurgeAllSites()
2727
{
2828
using (var serverManager = new ServerManager())
2929
{
30-
Guid appGuid;
31-
32-
var applications = serverManager.ApplicationPools
33-
.Where(appPool => Guid.TryParse(appPool.Name, out appGuid)).ToList();
30+
var applications = serverManager.ApplicationPools.ToList();
3431

3532
if (!applications.Any())
3633
{
37-
// There does'nt seem to be any to remove.
34+
// There is nothing to do.
3835

3936
return;
4037
}
4138

4239
foreach (var appPool in applications)
4340
{
44-
// Assumption any pool with name of a GUID was created by Azure.
45-
4641
appPool.Stop();
4742

48-
// Find all site & applications using this pool (Should one be one).
43+
// Find all site & applications using this pool.
4944

5045
var sites = serverManager.Sites
5146
.Where(site => site.Applications.Any(x => x.ApplicationPoolName == appPool.Name)).ToList();

AzureWebFarm.OctopusDeploy/WebFarmRole.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using System;
2+
using System.ComponentModel.Design;
3+
using System.Net.Configuration;
24
using System.Threading;
35
using AzureWebFarm.OctopusDeploy.Infrastructure;
46
using Microsoft.WindowsAzure.ServiceRuntime;
@@ -12,12 +14,14 @@ namespace AzureWebFarm.OctopusDeploy
1214
public class WebFarmRole
1315
{
1416
private readonly Infrastructure.OctopusDeploy _octopusDeploy;
17+
private readonly bool _purgesites;
1518

1619
/// <summary>
1720
/// Create the web role coordinator.
1821
/// </summary>
1922
/// <param name="machineName">Specify the machineName if you would like to override the default machine name configuration.</param>
20-
public WebFarmRole(string machineName = null)
23+
/// <param name="purgeSites">Specify true to remove all sites before installing the tentacle</param>
24+
public WebFarmRole(string machineName = null,bool purgeSites = false)
2125
{
2226
Log.Logger = AzureEnvironment.GetAzureLogger();
2327
var config = AzureEnvironment.GetConfigSettings();
@@ -26,7 +30,9 @@ public WebFarmRole(string machineName = null)
2630
var octopusRepository = Infrastructure.OctopusDeploy.GetRepository(config);
2731
var processRunner = new ProcessRunner();
2832
var registryEditor = new RegistryEditor();
33+
2934
_octopusDeploy = new Infrastructure.OctopusDeploy(machineName, config, octopusRepository, processRunner, registryEditor);
35+
_purgesites = purgeSites;
3036

3137
AzureEnvironment.RequestRecycleIfConfigSettingChanged(config);
3238
}
@@ -37,11 +43,14 @@ public WebFarmRole(string machineName = null)
3743
/// <returns>true; throws exception is there is an error</returns>
3844
public bool OnStart()
3945
{
46+
if (_purgesites)
47+
{
48+
IisEnvironment.PurgeAllSites();
49+
}
50+
4051
_octopusDeploy.ConfigureTentacle();
4152
_octopusDeploy.DeployAllCurrentReleasesToThisMachine();
42-
43-
IisEnvironment.PurgeAllDefaultSites();
44-
53+
4554
return true;
4655
}
4756

0 commit comments

Comments
 (0)