Skip to content

Commit cbb9929

Browse files
v-weimin@handshakes.com.sgv-weimin@handshakes.com.sg
authored andcommitted
优化 SQL Server 停止步骤,增加超时时间设置,确保内存释放更可靠
1 parent c64ae97 commit cbb9929

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

.github/workflows/deploy-to-iis-local.yml

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,27 @@ jobs:
7171
NODE_OPTIONS: --max-old-space-size=1024 # 限制为 1GB,避免占用过多内存
7272

7373
steps:
74-
# 临时停止 SQL Server 释放内存
74+
# 临时停止 SQL Server 释放内存(可选)
7575
- name: 停止 SQL Server(释放内存)
7676
shell: powershell
77+
continue-on-error: true # 即使失败也继续执行
7778
run: |
7879
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
7980
Write-Host "Stopping SQL Server to free memory..."
80-
Stop-Service -Name "MSSQLSERVER" -Force -ErrorAction SilentlyContinue
81-
Stop-Service -Name "SQLSERVERAGENT" -Force -ErrorAction SilentlyContinue
82-
Start-Sleep -Seconds 5
81+
82+
# 增加超时时间到 60 秒
83+
$service = Get-Service -Name "MSSQLSERVER" -ErrorAction SilentlyContinue
84+
if ($service -and $service.Status -eq 'Running') {
85+
$service.Stop()
86+
$service.WaitForStatus('Stopped', '00:01:00') # 等待最多 60 秒
87+
}
88+
89+
$agentService = Get-Service -Name "SQLSERVERAGENT" -ErrorAction SilentlyContinue
90+
if ($agentService -and $agentService.Status -eq 'Running') {
91+
$agentService.Stop()
92+
$agentService.WaitForStatus('Stopped', '00:00:30') # 等待最多 30 秒
93+
}
94+
8395
Write-Host "SQL Server stopped successfully"
8496
8597
# 下载构建产物(比完整代码库小很多)

0 commit comments

Comments
 (0)