How do you turn an Azure Website on and off on a schedule?

僤鯓⒐⒋嵵緔 提交于 2019-12-08 03:49:25

问题


I have a line of business app that I want to deploy to Windows Azure. The app is only needed during office ours so to save on costs I want to turn the Azure Website on and off outside of business hours.

How is this achievable?


回答1:


You can do this using Azure Automation (currently in preview). To do this,

Create a Runbook to Start the website. For example,

workflow StartContosoWebsite
{
    $cred = Get-AutomationPSCredential -Name "rick@cloudalloc.com"

    Add-AzureAccount -Credential $cred

    InlineScript {

        Select-AzureSubscription -SubscriptionName "MCT"

        Start-AzureWebsite -Name "contoso-web"  
    }
}

Create a Runbook to Stop the website. For example,

workflow StopContosoWebsite
{
    $cred = Get-AutomationPSCredential -Name "rick@cloudalloc.com"

    Add-AzureAccount -Credential $cred

    InlineScript {

        Select-AzureSubscription -SubscriptionName "MCT"

        Stop-AzureWebsite -Name "contoso-web"  
    }
}

Create an Asset in your automation account for the credentials you use in your runbooks to start and stop the web site. For example,

Then, for each runbook, define the schedule you want it to run on. For your scenario, you would want to define a Daily schedule to run every 7 days. Using the example above, the StartContosoWebsite would run on Monday morning at some time you specify. The StopContosoWebsite would run on Friday eventing at some time you specify.



来源:https://stackoverflow.com/questions/25929339/how-do-you-turn-an-azure-website-on-and-off-on-a-schedule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!