Check if the agents service is running before starting it

This commit is contained in:
Sander Declerck 2026-01-19 14:23:15 +01:00
parent 3958fcfcef
commit 2784dfd34e
No known key found for this signature in database

View file

@ -146,6 +146,19 @@ function stopServiceIfRunning() {
}
function startService() {
try {
// Check if service is already running
ui.writeVerbose('Checking service status: sc query "SafeChainAgent"');
const status = execSync('sc query "SafeChainAgent"', { encoding: "utf8" });
if (status.includes("RUNNING")) {
ui.writeVerbose("SafeChain Agent service is already running.");
return;
}
} catch {
// Service might not exist yet or query failed, proceed with start
}
ui.writeVerbose('Running: net start "SafeChainAgent"');
execSync('net start "SafeChainAgent"', { stdio: "inherit" });
}