diff --git a/lib/CLI.js b/lib/CLI.js index 8d5b1412..5e2dc329 100644 --- a/lib/CLI.js +++ b/lib/CLI.js @@ -1399,6 +1399,8 @@ function fallbackLogStream(id) { exitCli(cst.ERROR_EXIT); } + Log.stream(cst.PM2_LOG_FILE_PATH, 'PM2'); + printOut('########### Starting streaming logs for [%s] process', id || 'all'); list.forEach(function(proc) { if ((!id || (id && !isNaN(parseInt(id)) && proc.pm_id == id)) || diff --git a/lib/God.js b/lib/God.js index 1d9f6e47..294f05fd 100644 --- a/lib/God.js +++ b/lib/God.js @@ -55,7 +55,7 @@ require('./Watcher')(God); * @return */ God.handleExit = function handleExit(clu, exit_code) { - console.log('Script %s %s exit', clu.pm2_env.pm_exec_path, clu.pm2_env.pm_id); + console.log('App name:%s id:%s exited', clu.pm2_env.name, clu.pm2_env.pm_id); var proc = this.clusters_db[clu.pm2_env.pm_id]; @@ -202,6 +202,7 @@ God.executeApp = function executeApp(env, cb) { God.bus.emit('process:online', {process : Common.serialize(proc)}); + console.log('App name:%s id:%s online', proc.pm2_env.name, proc.pm2_env.pm_id); if (cb) cb(null, clu); return false; }); @@ -233,7 +234,7 @@ God.executeApp = function executeApp(env, cb) { clu.once('online', function cluOnline() { proc.pm2_env.status = cst.ONLINE_STATUS; - console.log('%s - id%s worker online', proc.pm2_env.pm_exec_path, proc.pm2_env.pm_id); + console.log('App name:%s id:%s online', proc.pm2_env.name, proc.pm2_env.pm_id); God.bus.emit('process:online', { process : Common.serialize(proc) }); diff --git a/lib/God/ActionMethods.js b/lib/God/ActionMethods.js index 72d07e92..7ce1782c 100644 --- a/lib/God/ActionMethods.js +++ b/lib/God/ActionMethods.js @@ -311,13 +311,12 @@ module.exports = function(God) { util._extend(proc.pm2_env.env, opts.env); if (proc.pm2_env.status == cst.ONLINE_STATUS) { - debug('[restart] process already online, killing it for auto restart'); - God.killProcess(proc.process.pid, function() { - setTimeout(function() { - return cb(null, God.getFormatedProcesses()); - }, 100); - return false; + God.stopProcessId(id, function(err) { + proc.pm2_env.restart_time += 1; + return God.startProcessId(id, cb); }); + + return false; } else { debug('[restart] process not online, starting it'); diff --git a/lib/God/ClusterMode.js b/lib/God/ClusterMode.js index 5044eaf2..d23f489d 100644 --- a/lib/God/ClusterMode.js +++ b/lib/God/ClusterMode.js @@ -35,7 +35,9 @@ module.exports = function ClusterMode(God) { // return cb(God.logAndGenerateError('Script ' + env_copy.pm_exec_path + ' missing'), {}); // } - console.log('Entering in node wrap logic (cluster_mode) for script %s', env_copy.pm_exec_path); + console.log('Starting execution sequence in -cluster mode- for app name:%s id:%s', + env_copy.name, + env_copy.pm_id); if (env_copy.node_args && Array.isArray(env_copy.node_args)) { cluster.settings.execArgv = env_copy.node_args; diff --git a/lib/God/ForkMode.js b/lib/God/ForkMode.js index 5c7ec30c..be6e2b84 100644 --- a/lib/God/ForkMode.js +++ b/lib/God/ForkMode.js @@ -31,7 +31,9 @@ module.exports = function ForkMode(God) { var command = ''; var args = []; - console.log('Entering in fork mode'); + console.log('Starting execution sequence in -fork mode- for app name:%s id:%s', + pm2_env.name, + pm2_env.pm_id); var spawn = require('child_process').spawn; var interpreter = pm2_env.exec_interpreter || 'node'; diff --git a/lib/God/Methods.js b/lib/God/Methods.js index 2c757e7e..d4842a8f 100644 --- a/lib/God/Methods.js +++ b/lib/God/Methods.js @@ -179,16 +179,16 @@ module.exports = function(God) { God.processIsDead = function(pid, cb) { if (!pid) return cb({type : 'param:missing', msg : 'no pid passed'}); - var timeout; + var timeout = null; var timer = setInterval(function() { if (God.checkProcess(pid) === false) { - console.log('process with pid %d successfully killed', pid); + console.log('Process with pid %d killed', pid); clearTimeout(timeout); clearInterval(timer); return cb(null, true); } - console.log('process with pid %d still not killed, retrying...', pid); + console.log('Process with pid %d still not killed, retrying...', pid); return false; }, 50); diff --git a/lib/God/Reload.js b/lib/God/Reload.js index f3153c00..3f3e1a98 100644 --- a/lib/God/Reload.js +++ b/lib/God/Reload.js @@ -57,7 +57,7 @@ function softReload(God, id, cb) { // The new worker is up but does not need to listen. new_worker.emit('listening'); } - } + }; new_worker.on('message', onmessage); @@ -65,16 +65,12 @@ function softReload(God, id, cb) { new_worker.once('listening', function() { new_worker.removeListener('message', onmessage); clearTimeout(timeout_1); - console.log('%s - id%d worker listening', - new_worker.pm2_env.pm_exec_path, - new_worker.pm2_env.pm_id); + console.log('-reload- New worker listening'); old_worker.once('disconnect', function() { clearTimeout(timeout_2); - console.log('%s - id%s worker disconnect', - old_worker.pm2_env.pm_exec_path, - old_worker.pm2_env.pm_id); + console.log('-reload- Old worker disconnected'); return God.deleteProcessId(t_key, cb); }); timeout_2 = setTimeout(function() { @@ -131,6 +127,7 @@ function hardReload(God, id, cb) { old_worker.pm2_env.pm_id = t_key; + console.log('-reload- Creating a new process waiting for connections'); God.executeApp(new_env, function(err, new_worker) { if (err) return cb(err); @@ -141,15 +138,10 @@ function hardReload(God, id, cb) { // Bind to know when the new process is up new_worker.once('listening', function() { clearTimeout(timer); - console.log('%s - id%d worker listening', - new_worker.pm2_env.pm_exec_path, - new_worker.pm2_env.pm_id); + console.log('-reload- New worker listening'); //old_worker.once('message', function(type) { old_worker.once('disconnect', function() { - console.log('%s - id%s worker disconnect', - old_worker.pm2_env.pm_exec_path, - old_worker.pm2_env.pm_id); - + console.log('-reload- Old worker disconnected'); God.deleteProcessId(t_key, cb); }); try {