Start and stop safe-chain agent's Windows service.

This commit is contained in:
Sander Declerck 2026-01-19 13:28:16 +01:00
parent 879b37e164
commit 2c0245b020
No known key found for this signature in database

View file

@ -38,13 +38,18 @@ async function installOnWindows() {
ui.writeVerbose(`Destination: ${msiPath}`);
await downloadFile(downloadUrl, msiPath);
stopServiceIfRunning();
ui.writeInformation("Installing SafeChain Agent...");
ui.writeVerbose(`Running: msiexec /i "${msiPath}" /qn`);
runMsiInstaller(msiPath);
ui.writeInformation("Starting SafeChain Agent service...");
startService();
ui.writeVerbose(`Cleaning up temporary file: ${msiPath}`);
cleanup(msiPath);
ui.writeInformation("SafeChain Agent installed successfully!");
ui.writeInformation("SafeChain Agent installed and started successfully!");
}
function isRunningAsAdmin() {
@ -89,6 +94,22 @@ function runMsiInstaller(msiPath) {
execSync(`msiexec /i "${msiPath}" /qn`, { stdio: "inherit" });
}
function stopServiceIfRunning() {
try {
ui.writeInformation("Stopping existing SafeChain Agent service...");
ui.writeVerbose('Running: net stop "SafeChainAgent"');
execSync('net stop "SafeChainAgent"', { stdio: "inherit" });
} catch {
// Service is not running or doesn't exist, which is fine
ui.writeVerbose("SafeChain Agent service not running or not installed.");
}
}
function startService() {
ui.writeVerbose('Running: net start "SafeChainAgent"');
execSync('net start "SafeChainAgent"', { stdio: "inherit" });
}
/**
* @param {string} msiPath
*/