huge rewrite

This commit is contained in:
2026-10-29 22:19:03 -07:00
parent 25358e9c17
commit e738ea158b
29 changed files with 2237 additions and 2060 deletions

View File

@@ -93,25 +93,6 @@ class ServiceManager {
child.stderr.on('data', (data) => {
const text = data.toString().trim();
this.logToFile(name, `STDERR: ${text}`);
if (text.includes('EADDRINUSE')) {
const match = text.match(/:(\d+)/);
const port = match ? match[1] : null;
if (port) {
try {
if (process.platform === 'win32') {
require('child_process').spawnSync('powershell.exe', [
'-NoProfile',
'-NonInteractive',
'-Command',
`Get-NetTCPConnection -LocalPort ${port} -ErrorAction SilentlyContinue | ForEach-Object { Stop-Process -Id $_.OwningProcess -Force }`
], { stdio: 'ignore', windowsHide: true });
} else {
require('child_process').spawnSync('fuser', ['-k', '-9', `${port}/tcp`], { stdio: 'ignore' });
}
} catch (_) { }
}
}
});
child.on('exit', (code, signal) => {
@@ -144,7 +125,7 @@ class ServiceManager {
));
}
async stopAll() {
stopAll() {
this.isStopping = true;
for (const name of Object.keys(this.stableTimers)) {
if (this.stableTimers[name]) {
@@ -152,20 +133,14 @@ class ServiceManager {
}
}
this.stableTimers = {};
const killPromises = Object.keys(this.processes).map((name) => {
for (const name of Object.keys(this.processes)) {
const procInfo = this.processes[name];
if (procInfo && procInfo.child) {
this.logToFile(name, `Killing service`);
return new Promise((resolve) => {
procInfo.child.removeAllListeners('exit');
procInfo.child.on('exit', () => resolve());
procInfo.child.kill();
});
try {
procInfo.child.kill('SIGTERM');
} catch (e) { }
}
return Promise.resolve();
});
await Promise.all(killPromises);
}
this.processes = {};
}
@@ -203,4 +178,4 @@ class ServiceManager {
}
}
module.exports = ServiceManager;
module.exports = ServiceManager;