修改消息后台的启动和停止文件并整理文档

This commit is contained in:
not-like-juvenile
2026-03-11 16:42:33 +08:00
parent e67016a6f4
commit 9cc6dcc2a6
19 changed files with 327 additions and 375 deletions

View File

@@ -54,6 +54,7 @@ foreach ($s in $services) {
Ensure-Dir (Join-Path $root 'server\.runtime')
$pidsFile = Join-Path $root 'server\.runtime\delivery-backend.pids.json'
$pids | ConvertTo-Json -Depth 5 | Set-Content -Path $pidsFile -Encoding UTF8
$json = $pids | ConvertTo-Json -Depth 5
[IO.File]::WriteAllText($pidsFile, $json + "`r`n", (New-Object System.Text.UTF8Encoding($false)))
Write-Host "Saved pids: $pidsFile"
Write-Host "Done. Use test sender: node .\pages\mall\delivery\webhook-server\test-send.js"

View File

@@ -1,27 +1,60 @@
$ErrorActionPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
function Stop-ListeningPort($port) {
try {
$lines = netstat -ano | Select-String (":$port ")
foreach ($l in $lines) {
$m = [regex]::Match($l.ToString(), "\sLISTENING\s+(\d+)$")
if ($m.Success) {
$procId = [int]$m.Groups[1].Value
try {
Stop-Process -Id $procId -Force -ErrorAction Stop
Write-Host "Stopped PID $procId on port $port"
} catch {
Write-Host "Failed to stop PID $procId on port ${port}: $($_.Exception.Message)"
}
}
}
} catch {
Write-Host "Failed to inspect port ${port}: $($_.Exception.Message)"
}
}
$root = Resolve-Path (Join-Path $PSScriptRoot "..\..")
$pidsFile = Join-Path $root 'server\.runtime\delivery-backend.pids.json'
if (Test-Path $pidsFile) {
try {
$pids = Get-Content $pidsFile -Raw | ConvertFrom-Json
foreach ($name in $pids.PSObject.Properties.Name) {
$pid = [int]$pids.$name
if ($pid -gt 0) {
# Windows PowerShell 5.1 + Set-Content -Encoding UTF8 often writes BOM; trim it before JSON parse.
$raw = Get-Content -Path $pidsFile -Raw -Encoding UTF8
if ($raw.Length -gt 0 -and $raw[0] -eq [char]0xFEFF) { $raw = $raw.Substring(1) }
$pids = $raw | ConvertFrom-Json
foreach ($prop in $pids.PSObject.Properties) {
$name = $prop.Name
$procPid = [int]$prop.Value
if ($procPid -gt 0) {
try {
Stop-Process -Id $pid -Force
Write-Host "Stopped $name PID=$pid"
Stop-Process -Id $procPid -Force -ErrorAction Stop
Write-Host "Stopped $name PID=$procPid"
} catch {
Write-Host "Failed to stop $name PID=$pid"
Write-Host "Failed to stop $name PID=${procPid}: $($_.Exception.Message)"
}
}
}
try {
Remove-Item -Path $pidsFile -Force -ErrorAction Stop
Write-Host "Removed pid file: $pidsFile"
} catch {
Write-Host "Failed to remove pid file: $($_.Exception.Message)"
}
} catch {
Write-Host "Failed to parse $pidsFile"
Write-Host "Failed to parse ${pidsFile}: $($_.Exception.Message)"
}
} else {
Write-Host "No pid file found: $pidsFile"
}
Write-Host "If ports still occupied, run: netstat -ano | Select-String ':7201 ' / ':7301 '"
# Fallback: ensure ports are freed even if pid file is missing/invalid.
Stop-ListeningPort 7201
Stop-ListeningPort 7301