From 1896524435c1e865f7a5d91fc2dfca9eea80b2b8 Mon Sep 17 00:00:00 2001 From: Unitech Date: Tue, 17 Jan 2017 15:25:43 +0100 Subject: [PATCH] (CLI) --disable-trace --- bin/pm2 | 5 +++-- lib/API.js | 27 +++++++++++++-------------- lib/API/schema.json | 6 +++++- lib/Common.js | 9 ++++++++- lib/God.js | 15 --------------- 5 files changed, 29 insertions(+), 33 deletions(-) diff --git a/bin/pm2 b/bin/pm2 index 0d959715..d1fdaaa5 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -59,7 +59,8 @@ commander.version(pkg.version) .option('--no-treekill', 'Only kill the main process, not detached children') .option('--no-pmx', 'start an app without pmx') .option('--no-automation', 'start an app without pmx') - .option('--trace [instances_to_trace]', 'enable transaction tracing with keymetrics', false) + .option('--trace', 'enable transaction tracing with km') + .option('--disable-trace', 'disable transaction tracing with km') .usage('[cmd] app'); commander.on('--help', function() { @@ -729,7 +730,7 @@ commander.command('logs [id|name]') if (cmd.err === true) exclusive = 'err'; - + if (cmd.nostream === true) pm2.printLogs(id, line, raw, timestamp, exclusive); else if (cmd.json === true) diff --git a/lib/API.js b/lib/API.js index 004c6bb8..83437f13 100644 --- a/lib/API.js +++ b/lib/API.js @@ -108,16 +108,14 @@ var API = module.exports = function(opts) { this.gl_interact_infos = null; this.gl_is_km_linked = false; - fs.readFile(conf.INTERACTOR_PID_PATH, function(err, data) { - if (err) return false; - try { - var pid = parseInt(data.toString().trim()); - process.kill(pid, 0); - that.gl_is_km_linked = true; - } catch(e) { - that.gl_is_km_linked = false; - } - }); + try { + var pid = fs.readFileSync(conf.INTERACTOR_PID_PATH); + pid = parseInt(pid.toString().trim()); + process.kill(pid, 0); + that.gl_is_km_linked = true; + } catch(e) { + that.gl_is_km_linked = false; + } KMDaemon.getInteractInfo(this._conf, function(i_err, interact) { that.gl_interact_infos = interact; @@ -783,8 +781,7 @@ API.prototype._startScript = function(script, opts, cb) { util._extend(resolved_paths.env, additional_env); // Is KM linked? - if (that.gl_is_km_linked != false) - resolved_paths.km_link = true; + resolved_paths.km_link = that.gl_is_km_linked; that.Client.executeRemote('prepare', resolved_paths, function(err, data) { if (err) { @@ -1014,8 +1011,7 @@ API.prototype._startJson = function(file, opts, action, pipe, cb) { delete resolved_paths.env.current_conf; // Is KM linked? - if (that.gl_is_km_linked != false) - resolved_paths.km_link = true; + resolved_paths.km_link = that.gl_is_km_linked; that.Client.executeRemote('prepare', resolved_paths, function(err, data) { if (err) { @@ -1190,6 +1186,9 @@ API.prototype._operate = function(action_name, process_name, envs, cb) { envs = { current_conf : _conf } + + // Is KM linked? + envs.current_conf.km_link = that.gl_is_km_linked; } /** diff --git a/lib/API/schema.json b/lib/API/schema.json index 7c7756e2..1044b30f 100644 --- a/lib/API/schema.json +++ b/lib/API/schema.json @@ -167,9 +167,13 @@ "post_update": { "type": "array" }, + "disable_trace": { + "type": [ + "boolean" + ] + }, "trace": { "type": [ - "number", "boolean" ] } diff --git a/lib/Common.js b/lib/Common.js index 94fbfa7c..90cb4179 100644 --- a/lib/Common.js +++ b/lib/Common.js @@ -501,6 +501,7 @@ Common.mergeEnvironmentVariables = function(app_env, env_name, deploy_conf) { /** * This function will resolve paths, option and environment + * CALLED before 'prepare' God call (=> PROCESS INITIALIZATION) * @method resolveAppAttributes * @param {Object} opts * @param {Object} opts.cwd @@ -521,7 +522,8 @@ Common.resolveAppAttributes = function(opts, legacy_app) { /** - * Verify configurations. + * Verify configurations + * Called on EVERY Operation (start/restart/reload/stop...) * @param {Array} appConfs * @returns {Array} */ @@ -538,6 +540,11 @@ Common.verifyConfs = function(appConfs){ for (var i = 0; i < appConfs.length; i++) { var app = appConfs[i]; + if (app.disable_trace) { + app.trace = false + delete app.disable_trace; + } + // Warn deprecates. checkDeprecates(app); diff --git a/lib/God.js b/lib/God.js index b0addf84..a62d53c1 100644 --- a/lib/God.js +++ b/lib/God.js @@ -361,9 +361,6 @@ God.prepare = function prepare(env, cb) { var arr = []; var instance_id = 0; - // pick a number of worker that will have tracing enabled - var workerTraced = typeof(env.trace === 'number') ? env.trace : 1; - (function ex(i) { if (i <= 0) { if (cb) return cb(null, arr); @@ -376,18 +373,6 @@ God.prepare = function prepare(env, cb) { if (env.env && env.env.vizion_running) env.env.vizion_running = false; - // if the tracing is enabled - if (env.trace !== undefined && env.trace !== false) { - // check if we enabled trace in the number provided of worker - if (workerTraced > 0) { - workerTraced--; - env.trace = true; - } - // or disable it - else - env.trace = false; - } - return God.executeApp(Utility.clone(env), function(err, clu) { if (err) return ex(i - 1); arr.push(Utility.clone(clu));