我们有一个Azure Web App,我们想要按计划设置自动重启。如果我想使用Runbook来做这件事,我如何添加一个或多个应用程序来按不同的计划自动重启?
发布于 2018-06-09 07:13:49
有许多不同的方法可以做到这一点,其中一些将取决于您拥有的Azure-Runbook模块版本。
要获得连接,您可以使用cmdlet:Get-AutomationConnection
如果您设置了一个$result= Restart-AzureRmWebApp
,如果$result
为空,则它不起作用,否则您将看到正在运行的webapp的状态。例如:如果工作成功,则返回$result.State = "Running"
。
要在 Schedule 上执行此操作,请转到Runbook > Schedules > Add Schedule。
添加输入参数,并选择/创建循环计划。单击Ok,您就完成了!
*如果对webAppName使用参数,则可以重用runbook,只需添加具有不同输入参数的不同计划
示例代码。
try
{
$servicePrincipalConnection= Get-AutomationConnection -Name "AzureRunAsConnection"
# Logging in to Azure
$account = Add-AzureRmAccount `
-ServicePrincipal `
-TenantId $servicePrincipalConnection.TenantId `
-ApplicationId $servicePrincipalConnection.ApplicationId `
-CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint
Select-AzureRmSubscription -SubscriptionName "Azure subscription name"
$result = Restart-AzureRmWebApp `
-ResourceGroupName "Resource Name"
-Name "Name of webapp you want to restart"
if($result)
{
$state = $result.State
Write-Output ("Web app restarted and is now $state") #State should be Running at this point
}
else
{
Write-Output ("Web app did NOT restart")
}
}
catch
{
Write-Output ("Web app did NOT restart")
throw $_.Exception
}
https://stackoverflow.com/questions/50768891
复制相似问题