1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00

Add SIGTERM handler

This commit is contained in:
rickkwa 2023-05-21 02:25:27 -04:00
parent 2aea6f4456
commit a4898bc197

View File

@ -131,6 +131,15 @@ export class Server {
this.server.listen(Config.Server.port, Config.Server.host);
this.server.on('error', this.onError);
this.server.on('listening', this.onListening);
this.server.on('close', this.onClose);
// Sigterm handler
process.on('SIGTERM', () => {
Logger.info(LOG_TAG, 'SIGTERM signal received');
this.server.close(() => {
process.exit(0);
});
});
this.onStarted.trigger();
}
@ -170,6 +179,13 @@ export class Server {
typeof addr === 'string' ? 'pipe ' + addr : 'port ' + addr.port;
Logger.info(LOG_TAG, 'Listening on ' + bind);
};
/**
* Event listener for HTTP server "close" event.
*/
private onClose = () => {
Logger.info(LOG_TAG, 'Closed http server');
};
}