@geekbeer/minion 3.59.2 → 3.59.4
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.
- package/package.json +1 -1
- package/win/minion-cli.ps1 +76 -1
package/package.json
CHANGED
package/win/minion-cli.ps1
CHANGED
|
@@ -17,6 +17,7 @@ $ApiToken = ''
|
|
|
17
17
|
$SetupTunnel = $false
|
|
18
18
|
$KeepData = $false
|
|
19
19
|
$Force = $false
|
|
20
|
+
$All = $false
|
|
20
21
|
|
|
21
22
|
$i = 0
|
|
22
23
|
while ($i -lt $args.Count) {
|
|
@@ -30,6 +31,7 @@ while ($i -lt $args.Count) {
|
|
|
30
31
|
'^--setup-tunnel$' { $SetupTunnel = $true }
|
|
31
32
|
'^--keep-data$' { $KeepData = $true }
|
|
32
33
|
'^--force$' { $Force = $true }
|
|
34
|
+
'^--all$' { $All = $true }
|
|
33
35
|
'^(-h|--help)$' { $Command = 'help' }
|
|
34
36
|
}
|
|
35
37
|
$i++
|
|
@@ -555,6 +557,70 @@ function Restart-MinionService {
|
|
|
555
557
|
Start-MinionService
|
|
556
558
|
}
|
|
557
559
|
|
|
560
|
+
function Restart-AllMinionServices {
|
|
561
|
+
# Restart every NSSM-managed minion service plus the user-session logon tasks.
|
|
562
|
+
# Use case: Windows Update or similar reboot left some services (typically
|
|
563
|
+
# cloudflared, which is DEMAND_START) not running. The plain `restart`
|
|
564
|
+
# command only touches minion-agent, so this is the catch-all recovery path.
|
|
565
|
+
$services = @('minion-cloudflared', 'minion-websockify', 'minion-agent')
|
|
566
|
+
|
|
567
|
+
# Step 1: Ask minion-agent to shut down gracefully (sends offline heartbeat).
|
|
568
|
+
# Same pattern as Stop-MinionService — don't wait for exit, sc.exe will finish it.
|
|
569
|
+
$token = ''
|
|
570
|
+
if (Test-Path $EnvFile) {
|
|
571
|
+
$envVars = Read-EnvFile $EnvFile
|
|
572
|
+
if ($envVars['API_TOKEN']) { $token = $envVars['API_TOKEN'] }
|
|
573
|
+
}
|
|
574
|
+
try {
|
|
575
|
+
$headers = @{}
|
|
576
|
+
if ($token) { $headers['Authorization'] = "Bearer $token" }
|
|
577
|
+
Invoke-RestMethod -Uri "$AgentUrl/api/shutdown" -Method POST `
|
|
578
|
+
-ContentType 'application/json' -Headers $headers -TimeoutSec 3 | Out-Null
|
|
579
|
+
} catch {
|
|
580
|
+
# Agent may already be down — sc.exe stop will handle it
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
# Step 2: Stop services (cloudflared first so tunnel teardown doesn't race
|
|
584
|
+
# with agent shutdown, websockify next, agent last).
|
|
585
|
+
foreach ($svc in $services) {
|
|
586
|
+
$state = Get-ServiceState $svc
|
|
587
|
+
if (-not $state) {
|
|
588
|
+
Write-Warn "${svc}: not installed, skipping"
|
|
589
|
+
continue
|
|
590
|
+
}
|
|
591
|
+
if ($state -ne 'STOPPED') {
|
|
592
|
+
Write-Host "Stopping $svc..."
|
|
593
|
+
sc.exe stop $svc 2>&1 | Out-Null
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
# Step 3: Wait for all services to reach STOPPED (up to 15 seconds total).
|
|
598
|
+
for ($i = 0; $i -lt 15; $i++) {
|
|
599
|
+
$stillRunning = $false
|
|
600
|
+
foreach ($svc in $services) {
|
|
601
|
+
$s = Get-ServiceState $svc
|
|
602
|
+
if ($s -and $s -ne 'STOPPED') { $stillRunning = $true; break }
|
|
603
|
+
}
|
|
604
|
+
if (-not $stillRunning) { break }
|
|
605
|
+
Start-Sleep -Seconds 1
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
# Step 4: Start services in reverse order (agent → websockify → cloudflared).
|
|
609
|
+
foreach ($svc in @('minion-agent', 'minion-websockify', 'minion-cloudflared')) {
|
|
610
|
+
$state = Get-ServiceState $svc
|
|
611
|
+
if (-not $state) { continue }
|
|
612
|
+
Write-Host "Starting $svc..."
|
|
613
|
+
sc.exe start $svc 2>&1 | Out-Null
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
# Step 5: Re-trigger user-session logon tasks. schtasks /Run is a no-op if
|
|
617
|
+
# the task is already running, so this is safe regardless of current state.
|
|
618
|
+
schtasks /Run /TN MinionVNC 2>$null | Out-Null
|
|
619
|
+
schtasks /Run /TN MinionWSL 2>$null | Out-Null
|
|
620
|
+
|
|
621
|
+
Write-Host "All minion services restarted"
|
|
622
|
+
}
|
|
623
|
+
|
|
558
624
|
# ============================================================
|
|
559
625
|
# Setup
|
|
560
626
|
# ============================================================
|
|
@@ -1785,7 +1851,9 @@ switch ($Command) {
|
|
|
1785
1851
|
'stop' {
|
|
1786
1852
|
if ($Force) { Stop-MinionServiceForce } else { Stop-MinionService }
|
|
1787
1853
|
}
|
|
1788
|
-
'restart' {
|
|
1854
|
+
'restart' {
|
|
1855
|
+
if ($All) { Restart-AllMinionServices } else { Restart-MinionService }
|
|
1856
|
+
}
|
|
1789
1857
|
'status' { Show-Status }
|
|
1790
1858
|
'health' { Show-Health }
|
|
1791
1859
|
'daemons' { Show-Daemons }
|
|
@@ -1806,6 +1874,7 @@ switch ($Command) {
|
|
|
1806
1874
|
Write-Host " stop Stop the minion-agent service (graceful)"
|
|
1807
1875
|
Write-Host " stop --force Force-stop all minion services & processes (admin required)"
|
|
1808
1876
|
Write-Host " restart Restart the minion-agent service"
|
|
1877
|
+
Write-Host " restart --all Restart all minion services (agent + websockify + cloudflared)"
|
|
1809
1878
|
Write-Host " status Show agent service status"
|
|
1810
1879
|
Write-Host " health Check agent health endpoint"
|
|
1811
1880
|
Write-Host " daemons Show all daemon service status"
|
|
@@ -1827,5 +1896,11 @@ switch ($Command) {
|
|
|
1827
1896
|
Write-Host " kill remaining helpers (tvnserver/websockify/cloudflared)"
|
|
1828
1897
|
Write-Host " and node.exe processes that lock package files."
|
|
1829
1898
|
Write-Host " Use when graceful stop fails (e.g. corrupted update)."
|
|
1899
|
+
Write-Host ""
|
|
1900
|
+
Write-Host "Restart options:"
|
|
1901
|
+
Write-Host " --all Restart minion-agent, minion-websockify, and"
|
|
1902
|
+
Write-Host " minion-cloudflared, then re-trigger MinionVNC/MinionWSL"
|
|
1903
|
+
Write-Host " logon tasks. Use after Windows Update or when only"
|
|
1904
|
+
Write-Host " some services came back online."
|
|
1830
1905
|
}
|
|
1831
1906
|
}
|