1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/src/lib/util/graceful-shutdown.ts

25 lines
823 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.debug('Registering graceful shutdown');
process.on('SIGINT', unleashCloser('SIGINT'));
process.on('SIGHUP', unleashCloser('SIGHUP'));
process.on('SIGTERM', unleashCloser('SIGTERM'));
}
export default registerGracefulShutdown;