Skip to content

Commit 1c0946b

Browse files
committed
Merge branch 'pull-request-28' fixes #28
2 parents ba03d74 + 52afd09 commit 1c0946b

File tree

2 files changed

+49
-1
lines changed

2 files changed

+49
-1
lines changed

AzureWebFarm.OctopusDeploy/Infrastructure/IisEnvironment.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,42 @@ public static void WaitForAllHttpRequestsToEnd()
2323
}
2424
}
2525

26+
public static void PurgeAllSites()
27+
{
28+
using (var serverManager = new ServerManager())
29+
{
30+
var applications = serverManager.ApplicationPools.ToList();
31+
32+
if (!applications.Any())
33+
{
34+
// There is nothing to do.
35+
36+
return;
37+
}
38+
39+
foreach (var appPool in applications)
40+
{
41+
appPool.Stop();
42+
43+
// Find all site & applications using this pool.
44+
45+
var sites = serverManager.Sites
46+
.Where(site => site.Applications.Any(x => x.ApplicationPoolName == appPool.Name)).ToList();
47+
48+
foreach (var site in sites)
49+
{
50+
serverManager.Sites[site.Name].Stop();
51+
52+
serverManager.Sites.Remove(site);
53+
}
54+
55+
serverManager.ApplicationPools.Remove(appPool);
56+
}
57+
58+
serverManager.CommitChanges();
59+
}
60+
}
61+
2662
public static void ActivateAppInitialisationModuleForAllSites()
2763
{
2864
// https://github.com/sandrinodimattia/WindowsAzure-IISApplicationInitializationModule

AzureWebFarm.OctopusDeploy/WebFarmRole.cs

Lines changed: 13 additions & 1 deletion
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,8 +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();
53+
4254
return true;
4355
}
4456

0 commit comments

Comments
 (0)