1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/src/lib/util/graceful-shutdown.ts

25 lines
822 B
TypeScript
Raw Normal View History

import { Logger } from '../logger';
import { IUnleash } from '../types/core';
function registerGracefulShutdown(unleash: IUnleash, logger: Logger): void {
const unleashCloser = (signal: string) => async () => {
try {
logger.info(`Graceful shutdown signal (${signal}) received.`);
await unleash.stop();
logger.info('Unleash has been successfully stopped.');
process.exit(0);
} catch (e) {
logger.error('Unable to shutdown Unleash. Hard exit!');
process.exit(1);
}
};
logger.info('Registering graceful shutdown');
process.on('SIGINT', unleashCloser('SIGINT'));
process.on('SIGHUP', unleashCloser('SIGHUP'));
process.on('SIGTERM', unleashCloser('SIGTERM'));
}
export default registerGracefulShutdown;