@geekbeer/minion 2.68.0 → 2.68.2
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/lib/process-manager.js +3 -3
- package/win/routes/commands.js +18 -3
package/package.json
CHANGED
|
@@ -213,8 +213,8 @@ function buildAllowedCommands(procMgr, agentConfig = {}) {
|
|
|
213
213
|
const pidFile = path.join(dataDir, 'minion-agent.pid')
|
|
214
214
|
const startScript = path.join(dataDir, 'start-agent.ps1')
|
|
215
215
|
|
|
216
|
-
const stopBlock = `$
|
|
217
|
-
const startBlock = `Start-Process powershell -ArgumentList '-ExecutionPolicy Bypass -WindowStyle Hidden -File
|
|
216
|
+
const stopBlock = `$agentPid = Get-Content '${pidFile}' -ErrorAction SilentlyContinue; if ($agentPid) { Get-CimInstance Win32_Process -Filter ('ParentProcessId = ' + $agentPid) -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }; Stop-Process -Id $agentPid -Force -ErrorAction SilentlyContinue }`
|
|
217
|
+
const startBlock = `Start-Process powershell -ArgumentList ('-ExecutionPolicy Bypass -WindowStyle Hidden -File \"' + '${startScript}' + '\"') -WindowStyle Hidden`
|
|
218
218
|
|
|
219
219
|
commands['restart-agent'] = {
|
|
220
220
|
description: 'Restart the minion agent process',
|
|
@@ -248,7 +248,7 @@ function buildAllowedCommands(procMgr, agentConfig = {}) {
|
|
|
248
248
|
}
|
|
249
249
|
commands['status-services'] = {
|
|
250
250
|
description: 'Show agent process info',
|
|
251
|
-
command: `powershell -Command "$pidFile = '${pidFile}'; if (Test-Path $pidFile) { $
|
|
251
|
+
command: `powershell -Command "$pidFile = '${pidFile}'; if (Test-Path $pidFile) { $agentPid = (Get-Content $pidFile -Raw).Trim(); $proc = Get-Process -Id $agentPid -ErrorAction SilentlyContinue; if ($proc) { Write-Host 'minion-agent: running (PID:' $agentPid ')' } else { Write-Host 'minion-agent: not running (stale PID)' } } else { Write-Host 'minion-agent: not running' }"`,
|
|
252
252
|
}
|
|
253
253
|
} else if (procMgr === 'nssm') {
|
|
254
254
|
// NSSM handles graceful stop via its own service control, so no HTTP API needed
|
package/win/routes/commands.js
CHANGED
|
@@ -6,12 +6,20 @@
|
|
|
6
6
|
|
|
7
7
|
const { exec, spawn } = require('child_process')
|
|
8
8
|
const { promisify } = require('util')
|
|
9
|
+
const fs = require('fs')
|
|
10
|
+
const path = require('path')
|
|
11
|
+
const os = require('os')
|
|
9
12
|
const execAsync = promisify(exec)
|
|
10
13
|
|
|
11
14
|
const { verifyToken } = require('../../core/lib/auth')
|
|
12
15
|
const { config } = require('../../core/config')
|
|
13
16
|
const { detectProcessManager, buildAllowedCommands } = require('../lib/process-manager')
|
|
14
17
|
|
|
18
|
+
const SPAWN_LOG = path.join(os.homedir(), '.minion', 'spawn-debug.log')
|
|
19
|
+
function spawnLog(msg) {
|
|
20
|
+
try { fs.appendFileSync(SPAWN_LOG, `${new Date().toISOString()} ${msg}\n`) } catch {}
|
|
21
|
+
}
|
|
22
|
+
|
|
15
23
|
const PROC_MGR = detectProcessManager()
|
|
16
24
|
const ALLOWED_COMMANDS = buildAllowedCommands(PROC_MGR, config)
|
|
17
25
|
|
|
@@ -57,19 +65,26 @@ async function commandRoutes(fastify) {
|
|
|
57
65
|
console.log(`[Command] Scheduling deferred command: ${command}`)
|
|
58
66
|
setTimeout(() => {
|
|
59
67
|
if (allowedCommand.spawnArgs) {
|
|
60
|
-
// Use spawn with detached:true for update scripts.
|
|
61
|
-
// Avoids cmd.exe quoting issues and -WindowStyle Hidden hangs
|
|
62
|
-
// in non-interactive sessions that caused HQ update timeouts.
|
|
63
68
|
const [cmd, args] = allowedCommand.spawnArgs
|
|
69
|
+
spawnLog(`[${command}] spawn: ${cmd} ${JSON.stringify(args)}`)
|
|
64
70
|
try {
|
|
65
71
|
const child = spawn(cmd, args, {
|
|
66
72
|
detached: true,
|
|
67
73
|
stdio: 'ignore',
|
|
68
74
|
windowsHide: true,
|
|
69
75
|
})
|
|
76
|
+
child.on('error', (err) => {
|
|
77
|
+
spawnLog(`[${command}] child error: ${err.message}`)
|
|
78
|
+
console.error(`[Command] Spawn child error: ${command} - ${err.message}`)
|
|
79
|
+
})
|
|
80
|
+
child.on('exit', (code, signal) => {
|
|
81
|
+
spawnLog(`[${command}] child exit: code=${code} signal=${signal}`)
|
|
82
|
+
})
|
|
70
83
|
child.unref()
|
|
84
|
+
spawnLog(`[${command}] spawned pid=${child.pid}`)
|
|
71
85
|
console.log(`[Command] Deferred command spawned: ${command} (pid: ${child.pid})`)
|
|
72
86
|
} catch (err) {
|
|
87
|
+
spawnLog(`[${command}] spawn threw: ${err.message}`)
|
|
73
88
|
console.error(`[Command] Deferred spawn failed: ${command} - ${err.message}`)
|
|
74
89
|
}
|
|
75
90
|
} else {
|