mirror of
https://gitlab.com/vyla-entertainment/home.git
synced 2026-11-19 16:47:21 -05:00
huge rewrite
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user