pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

cluster cannot exit gracefully in no daemon mode

Open lenew opened this issue 10 years ago • 1 comments

I am trying to deploy pm2 on AWS Elastic BeansTalk using PM2 in no daemon mode. The bootstrap.js code copy from http://pm2.keymetrics.io/docs/usage/use-pm2-with-cloud-providers/ and change pm2.connect(function() { ... to pm2.connect(true, function() {

I have some problem when running this bootstrap.js When hit Ctrl-C, workers may exit before PM2 to kill it. PM2 will try to restart it. this will cause some error. like

my code

var t1 = setInterval(function(){
    console.log("", new Date())
}, 2000)

process.on("SIGINT", function(){
    console.log("=>Exiting...")
    clearInterval(t1);
    setTimeout(function(){ //simulate some clean work
        console.log("=>Fully exit.")
        process.exit(0);
    },500)

});

some error message

^C2016-03-29 10:43:00: Stopping app:my-app id:0
2016-03-29 10:43:00: [App:my-app] =>Exiting...

2016-03-29 10:43:00: [App:my-app] =>Exiting...

2016-03-29 10:43:00: [App:my-app] =>Exiting...

2016-03-29 10:43:00: Stopping app:my-app id:0
2016-03-29 10:43:00: App name:my-app id:0 disconnected
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: Process with pid 73887 still not killed, retrying...
2016-03-29 10:43:00: [App:my-app] =>Fully exit.

2016-03-29 10:43:00: [App:my-app] =>Fully exit.

2016-03-29 10:43:00: App name:my-app id:2 disconnected
2016-03-29 10:43:00: App [my-app] with id [0] and pid [73887], exited with code [0] via signal [SIGINT]
2016-03-29 10:43:00: App name:my-app id:1 disconnected
2016-03-29 10:43:00: App [my-app] with id [1] and pid [73888], exited with code [0] via signal [SIGINT]
2016-03-29 10:43:00: App [my-app] with id [2] and pid [73897], exited with code [0] via signal [SIGINT]
2016-03-29 10:43:00: Starting execution sequence in -cluster mode- for app name:my-app id:1
2016-03-29 10:43:00: Starting execution sequence in -cluster mode- for app name:my-app id:2
2016-03-29 10:43:01: App name:my-app id:1 online
2016-03-29 10:43:01: App name:my-app id:2 online
**2016-03-29 10:43:01: [App:my-app] =>Staring...**

2016-03-29 10:43:01: [App:my-app] =>Staring...

2016-03-29 10:43:01: Stopping app:my-app id:1
2016-03-29 10:43:01: Stopping app:my-app id:1

How to solve this problem?

lenew avatar Mar 29 '16 02:03 lenew

May be i should use kill to send SIGTERM.

lenew avatar Mar 29 '16 10:03 lenew