diff options
Diffstat (limited to 'packages/meshbay-client/build/stop-node.ps1')
| -rw-r--r-- | packages/meshbay-client/build/stop-node.ps1 | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/packages/meshbay-client/build/stop-node.ps1 b/packages/meshbay-client/build/stop-node.ps1 index cfaf2f8..dcb0ea6 100644 --- a/packages/meshbay-client/build/stop-node.ps1 +++ b/packages/meshbay-client/build/stop-node.ps1 @@ -10,9 +10,34 @@ # 2. Task Scheduler for a background-service node (the owner may end the task; # taskkill from here gets "Access is denied" in its session). # 3. taskkill for anything left in this session. -# Exit 0 once no meshbay-node.exe is left, 1 otherwise. +# +# Before all that, the command-line client (-InstallDir, setup's $INSTDIR): it +# runs from the same node-runtime folder and holds its Python DLLs, so one left +# open -- a `chat --follow`, a `stream` -- made the previous version's +# uninstaller fail ("Failed to uninstall old application files"), silent +# updates included. It is ended like the app is; only copies of this install. +# Exit 0 once neither is left, 1 otherwise. +param([string]$InstallDir = "") $ErrorActionPreference = "SilentlyContinue" +if ($InstallDir) { + $runtime = Join-Path $InstallDir "resources\node-runtime\" + # Through CIM, not Get-Process: setup runs the 32-bit PowerShell ($SYSDIR is + # SysWOW64 there), which reads no path for a 64-bit process -- the filter + # matched nothing and the update failed as before. + function CliLeft { + @(Get-CimInstance Win32_Process -Filter "Name='meshbay-cli.exe'" ` + -ErrorAction SilentlyContinue | Where-Object { + $_.ExecutablePath -and + $_.ExecutablePath.StartsWith($runtime, [StringComparison]::OrdinalIgnoreCase) + }) + } + CliLeft | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue } + $deadline = (Get-Date).AddSeconds(10) + while ((CliLeft).Count -and (Get-Date) -lt $deadline) { Start-Sleep -Milliseconds 250 } + if ((CliLeft).Count) { exit 1 } +} + function NodeLeft { [bool](Get-Process -Name meshbay-node -ErrorAction SilentlyContinue) } function WaitGone([int]$Seconds) { $deadline = (Get-Date).AddSeconds($Seconds) |