Hey people!
I'm running both Node.JS and Python scripts. When PM2 receives a kill interruption (not by $ pm2 kill), it successfully terminates all node processes, but leaves python processes behind, which causes duplicates when resurrecting PM2.
Do you have any ideas on this?
Btw, thanks for the awesome work 馃憤
Create files script.py, script.js, ecosystem.config.js
script.py
import time
if __name__ == "__main__":
while 1:
print 'Script.py: alive'
time.sleep(1)
script.js
setInterval(function() {
console.log('Script.js: alive')
}, 1000);
````
*ecosystem.config.js*
```js
module.exports = {
apps : [
{
name : "py-script",
script : "script.py"
},
{
name : "js-script",
script : "script.js"
}
]
}
Execute commands:
pm2 start ecosystem.config.js # start python and node apps
ps -ef |grep '[s]cript.py' # verify that script.py is running and its PID
ps -ef |grep '[s]cript.js' # verify that script.js is running and its PID
kill `cat ~/.pm2/pm2.pid` # kill PM2
ps -ef |grep '[s]cript.py' # script.py is still running
ps -ef |grep '[s]cript.js' # script.js is not running
OS : Ubuntu 14.04
node.js : 4.6.1
python : 2.7.6
PM2 : 2.1.5
2016-11-18 12:26:51: Starting execution sequence in -fork mode- for app name:py-script id:0
2016-11-18 12:26:51: Starting execution sequence in -fork mode- for app name:js-script id:1
2016-11-18 12:26:51: App name:py-script id:0 online
2016-11-18 12:26:51: App name:js-script id:1 online
2016-11-18 12:26:58: pm2 has been killed by signal, dumping process list before exit...
2016-11-18 12:26:58: [PM2] Exited peacefully
Do you see the same behavior by using pm2 kill? There might be a missing signal handler there.
No! All processes are killed.
2016-11-18 12:55:10: Starting execution sequence in -fork mode- for app name:py-script id:0
2016-11-18 12:55:10: Starting execution sequence in -fork mode- for app name:js-script id:1
2016-11-18 12:55:10: App name:py-script id:0 online
2016-11-18 12:55:10: App name:js-script id:1 online
2016-11-18 12:55:23: Stopping app:py-script id:0
2016-11-18 12:55:23: Stopping app:js-script id:1
2016-11-18 12:55:23: App [py-script] with id [0] and pid [10846], exited with code [1] via signal [SIGINT]
2016-11-18 12:55:23: [HandleExit] PM2 is being killed, stopping restart procedure...
2016-11-18 12:55:23: App [js-script] with id [1] and pid [10847], exited with code [0] via signal [SIGINT]
2016-11-18 12:55:23: [HandleExit] PM2 is being killed, stopping restart procedure...
2016-11-18 12:55:23: pid=10846 msg=process killed
2016-11-18 12:55:23: pid=10847 msg=process killed
2016-11-18 12:55:23: ===============================================================================
2016-11-18 12:55:23: --- Stopping PM2 --------------------------------------------------------------
2016-11-18 12:55:23: Time : Fri Nov 18 2016 12:55:23 GMT-0200 (BRST)
2016-11-18 12:55:23: ===============================================================================
2016-11-18 12:55:23: RPC closed
2016-11-18 12:55:23: PUB closed
2016-11-18 12:55:23: PM2 successfully stopped
Hmm, weird
https://github.com/Unitech/pm2/blob/master/lib/Daemon.js#L251
the default signal for kill should be TERM which should be handled...
saroka thanks for the precise report it's been helpful to find the bug.
The fix is already available on the development branch:
$ npm install Unitech/pm2#development
$ pm2 update
Yeah! That fixed the issue 馃樅
Thank you!
available in current pm2 version (2.1.6)