我有一个业务线应用程序想要部署到 Windows Azure。该应用程序仅在我们的办公室期间需要,因此为了节省成本,我想在工作时间之外打开和关闭 Azure 网站。
如何实现这一目标?
最佳答案
您可以使用 Azure 自动化(当前处于预览版)来执行此操作。为此,
创建运行手册来启动网站。例如,
workflow StartContosoWebsite
{
$cred = Get-AutomationPSCredential -Name "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="295b404a42694a45465c4d484545464a074a4644" rel="noreferrer noopener nofollow">[email protected]</a>"
Add-AzureAccount -Credential $cred
InlineScript {
Select-AzureSubscription -SubscriptionName "MCT"
Start-AzureWebsite -Name "contoso-web"
}
}
创建 Runbook 以停止网站。例如,
workflow StopContosoWebsite
{
$cred = Get-AutomationPSCredential -Name "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="16647f757d56757a796372777a7a79753875797b" rel="noreferrer noopener nofollow">[email protected]</a>"
Add-AzureAccount -Credential $cred
InlineScript {
Select-AzureSubscription -SubscriptionName "MCT"
Stop-AzureWebsite -Name "contoso-web"
}
}
在您的自动化帐户中为您在 Runbook 中用于启动和停止网站的凭据创建一个 Assets 。例如,
然后,对于每个 Runbook,定义您希望其运行的计划。对于您的场景,您需要定义一个每日计划来每 7 天运行一次。使用上面的示例,StartContosoWebsite 将在星期一早上您指定的某个时间运行。 StopContosoWebsite 将在周五您指定的某个时间运行事件。
关于azure - 如何按计划打开和关闭 Azure 网站?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25929339/