I'm using pm2 to running node application. I must save data before application will be closed. This code works fine in shell:
process.on('exit', function(){
log.debug('exit');
});
process.on('SIGINT', function(){
log.debug('SIGINT');
});
process.on('uncaughtException', function(){
log.debug('uncaughtException');
});
When I'm stopping the application using "pm2 stop" the code doesn't work. I think that pm2 kills process.
I'm using pm2 to running node application. I must save data before application will be closed. This code works fine in shell:
process.on('exit', function(){
log.debug('exit');
});
process.on('SIGINT', function(){
log.debug('SIGINT');
});
process.on('uncaughtException', function(){
log.debug('uncaughtException');
});
When I'm stopping the application using "pm2 stop" the code doesn't work. I think that pm2 kills process.
Share Improve this question asked Oct 2, 2014 at 15:05 SanninSannin 912 silver badges10 bronze badges1 Answer
Reset to default 8SIGINT
is generally triggered after a user-invoked shutdown (e.g. Ctrl+C). Assuming pm2
is triggering an abrupt shutdown then SIGINT
won't be triggered.
Instead, you should listen for the termination signal SIGTERM
which should cover both scenarios
process.on('SIGTERM', function() {
// clean up
});