我正在使用具有几个角色流程的Azure云服务(经典)。其中一个是一个工人,一个星期后变得有点不稳定,所以我想每隔几天重新启动一次。最终,将使角色稳定,但同时,如果可能的话,最好每隔几天自动重新启动它。
是否存在每天大约重新启动一次Azure经典云服务工作者角色的方法?通过编程还是通过配置?
答案 0 :(得分:1)
完全可以,有两种方法可以通过间隔触发以编程方式重新启动Azure经典Cloud Service角色实例。
答案 1 :(得分:0)
我在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
}
我对参数做了一些小的更改,并移除了外部括号。因此,大部分情况下都可以使用该脚本。