【发布时间】:2018-12-17 21:36:11
【问题描述】:
我正在使用具有多个角色进程的 Azure 云服务(经典)。其中一个是一周后变得有点不稳定的工人,所以我想每隔几天重新启动一次。最终,worker 角色将变得稳定,但与此同时,如果可能的话,每隔几天自动重新启动它会很好。
有没有办法每天左右重新启动 Azure 经典云服务工作者角色?以编程方式还是通过配置?
【问题讨论】:
标签: azure-cloud-services azure-worker-roles
我正在使用具有多个角色进程的 Azure 云服务(经典)。其中一个是一周后变得有点不稳定的工人,所以我想每隔几天重新启动一次。最终,worker 角色将变得稳定,但与此同时,如果可能的话,每隔几天自动重新启动它会很好。
有没有办法每天左右重新启动 Azure 经典云服务工作者角色?以编程方式还是通过配置?
【问题讨论】:
标签: azure-cloud-services azure-worker-roles
绝对是的,有两种方法可以通过按时间间隔以编程方式触发来重新启动 Azure 经典云服务角色实例。
【讨论】:
我在 Azure 论坛和 Reddit 上问过这个问题。
第一个回复是Azure Forum, Marcin said:
您可以将 Azure 自动化用于此目的
https://docs.microsoft.com/en-us/azure/cloud-services/automation-manage-cloud-services
https://gallery.technet.microsoft.com/scriptcenter/Reboot-Cloud-Service-PaaS-b337a06d
您可以使用 PowerShell 工作流运行手册来做到这一点:
workflow ResetRoleClassic
{
Param
(
[Parameter (Mandatory = $true)]
[string]$serviceName,
[Parameter (Mandatory = $true)]
[string]$slot,
[Parameter (Mandatory = $true)]
[string]$instanceName
)
$ConnectionAssetName = "AzureClassicRunAsConnection"
# Get the connection
$connection = Get-AutomationConnection -Name $connectionAssetName
# Authenticate to Azure with certificate
Write-Verbose "Get connection asset: $ConnectionAssetName" -Verbose
$Conn = Get-AutomationConnection -Name $ConnectionAssetName
if ($Conn -eq $null)
{
throw "Could not retrieve connection asset: $ConnectionAssetName. Assure that this asset exists in the Automation account."
}
$CertificateAssetName = $Conn.CertificateAssetName
Write-Verbose "Getting the certificate: $CertificateAssetName" -Verbose
$AzureCert = Get-AutomationCertificate -Name $CertificateAssetName
if ($AzureCert -eq $null)
{
throw "Could not retrieve certificate asset: $CertificateAssetName. Assure that this asset exists in the Automation account."
}
Write-Verbose "Authenticating to Azure with certificate." -Verbose
Set-AzureSubscription -SubscriptionName $Conn.SubscriptionName -SubscriptionId $Conn.SubscriptionID -Certificate $AzureCert
Select-AzureSubscription -SubscriptionId $Conn.SubscriptionID
Write-Verbose "Getting $serviceName Role." -Verbose
$results = Get-AzureRole -ServiceName $serviceName -InstanceDetails
Write-Output $results
Write-Verbose "Resetting Role Instance $instanceName" -Verbose
$results = Reset-AzureRoleInstance -ServiceName $serviceName -Slot $slot -InstanceName $instanceName -Reboot
Write-Output $results
}
我对参数做了一些小改动,并移除了外大括号。因此能够在大部分情况下按原样使用脚本。
【讨论】: