powershell - 在交换暂存/生产槽(交换 VIP)之前等待新部署完全初始化?

标签 powershell azure

我使用以下代码将新部署的应用程序从暂存槽交换到生产槽(交换 VIP):

Get-HostedService -serviceName $serviceName -subscriptionId $subcription -certificate $certificate | Get-Deployment -slot staging | Move-Deployment |Get-OperationStatus –WaitToComplete

我认为 -WaitToComplete 标志将确保所有虚拟机在执行交换之前已完全初始化,但事实并非如此,并且它执行交换,此时生产槽中新部署的应用程序仍在初始化并且不可用于完全初始化时大约需要 5/10 分钟。

在执行交换 VIP 操作之前确保应用程序完全初始化的最佳方法是什么?

最佳答案

此 PowerShell 代码段将等待每个实例准备就绪(基于 @astaykov 给出的答案)。

它查询暂存槽中正在运行的实例的状态,只有当所有实例都显示为“就绪”时,它才会离开循环。

$hostedService = "YOUR_SERVICE_NAME"

do {
    # query the status of the running instances
    $list = (Get-AzureRole -ServiceName $hostedService `
                           -Slot Staging `
                           -InstanceDetails).InstanceStatus 

    # total number of instances
    $total = $list.Length

    # count the number of ready instances
    $ready = ($list | Where-Object { $_ -eq "ReadyRole" }).Length

    Write-Host "$ready out of $total are ready"

    $notReady = ($ready -ne $total)
    If ($notReady) {
        Start-Sleep -s 10
    }
}
while ($notReady)

关于powershell - 在交换暂存/生产槽(交换 VIP)之前等待新部署完全初始化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9333182/

相关文章:

powershell 'system.windows.media.mediaplayer' 注册对象事件

json - powershell 解析 Json 文件,其中键名包含\和通配符

azure - 前门无法访问KV证书

azure - 在 adf 逻辑应用中使用有效负载运行时,逻辑应用抛出扩展的 ajax 错误

azure - 使用在 Windows Server 2003 上运行的 .net Framework 2.0 创建的 Web 应用程序可以迁移到 Azure 吗?

powershell - 如何将 ASCII Art 输出到控制台?

.net - Select-String如何读取文本文件内容?大块?

powershell - 如何在 PowerShell 中退出 ForEach-Object

java - 有没有办法使用 Java 从 Azure AD 恢复最近删除的用户?

数据库防火墙设置后,AZURE SQL DB 漏洞评估标记为高风险