Files
2026-01-28 19:12:13 -08:00

81 lines
1.9 KiB
PowerShell

param()
$ErrorActionPreference = "Stop"
$apiPort = 22391
foreach ($arg in $args) {
if ($arg -eq "--testnet" -or $arg -eq "-t") {
$apiPort = 62391
break
}
}
$runPid = $null
$isPidValid = $false
if (Test-Path "run.pid") {
$pidText = (Get-Content -Raw -Path "run.pid").Trim()
if ($pidText -match '^\d+$') {
$runPid = [int]$pidText
$isPidValid = $true
}
}
if (-not $runPid) {
$proc = Get-CimInstance Win32_Process -Filter "Name='java.exe'" -ErrorAction SilentlyContinue |
Where-Object { $_.CommandLine -match "qortal\.jar" } |
Select-Object -First 1
if ($proc) {
$runPid = $proc.ProcessId
$isPidValid = $true
}
}
$apikey = ""
if (Test-Path "apikey.txt") {
$apikey = (Get-Content -Raw -Path "apikey.txt").Trim()
}
$success = $false
if ($apikey) {
Write-Host "Stopping Qortal via API..."
try {
Invoke-WebRequest -Uri "http://localhost:$apiPort/admin/stop?apiKey=$apikey" -UseBasicParsing | Out-Null
$success = $true
} catch {
$success = $false
}
}
if (-not $success -and $runPid) {
Write-Host "Stopping Qortal process $runPid..."
try {
Stop-Process -Id $runPid -ErrorAction Stop
$success = $true
} catch {
$success = $false
}
}
if (-not $success) {
if ($runPid) {
Write-Host "Stop command failed - not running with process id $runPid?"
} else {
Write-Host "Stop command failed - not running?"
}
exit 1
}
Write-Host "Qortal node should be shutting down"
if ($isPidValid -and $runPid) {
Write-Host -NoNewline "Monitoring for Qortal node to end"
while (Get-Process -Id $runPid -ErrorAction SilentlyContinue) {
Write-Host -NoNewline "."
Start-Sleep -Seconds 1
}
Write-Host ""
Write-Host "Qortal ended gracefully"
Remove-Item -Force "run.pid" -ErrorAction SilentlyContinue
}
exit 0