mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
CLI.kill now wait for system signal from PM2
This commit is contained in:
parent
37a81a929f
commit
4a8b0fe1fb
4
bin/pm2
4
bin/pm2
@ -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);
|
||||
});
|
||||
}));
|
||||
|
||||
//
|
||||
|
||||
@ -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);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
28
lib/Satan.js
28
lib/Satan.js
@ -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() {});
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user