【问题标题】:How programatically restart a Azure VM role (PaaS VM)如何以编程方式重新启动 Azure VM 角色 (PaaS VM)
【发布时间】:2014-12-03 16:43:02
【问题描述】:

我有一个需要使用 Azure 管理库重新启动的 PaaS VM 角色。我尝试了以下代码,但由于“BadRequest:MyPaaSVmName 类型的角色不支持该操作”而失败。但是我使用下面的 Method1 成功地重新启动了 IaaS VM。 是否可以使用 Azure 管理库重新启动 PaaS VM 角色? 如果没有,有没有其他方法可以使用c#实现它。

1.

ComputeManagementClient client = new ComputeManagementClient(cloudCredentials);
client.VirtualMachines.Restart(hostedServiceName, deploymentName, vmName);

2.

ComputeManagementClient client = new ComputeManagementClient(cloudCredentials);
VirtualMachineOperationsExtensions.Restart(client.VirtualMachines, hostserviceName, deploymentName, vmName);

谢谢。

【问题讨论】:

    标签: azure azure-web-roles azure-management azure-management-api


    【解决方案1】:

    发现问题, Method1 应该是这样的,因为我正在重新启动角色实例。方法2错了。

    client.Deployments.RebootRoleInstanceByDeploymentName(hostserviceName, deploymentName, roleName);
    

    【讨论】:

      【解决方案2】:

      以下是使用 Azure Powershell 的方法:

      ReSet-AzureRoleInstance -ServiceName "MySvc1" -Slot Staging -InstanceName "MyWebRole_IN_0" –reboot

      https://msdn.microsoft.com/en-us/library/azure/dn495202.aspx

      这是来自 Azure 自动化运行手册的一个 sn-p,它可以重新启动每个更新域的所有云服务实例(因此您没有停机时间):

      https://gallery.technet.microsoft.com/Reboot-Cloud-Service-PaaS-b337a06d

      $roleInstances = Get-AzureRole -ServiceName $cloudServiceName -Slot Production -InstanceDetails
      Write-Output "Retrieved all role instances for cloud service: $cloudServiceName. Number of instances: " + $roleInstances.Count
      
      # Group instances per update domain
      $roleInstanceGroups = $roleInstances | Group-Object -AsHashTable -AsString -Property InstanceUpgradeDomain
      Write-Output "Number of update domains found: " + $roleInstanceGroups.Keys.Count
      
      # Visit each update domain
      foreach ($key in $roleInstanceGroups.Keys)
      {
          $count = $perDomainInstances.Count;
          Write-Output "Rebooting $count instances in domain $key"    
      
          $perDomainInstances = $roleInstanceGroups.Get_Item($key)
      
          foreach -parallel($instance in $perDomainInstances)
          {
              $instanceName = $instance.InstanceName
              Write-Output "Rebooting instance $instanceName"
      
              Reset-AzureRoleInstance -ServiceName $cloudServiceName -Slot Production -InstanceName $instanceName -Reboot -ErrorAction Stop
          } 
      }
      

      【讨论】:

      • 始终欢迎提供指向潜在解决方案的链接,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及它存在的原因。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-23
      • 2021-08-19
      相关资源
      最近更新 更多