最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - node.js pm2 on exit - Stack Overflow

programmeradmin0浏览0评论

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 badges
Add a ment  | 

1 Answer 1

Reset to default 8

SIGINT 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
});
发布评论

评论列表(0)

  1. 暂无评论