public static void StopStart(IWebApp app) { WriteSection("Applying a possible stop/start fix"); Log("Stopping Web App"); app.Stop(); LetsWaitALittle(); Log("Starting Web App"); app.Start(); LetsWaitALittle(); }
/** * Azure App Service basic sample for managing web apps. * - Create 3 linux web apps under the same new app service plan: * - 1, 2 are in the same resource group, 3 in a different one * - Stop and start 1, restart 2 * - Add Java support to app 3 * - List web apps * - Delete a web app */ public static void RunSample(IAzure azure) { string app1Name = SdkContext.RandomResourceName("webapp1-", 20); string app2Name = SdkContext.RandomResourceName("webapp2-", 20); string app3Name = SdkContext.RandomResourceName("webapp3-", 20); string rg1Name = SdkContext.RandomResourceName("rg1NEMV_", 24); string rg2Name = SdkContext.RandomResourceName("rg2NEMV_", 24); try { //============================================================ // Create a web app with a new app service plan Utilities.Log("Creating web app " + app1Name + " in resource group " + rg1Name + "..."); IWebApp app1 = azure.WebApps .Define(app1Name) .WithRegion(Region.USWest) .WithNewResourceGroup(rg1Name) .WithNewLinuxPlan(PricingTier.StandardS1) .WithBuiltInImage(RuntimeStack.NodeJS_6_9) .Create(); Utilities.Log("Created web app " + app1.Name); Utilities.Print(app1); //============================================================ // Create a second web app with the same app service plan Utilities.Log("Creating another web app " + app2Name + " in resource group " + rg1Name + "..."); IAppServicePlan plan = azure.AppServices.AppServicePlans.GetById(app1.AppServicePlanId); IWebApp app2 = azure.WebApps .Define(app2Name) .WithExistingLinuxPlan(plan) .WithExistingResourceGroup(rg1Name) .WithBuiltInImage(RuntimeStack.NodeJS_6_9) .Create(); Utilities.Log("Created web app " + app2.Name); Utilities.Print(app2); //============================================================ // Create a third web app with the same app service plan, but // in a different resource group Utilities.Log("Creating another web app " + app3Name + " in resource group " + rg2Name + "..."); IWebApp app3 = azure.WebApps .Define(app3Name) .WithExistingLinuxPlan(plan) .WithNewResourceGroup(rg2Name) .WithBuiltInImage(RuntimeStack.NodeJS_6_9) .Create(); Utilities.Log("Created web app " + app3.Name); Utilities.Print(app3); //============================================================ // stop and start app1, restart app 2 Utilities.Log("Stopping web app " + app1.Name); app1.Stop(); Utilities.Log("Stopped web app " + app1.Name); Utilities.Print(app1); Utilities.Log("Starting web app " + app1.Name); app1.Start(); Utilities.Log("Started web app " + app1.Name); Utilities.Print(app1); Utilities.Log("Restarting web app " + app2.Name); app2.Restart(); Utilities.Log("Restarted web app " + app2.Name); Utilities.Print(app2); //============================================================ // Configure app 3 to have Java 8 enabled Utilities.Log("Adding Java support to web app " + app3Name + "..."); app3.Update() .WithJavaVersion(JavaVersion.V8Newest) .WithWebContainer(WebContainer.Tomcat8_0Newest) .Apply(); Utilities.Log("Java supported on web app " + app3Name + "..."); //============================================================= // List web apps Utilities.Log("Printing list of web apps in resource group " + rg1Name + "..."); foreach (IWebApp webApp in azure.WebApps.ListByResourceGroup(rg1Name)) { Utilities.Print(webApp); } Utilities.Log("Printing list of web apps in resource group " + rg2Name + "..."); foreach (IWebApp webApp in azure.WebApps.ListByResourceGroup(rg2Name)) { Utilities.Print(webApp); } //============================================================= // Delete a web app Utilities.Log("Deleting web app " + app1Name + "..."); azure.WebApps.DeleteByResourceGroup(rg1Name, app1Name); Utilities.Log("Deleted web app " + app1Name + "..."); Utilities.Log("Printing list of web apps in resource group " + rg1Name + " again..."); foreach (IWebApp webApp in azure.WebApps.ListByResourceGroup(rg1Name)) { Utilities.Print(webApp); } } finally { try { Utilities.Log("Deleting Resource Group: " + rg2Name); azure.ResourceGroups.DeleteByName(rg2Name); Utilities.Log("Deleted Resource Group: " + rg2Name); Utilities.Log("Deleting Resource Group: " + rg1Name); azure.ResourceGroups.DeleteByName(rg1Name); Utilities.Log("Deleted Resource Group: " + rg1Name); } catch (NullReferenceException) { Utilities.Log("Did not create any resources in Azure. No clean up is necessary"); } catch (Exception g) { Utilities.Log(g); } } }