Files
maipulse/maipulse/tools/restart.ps1
T
maipulse 967e93af98 release: v1.0.2
加固:release 构建 + R8 混淆,清理无用资源,修启动链路
2026-10-30 21:35:19 +08:00

46 lines
1.7 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 先登出、再重启 maipulse。
#
# 为什么要专门走这个脚本:直接杀进程会把服务端会话留在 isLogin=True,
# 账号就卡小黑屋(登录回 returnCode=100),而那次 loginId 只在内存里,
# 事后连 UserLogout 都没法发对。
#
# 用法:
# powershell -ExecutionPolicy Bypass -File tools\restart.ps1
param(
[string]$Py = "%USERPROFILE%\AppData\Local\Programs\Python\Python313\python.exe",
[string]$AppDir = "<maipulse>",
[string]$Url = "http://127.0.0.1:8787"
)
$ErrorActionPreference = 'Continue'
# 1) 让服务自己登出再退出
try {
$r = Invoke-RestMethod -Uri "$Url/api/shutdown" -Method Post -TimeoutSec 40 -ContentType 'application/json' -Body '{}'
Write-Host ("shutdown: " + ($r | ConvertTo-Json -Compress))
} catch {
Write-Host "shutdown 调用失败(可能本来就没在跑): $($_.Exception.Message)"
}
# 2) 等端口释放
for ($i = 0; $i -lt 20; $i++) {
Start-Sleep -Milliseconds 500
$c = Get-NetTCPConnection -LocalPort 8787 -State Listen -ErrorAction SilentlyContinue
if (-not $c) { break }
if ($i -eq 19) {
$c | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force -ErrorAction SilentlyContinue }
Write-Host "警告:端口被强占,已强杀(这次可能留下会话,注意检查 isLogin)"
}
}
# 3) 重新拉起(Start-Process 不随本脚本退出)
$env:PYTHONIOENCODING = 'utf-8'
Start-Process -FilePath $Py -ArgumentList 'app.py' -WorkingDirectory $AppDir -WindowStyle Hidden
Start-Sleep -Seconds 3
try {
$s = Invoke-RestMethod -Uri "$Url/api/state" -TimeoutSec 8
Write-Host ("restarted: ok=" + $s.ok + " logged=" + $s.logged)
} catch {
Write-Host "启动后检查失败: $($_.Exception.Message)"
}