feat(01-05): implement graceful shutdown with signal handlers

- GracefulShutdown class handles SIGTERM, SIGINT, SIGHUP
- 10-second timeout before force exit
- Double SIGINT forces immediate exit
- Shutdown sequence: stop HTTP server, stop processes, cleanup
- Integrates with CoordinationServer and ProcessManager
This commit is contained in:
Lukas May
2026-01-30 13:23:58 +01:00
parent bec46aa234
commit 59b233792a
2 changed files with 129 additions and 11 deletions

View File

@@ -8,6 +8,7 @@
import { Command } from 'commander';
import { VERSION } from '../index.js';
import { CoordinationServer } from '../server/index.js';
import { GracefulShutdown } from '../server/shutdown.js';
import { ProcessManager, ProcessRegistry } from '../process/index.js';
import { LogManager } from '../logging/index.js';
@@ -42,17 +43,9 @@ async function startServer(port?: number): Promise<void> {
process.exit(1);
}
// Import shutdown handler (will be implemented in Task 2)
// For now, just handle basic signals
const handleSignal = async (signal: string) => {
console.log(`\nReceived ${signal}, shutting down...`);
await server.stop();
await processManager.stopAll();
process.exit(0);
};
process.on('SIGTERM', () => handleSignal('SIGTERM'));
process.on('SIGINT', () => handleSignal('SIGINT'));
// Install graceful shutdown handlers
const shutdown = new GracefulShutdown(server, processManager, logManager);
shutdown.install();
}
/**