javascript - node.js pm2 on exit - Stack Overflow

I'm using pm2 to running node application. I must save data before application will be closed. Thi

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
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745038940a4607692.html

相关推荐

  • javascript - node.js pm2 on exit - Stack Overflow

    I'm using pm2 to running node application. I must save data before application will be closed. Thi

    9小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信