pm2/examples/beforeExit.js
2015-11-24 14:10:11 +01:00

26 lines
459 B
JavaScript

'use strict';
let stopped = false;
function work() {
console.log('working');
!stopped && setTimeout(work, 200);
}
function stop() {
stopped = true;
console.log('shutting down', stopped);
}
process.once('SIGINT', function() {
console.log('SIGINT');
stop();
}); // CTRL-C
process.once('SIGTERM', function() {
console.log('SIGTERM');
stop();
}); // pm2 stop
process.on('beforeExit', () => console.log('exited cleanly :)'));
work();