CLI.kill now wait for system signal from PM2

This commit is contained in:
tknew2 2014-11-14 17:59:14 +01:00
parent 37a81a929f
commit 4a8b0fe1fb
3 changed files with 30 additions and 29 deletions

View File

@ -506,7 +506,9 @@ commander.command('ilogs')
commander.command('kill')
.description('kill daemon')
.action(failOnUnknown(function(arg) {
CLI.killDaemon();
CLI.killDaemon(function() {
process.exit(cst.SUCCESS_EXIT);
});
}));
//

View File

@ -16,6 +16,7 @@ var pkg = require('../../package.json');
var pidusage = require('pidusage');
var util = require('util');
var Satan = require('../Satan');
var debug = require('debug')('pm2:ActionMethod');
var Common = require('../Common');
@ -389,17 +390,29 @@ module.exports = function(God) {
* @param {} cb
* @return
*/
God.killMe = function(env, cb) {
God.killMe = function(opts, cb) {
console.log('PM2 is being killed via kill method');
cb(null, {msg : 'PM2 being stopped'});
God.bus.emit('pm2:kill', {
status : 'killed',
msg : 'pm2 has been killed via CLI'
});
setTimeout(function() {
God.bus.emit('pm2:kill', {
status : 'killed',
msg : 'pm2 has been killed via CLI'
/**
* Cleanly kill pm2
*/
Satan.rpc_socket.close(function() {
console.log('RPC socket closed');
Satan.pub_socket.close(function() {
console.log('PUB socket closed');
process.kill(parseInt(opts.pid), 'SIGUSR2');
setTimeout(function() {
process.exit(cst.SUCCESS_EXIT);
}, 2);
});
}, 50);
});
};

View File

@ -281,22 +281,6 @@ Satan.remoteWrapper = function() {
return false;
return pub.emit(this.event, JSON.parse(Stringify(data_v)));
});
/**
* Cleanly kill pm2
*/
God.bus.on('pm2:kill', function() {
console.log('killing PM2 via Satan');
self.rpc_socket.close(function() {
console.log('RPC socket closed');
self.pub_socket.close(function() {
console.log('PUB socket closed');
console.log('exiting PM2');
process.exit(cst.SUCCESS_EXIT);
});
});
});
};
/**
@ -527,14 +511,16 @@ Satan.notifyGod = function(action_name, id, cb) {
* @return
*/
Satan.killDaemon = function killDaemon(fn) {
Satan.executeRemote('killMe', {}, function() {
process.on('SIGUSR2', function() {
debug('Received SIGUSR2');
Satan.disconnectRPC(function() {
setTimeout(function() {
return fn ? fn(null, {success:true}) : false;
}, 200);
return false;
debug('RPC disconnected');
return fn ? fn(null, {success:true}) : false;
});
});
// Kill daemon
Satan.executeRemote('killMe', {pid : process.pid}, function() {});
};
/**