File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed
AzureWebFarm.OctopusDeploy Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,47 @@ public static void WaitForAllHttpRequestsToEnd()
2323 }
2424 }
2525
26+ public static void PurgeAllDefaultSites ( )
27+ {
28+ using ( var serverManager = new ServerManager ( ) )
29+ {
30+ Guid appGuid ;
31+
32+ var applications = serverManager . ApplicationPools
33+ . Where ( appPool => Guid . TryParse ( appPool . Name , out appGuid ) ) . ToList ( ) ;
34+
35+ if ( ! applications . Any ( ) )
36+ {
37+ // There does'nt seem to be any to remove.
38+
39+ return ;
40+ }
41+
42+ foreach ( var appPool in applications )
43+ {
44+ // Assumption any pool with name of a GUID was created by Azure.
45+
46+ appPool . Stop ( ) ;
47+
48+ // Find all site & applications using this pool (Should one be one).
49+
50+ var sites = serverManager . Sites
51+ . Where ( site => site . Applications . Any ( x => x . ApplicationPoolName == appPool . Name ) ) . ToList ( ) ;
52+
53+ foreach ( var site in sites )
54+ {
55+ serverManager . Sites [ site . Name ] . Stop ( ) ;
56+
57+ serverManager . Sites . Remove ( site ) ;
58+ }
59+
60+ serverManager . ApplicationPools . Remove ( appPool ) ;
61+ }
62+
63+ serverManager . CommitChanges ( ) ;
64+ }
65+ }
66+
2667 public static void ActivateAppInitialisationModuleForAllSites ( )
2768 {
2869 // https://github.com/sandrinodimattia/WindowsAzure-IISApplicationInitializationModule
Original file line number Diff line number Diff line change @@ -39,6 +39,9 @@ public bool OnStart()
3939 {
4040 _octopusDeploy . ConfigureTentacle ( ) ;
4141 _octopusDeploy . DeployAllCurrentReleasesToThisMachine ( ) ;
42+
43+ IisEnvironment . PurgeAllDefaultSites ( ) ;
44+
4245 return true ;
4346 }
4447
You can’t perform that action at this time.
0 commit comments