增强发布 SSH 连接重试 #29
@ -49,6 +49,31 @@ function Invoke-Native {
|
||||
}
|
||||
}
|
||||
|
||||
function Invoke-NativeWithRetry {
|
||||
param(
|
||||
[Parameter(Mandatory = $true)]
|
||||
[scriptblock]$Command,
|
||||
[Parameter(Mandatory = $true)]
|
||||
[string]$FailureMessage,
|
||||
[int]$Attempts = 3,
|
||||
[int]$DelaySeconds = 3
|
||||
)
|
||||
|
||||
for ($attempt = 1; $attempt -le $Attempts; $attempt++) {
|
||||
& $Command
|
||||
if ($LASTEXITCODE -eq 0) {
|
||||
return
|
||||
}
|
||||
|
||||
if ($attempt -lt $Attempts) {
|
||||
Write-Warning "$FailureMessage 正在重试($attempt/$Attempts)。"
|
||||
Start-Sleep -Seconds $DelaySeconds
|
||||
}
|
||||
}
|
||||
|
||||
throw $FailureMessage
|
||||
}
|
||||
|
||||
function Get-PrivateEnvironmentValue {
|
||||
param([Parameter(Mandatory = $true)][string]$Name)
|
||||
|
||||
@ -398,8 +423,8 @@ try {
|
||||
} '服务器激活、健康检查或增量仓库初始化失败。'
|
||||
}
|
||||
else {
|
||||
Invoke-Native {
|
||||
ssh -i $keyFullPath -o BatchMode=yes $sshTarget "chmod 700 '$RemotePath/'*.sh && chmod 644 '$RemotePath/config-db-init.sh' && (curl -fsS -o /dev/null http://127.0.0.1:5000/v2/ || '$RemotePath/setup-incremental-registry.sh' '$RemotePath' '$RemotePath/registry-config.yml')"
|
||||
Invoke-NativeWithRetry {
|
||||
ssh -i $keyFullPath -o BatchMode=yes -o ConnectTimeout=10 -o ConnectionAttempts=1 $sshTarget "chmod 700 '$RemotePath/'*.sh && chmod 644 '$RemotePath/config-db-init.sh' && (curl -fsS -o /dev/null http://127.0.0.1:5000/v2/ || '$RemotePath/setup-incremental-registry.sh' '$RemotePath' '$RemotePath/registry-config.yml')"
|
||||
} '服务器增量镜像仓库初始化失败。'
|
||||
|
||||
# docker save 导出未压缩层,每次导入重新压缩会改变摘要,导致 Registry 无法复用。
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user