Skip to content

Commit

Permalink
fix: auto-exit edge case fix + pm2 no daemon mode + log in raw by def…
Browse files Browse the repository at this point in the history
…ault + less logs
  • Loading branch information
Unitech committed Feb 2, 2018
1 parent d1916f4 commit 704ae51
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions lib/binaries/Runtime4Docker.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,17 @@ function start(cmd, opts) {
secret_key : process.env.KEYMETRICS_SECRET || commander.secret,
public_key : process.env.KEYMETRICS_PUBLIC || commander.public,
machine_name : process.env.INSTANCE_NAME || commander.machineName,
daemon_mode : true
daemon_mode : false
});

if (commander.autoExit) {
autoExit();
if (opts.web) {
var port = opts.web === true ? cst.WEB_PORT : opts.web;
pm2.web(port);
}

pm2.connect(function() {

if (opts.web) {
var port = opts.web === true ? cst.WEB_PORT : opts.web;
pm2.web(port);
}

run(cmd, opts);
run(cmd, opts, function() {
if (commander.autoExit)
autoExit();
});
}

Expand Down Expand Up @@ -95,25 +91,29 @@ process.on('SIGTERM', function() {
exitPM2();
});

function run(cmd, opts) {
function run(cmd, opts, cb) {
var needRaw = commander.raw;
var timestamp = commander.timestamp;

if (commander.json === true)
Log.jsonStream(pm2.Client, 'all');
else if (commander.format === true)
Log.formatStream(pm2.Client, 'all', false, 'YYYY-MM-DD-HH:mm:ssZZ');
else
Log.stream(pm2.Client, 'all', needRaw, timestamp, true);

function exec() {
pm2.start(cmd, opts, function(err, obj) {
if (err) {
console.error(err.message || err);
return exitPM2();
}

var pm_id = obj[0].pm2_env.pm_id;

if (commander.json === true)
Log.jsonStream(pm2.Client, pm_id);
else if (commander.format === true)
Log.formatStream(pm2.Client, pm_id, false, 'YYYY-MM-DD-HH:mm:ssZZ');
else
Log.stream(pm2.Client, 'all', needRaw, timestamp, false);
if (obj && obj.length == 0) {
console.error('Failed to start application %s', cmd);
return exitPM2();
}
// ack start
cb();

if (process.env.PM2_RUNTIME_DEBUG)
pm2.disconnect(function() {});
Expand All @@ -124,7 +124,6 @@ function run(cmd, opts) {
}

function exitPM2() {
console.log('Exiting PM2');
pm2.kill(function() {
process.exit(0);
});
Expand Down

0 comments on commit 704ae51

Please sign in to comment.