我使用以下代码将新部署的应用程序从暂存槽交换到生产槽(交换 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/