@myassis/gateway 1.0.69 → 1.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -746,12 +746,19 @@ async function updateService() {
746
746
  `$tmpExe = '${escapePowerShellString(tmpExe)}'`,
747
747
  `$backupExe = '${escapePowerShellString(`${currentExe}.bak`)}'`,
748
748
  `$pidFile = '${escapePowerShellString(GATEWAY_PID_FILE)}'`,
749
+ `$daemonPidFile = '${escapePowerShellString(GATEWAY_DAEMON_PID_FILE)}'`,
750
+ `$stopFlag = '${escapePowerShellString(GATEWAY_STOP_FLAG_FILE)}'`,
749
751
  `$launcher = '${escapePowerShellString(GATEWAY_LAUNCHER_FILE)}'`,
750
752
  `$logPath = Join-Path $env:TEMP 'myassis-gateway-update.log'`,
751
753
  `$logDir = Split-Path -Parent $logPath`,
752
754
  `if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }`,
753
755
  `function Write-UpdateLog { param([string]$Message) Add-Content -Path $logPath -Encoding UTF8 -Value \"$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') $Message\" }`,
754
756
  `function Stop-GatewayProcess {`,
757
+ ` # 先写停止标记,告诉守护进程这是主动停止,不要自动重启`,
758
+ ` try {`,
759
+ ` New-Item -ItemType File -Path $stopFlag -Force | Out-Null`,
760
+ ` Write-UpdateLog 'stop flag written'`,
761
+ ` } catch { Write-UpdateLog \"write stop flag failed: $($_.Exception.Message)\" }`,
755
762
  ` $stoppedPids = @{}`,
756
763
  ` if (Test-Path $pidFile) {`,
757
764
  ` try {`,
@@ -786,6 +793,33 @@ async function updateService() {
786
793
  ` Start-Sleep -Milliseconds 500`,
787
794
  ` }`,
788
795
  ` }`,
796
+ ` # 等待守护进程退出:gateway 退出后,守护检测到 stop-flag 会自行 break 退出`,
797
+ ` $daemonPid = $null`,
798
+ ` if (Test-Path $daemonPidFile) {`,
799
+ ` try {`,
800
+ ` $dpStr = (Get-Content $daemonPidFile -Raw).Trim()`,
801
+ ` if ($dpStr) { $daemonPid = [int]$dpStr }`,
802
+ ` } catch { Write-UpdateLog \"read daemon pid failed: $($_.Exception.Message)\" }`,
803
+ ` }`,
804
+ ` if ($daemonPid) {`,
805
+ ` Write-UpdateLog \"waiting daemon exit pid=$daemonPid\"`,
806
+ ` $daemonGone = $false`,
807
+ ` for ($w = 0; $w -lt 60; $w++) {`,
808
+ ` $dp = Get-Process -Id $daemonPid -ErrorAction SilentlyContinue`,
809
+ ` if (-not $dp) { $daemonGone = $true; break }`,
810
+ ` Start-Sleep -Milliseconds 500`,
811
+ ` }`,
812
+ ` if ($daemonGone) {`,
813
+ ` Write-UpdateLog 'daemon exited gracefully'`,
814
+ ` } else {`,
815
+ ` Write-UpdateLog \"daemon still alive after 30s, force kill pid=$daemonPid\"`,
816
+ ` try { Stop-Process -Id $daemonPid -Force -ErrorAction Stop } catch { Write-UpdateLog \"kill daemon failed: $($_.Exception.Message)\" }`,
817
+ ` Start-Sleep -Milliseconds 1000`,
818
+ ` }`,
819
+ ` Remove-Item $daemonPidFile -Force -ErrorAction SilentlyContinue`,
820
+ ` } else { Write-UpdateLog 'daemon pid file not found, skip daemon wait' }`,
821
+ ` # 清理停止标记,避免影响后续启动`,
822
+ ` Remove-Item $stopFlag -Force -ErrorAction SilentlyContinue`,
789
823
  `}`,
790
824
  `function Start-GatewayProcess {`,
791
825
  ` if (-not (Test-Path $launcher)) { Write-UpdateLog \"launcher script not found: $launcher\"; return }`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@myassis/gateway",
3
- "version": "1.0.69",
3
+ "version": "1.0.70",
4
4
  "description": "我的助手 Gateway Service - 本地 AI 网关服务,支持认证、WebSocket 实时通信和任务调度",
5
5
  "main": "dist/index.js",
6
6
  "bin": {