Skip to content

Commit

Permalink
dont use signal to verify daemon has been killed under windows (#2484)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmarchaud committed Oct 31, 2016
1 parent 0bbb113 commit 382f5ce
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
29 changes: 22 additions & 7 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,18 +493,33 @@ Client.prototype.killDaemon = function killDaemon(fn) {
});
}

process.once('SIGQUIT', function() {
debug('Received SIGQUIT');
clearTimeout(timeout);
quit();
});
// under unix, we listen for signal (that is send by daemon to notify us that its shuting down)
if (process.platform !== 'win32' && process.platform !== 'win64') {
process.once('SIGQUIT', function() {
debug('Received SIGQUIT from pm2 daemon');
clearTimeout(timeout);
quit();
});
}

timeout = setTimeout(function() {
quit();
quit();
}, 3000);

// Kill daemon
this.executeRemote('killMe', {pid : process.pid}, function() {});
this.executeRemote('killMe', {pid : process.pid});

// if under windows, try to ping the daemon to see if it still here
if (process.platform === 'win32' || process.platform === 'win64') {
setTimeout(function() {
that.pingDaemon(function(alive) {
if (!alive) {
clearTimeout(timeout);
return quit();
}
});
}, 250)
}
};


Expand Down
9 changes: 3 additions & 6 deletions lib/Daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,9 @@ Daemon.prototype.close = function(opts, cb) {
that.pub_socket.close(function() {
console.log('PUB closed');

var kill_signal = 'SIGQUIT';

if (process.platform === 'win32' || process.platform === 'win64') {
kill_signal = 'SIGTERM';
}
process.kill(parseInt(opts.pid), kill_signal);
// notify cli that the daemon is shuting down (only under unix since windows doesnt handle signals)
if (process.platform !== 'win32' && process.platform !== 'win64')
process.kill(parseInt(opts.pid), 'SIGQUIT');

console.log('PM2 successfully stopped');
setTimeout(function() {
Expand Down

0 comments on commit 382f5ce

Please sign in to comment.