mirror of
https://github.com/tiennm99/ccs.git
synced 2026-10-13 00:14:15 +00:00
fix(config): force shutdown immediately instead of waiting
This commit is contained in:
1 parent
d33fefd133
commit
6d69379ead
1 file changed
+10
-20
+10
-20
@@ -1,18 +1,16 @@
|
|||||||
/**
|
/**
|
||||||
* Graceful Shutdown Handler
|
* Shutdown Handler
|
||||||
*
|
*
|
||||||
* Handles SIGINT/SIGTERM signals to gracefully close WebSocket connections
|
* Handles SIGINT/SIGTERM signals to close server and exit immediately.
|
||||||
* and HTTP server before process exit.
|
* No graceful waiting - config dashboard doesn't need it.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Server as HTTPServer } from 'http';
|
import { Server as HTTPServer } from 'http';
|
||||||
import { WebSocketServer } from 'ws';
|
import { WebSocketServer } from 'ws';
|
||||||
import { ok, info, warn } from '../utils/ui';
|
import { ok } from '../utils/ui';
|
||||||
|
|
||||||
const SHUTDOWN_TIMEOUT = 10_000; // 10 seconds
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Setup graceful shutdown handlers for SIGINT and SIGTERM
|
* Setup shutdown handlers for SIGINT and SIGTERM
|
||||||
*/
|
*/
|
||||||
export function setupGracefulShutdown(
|
export function setupGracefulShutdown(
|
||||||
server: HTTPServer,
|
server: HTTPServer,
|
||||||
@@ -20,24 +18,16 @@ export function setupGracefulShutdown(
|
|||||||
cleanup?: () => void
|
cleanup?: () => void
|
||||||
): void {
|
): void {
|
||||||
const shutdown = () => {
|
const shutdown = () => {
|
||||||
console.log('\n' + info('Shutting down gracefully...'));
|
console.log('\n' + ok('Shutting down...'));
|
||||||
|
|
||||||
// Run cleanup first (closes file watchers + WebSocket clients)
|
// Run cleanup (closes file watchers + WebSocket clients)
|
||||||
if (cleanup) {
|
if (cleanup) {
|
||||||
cleanup();
|
cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close HTTP server
|
// Close server and exit immediately
|
||||||
server.close(() => {
|
server.close();
|
||||||
console.log(ok('Server closed'));
|
process.exit(0);
|
||||||
process.exit(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Force shutdown if graceful shutdown takes too long
|
|
||||||
setTimeout(() => {
|
|
||||||
console.log(warn('Force shutdown (timeout exceeded)'));
|
|
||||||
process.exit(1);
|
|
||||||
}, SHUTDOWN_TIMEOUT);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
process.on('SIGINT', shutdown);
|
process.on('SIGINT', shutdown);
|
||||||
|
|||||||
Reference in new issue
Block a user