Skip to content

Commit

Permalink
feat: ignore signal when running in --no-daemon
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Feb 2, 2018
1 parent 41bf6ef commit b9c01c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
3 changes: 2 additions & 1 deletion lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ Client.prototype.start = function(cb) {
var daemon = new Daemon({
pub_socket_file : that.conf.DAEMON_PUB_PORT,
rpc_socket_file : that.conf.DAEMON_RPC_PORT,
pid_file : that.conf.PM2_PID_FILE_PATH
pid_file : that.conf.PM2_PID_FILE_PATH,
ignore_signals : true
});

console.log('Launching in no daemon mode');
Expand Down
13 changes: 4 additions & 9 deletions lib/Daemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var fmt = require('./tools/fmt.js');
var Daemon = module.exports = function(opts) {
if (!opts) opts = {};

this.ignore_signals = opts.ignore_signals || false;
this.rpc_socket_ready = false;
this.pub_socket_ready = false;

Expand Down Expand Up @@ -89,7 +90,8 @@ Daemon.prototype.innerStart = function(cb) {
console.error(e.stack || e);
}

this.handleSignals();
if (this.ignore_signals != true)
this.handleSignals();

/**
* Pub system for real time notifications
Expand Down Expand Up @@ -255,18 +257,11 @@ Daemon.prototype.close = function(opts, cb) {
msg : 'pm2 has been killed via CLI'
});

fmt.sep();
fmt.title('Stopping PM2');
fmt.field('Time', new Date());
fmt.sep();

/**
* Cleanly kill pm2
*/
that.rpc_socket.close(function() {
console.log('RPC closed');
that.pub_socket.close(function() {
console.log('PUB closed');

// notify cli that the daemon is shuting down (only under unix since windows doesnt handle signals)
if (cst.IS_WINDOWS === false) {
Expand Down Expand Up @@ -335,7 +330,7 @@ Daemon.prototype.gracefullExit = function() {
try {
fs.unlinkSync(that.pid_path);
} catch(e) {}
console.log('[PM2] Exited peacefully');
console.log('Exited peacefully');
process.exit(0);
});
});
Expand Down

1 comment on commit b9c01c9

@holm
Copy link

@holm holm commented on b9c01c9 Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really caught us by surprise. Is there information on why this was changed?

Please sign in to comment.