【问题标题】:Is there anyway to restart an Azure classic cloud service role every interval?是否有每隔一段时间重新启动一个 Azure 经典云服务角色?
【发布时间】:2018-12-17 21:36:11
【问题描述】:

我正在使用具有多个角色进程的 Azure 云服务(经典)。其中一个是一周后变得有点不稳定的工人,所以我想每隔几天重新启动一次。最终,worker 角色将变得稳定,但与此同时,如果可能的话,每隔几天自动重新启动它会很好。

有没有办法每天左右重新启动 Azure 经典云服务工作者角色?以编程方式还是通过配置?

【问题讨论】:

    标签: azure-cloud-services azure-worker-roles


    【解决方案1】:

    绝对是的,有两种方法可以通过按时间间隔以编程方式触发来重新启动 Azure 经典云服务角色实例。

    1. 在编程中使用 crontab 触发器调用 REST API Reboot Role Instance
    2. 您可以通过在编程中调用REST APIVirtual Machines - Restart来重新启动角色的这些虚拟机,或者直接使用Azure SDK的相同功能API进行编程语言。

    【讨论】:

    • +1 我也在微软论坛上发布了这个问题,有人提到自动化可以用来做这个。
    【解决方案2】:

    我在 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

    然后Reddit, quentech said:

    您可以使用 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
    }
    

    我对参数做了一些小改动,并移除了外大括号。因此能够在大部分情况下按原样使用脚本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-23
      • 1970-01-01
      • 2023-03-29
      • 2021-07-05
      • 1970-01-01
      • 2014-11-05
      • 1970-01-01
      • 2014-03-18
      相关资源
      最近更新 更多