From 913be7d3ce811aba57aac303b2d088a5d6aa8157 Mon Sep 17 00:00:00 2001 From: chenxi Date: Mon, 28 Sep 2026 10:47:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E7=94=A8=E5=8F=91=E5=B8=83=20SSH=20?= =?UTF-8?q?=E8=BF=9E=E6=8E=A5=E9=81=BF=E5=85=8D=E6=9C=8D=E5=8A=A1=E5=99=A8?= =?UTF-8?q?=E9=99=90=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/deploy-from-workstation.ps1 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/scripts/deploy-from-workstation.ps1 b/scripts/deploy-from-workstation.ps1 index 2021b1d3..a21b060e 100644 --- a/scripts/deploy-from-workstation.ps1 +++ b/scripts/deploy-from-workstation.ps1 @@ -32,6 +32,7 @@ $authSession = $null $sshOptions = @() $scpOptions = @() if ($IsMacOS) { $scpOptions += '-O' } +$sshControlPath = if ($IsMacOS) { "/tmp/caiwu-ssh-$PID-$([Guid]::NewGuid().ToString('N')).sock" } else { $null } $sshTarget = "${SshUser}@${Server}" $imageName = 'caiwu_akaunting' $targetPlatform = 'linux/amd64' @@ -344,8 +345,10 @@ try { $authSession = Start-CaiwuDeploymentAuth -Server $Server -SshUser $SshUser -KeyPath $KeyPath -Password $Password -UpdatePassword:$UpdatePassword $sshOptions = $authSession.Options - & ssh @sshOptions $sshTarget true - if ($LASTEXITCODE -ne 0) { throw '服务器登录失败或已取消,已停止部署。若密码已变更,由 Codex 使用 -UpdatePassword 重新打开本机密码窗口。' } + if ($sshControlPath) { + $sshOptions += @('-o', 'ControlMaster=auto', '-o', 'ControlPersist=600', '-o', "ControlPath=$sshControlPath") + } + Invoke-NativeWithRetry { ssh @sshOptions $sshTarget true } '服务器登录失败或已取消,已停止部署。' -Attempts 3 if ($authSession.Directory) { $env:CAIWU_DEPLOY_PASSWORD_UPDATE = $null } $remoteArchive = "$RemotePath/image-$imageTag.tar.gz" @@ -608,6 +611,10 @@ finally { ssh @sshOptions -o ConnectTimeout=5 $sshTarget "rm -f '$bootstrapRemote'" 2>$null | Out-Null } + if ($sshControlPath) { + ssh @sshOptions -O exit $sshTarget 2>$null | Out-Null + } + # Keep the compiled PHP base and Composer vendor layers between releases. # The production build cache is normally about 20 GB; pruning it to 3 GB made # every deployment rebuild PHP extensions and download all dependencies again.