From cc5ff341d323703955710280eed1dfe61e54f827 Mon Sep 17 00:00:00 2001 From: Joni Shkurti Date: Sat, 25 Apr 2015 21:57:39 +0200 Subject: [PATCH 01/10] reverted commit about fn-arity --- CHANGELOG.md | 6 ++++-- lib/God/ActionMethods.js | 9 +++++++++ lib/Satan.js | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cce580be..9e84bd4a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,8 +7,10 @@ # 0.12.13 (In progress) -- Enhanced: Call reload instead of restart when max-memory-limit reached -- Enhanced: Modules are compatible ES6 by default by adding --harmony flag +- Enhanced : Call reload instead of restart when max-memory-limit reached +- Enhanced : Modules are compatible ES6 by default by adding --harmony flag +- Enhanced : Dump feature is now smarter +- Fix #1206 : fix `pm2 logs` bug when merged_logs # 0.12.12 (Current stable) diff --git a/lib/God/ActionMethods.js b/lib/God/ActionMethods.js index fbad04fd..8a8f2f14 100644 --- a/lib/God/ActionMethods.js +++ b/lib/God/ActionMethods.js @@ -123,6 +123,15 @@ module.exports = function(God) { var process_list = []; var apps = God.getFormatedProcesses(); + // Don't override the actual dump file if process list is empty + // unless user explicitely did `pm2 dump`. + // This often happens when PM2 crashed, we don't want to override + // the dump file with an empty list of process. + if (!apps[0]) { + debug('[PM2] Did not override dump file because list of processes is empty'); + return cb(null, {success:true, process_list: process_list}); + } + function fin(err) { try { fs.writeFileSync(cst.DUMP_FILE_PATH, JSON.stringify(process_list)); diff --git a/lib/Satan.js b/lib/Satan.js index c4ea3dcc..28bbdd8e 100644 --- a/lib/Satan.js +++ b/lib/Satan.js @@ -634,8 +634,8 @@ if (require.main === module) { else { var d = domain.create(); - d.on('error', function(err) { - console.error('ERROR CAUGHT BY DOMAIN:\n' + (err.stack || err)); + d.once('error', function(err) { + console.error('[PM2] Error caught by domain:\n' + (err.stack || err)); God.dumpProcessList(function() { require('child_process').spawn('pm2', ['update'], { From 1cfae8eff3bbc9d493dcc2b44ce21919aaf0b3da Mon Sep 17 00:00:00 2001 From: Joni Shkurti Date: Sat, 25 Apr 2015 22:18:15 +0200 Subject: [PATCH 02/10] pm2 update in domain spawns the actual pm2 exec not the global pm2 --- lib/Satan.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Satan.js b/lib/Satan.js index 28bbdd8e..d6f1259c 100644 --- a/lib/Satan.js +++ b/lib/Satan.js @@ -638,7 +638,7 @@ if (require.main === module) { console.error('[PM2] Error caught by domain:\n' + (err.stack || err)); God.dumpProcessList(function() { - require('child_process').spawn('pm2', ['update'], { + require('child_process').spawn('node', [process.env['_'], 'update'], { detached: true, stdio: [0,1,2] }); From bed99ca5fbb5e3c9ce7b416f775f4715bda3df7c Mon Sep 17 00:00:00 2001 From: Joni Shkurti Date: Sat, 25 Apr 2015 23:01:12 +0200 Subject: [PATCH 03/10] indentation fix --- lib/Satan.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Satan.js b/lib/Satan.js index d6f1259c..c4a4762c 100644 --- a/lib/Satan.js +++ b/lib/Satan.js @@ -638,7 +638,7 @@ if (require.main === module) { console.error('[PM2] Error caught by domain:\n' + (err.stack || err)); God.dumpProcessList(function() { - require('child_process').spawn('node', [process.env['_'], 'update'], { + require('child_process').spawn('node', [process.env['_'], 'update'], { detached: true, stdio: [0,1,2] }); From 10bd30dbcea79b028dd4620d1bd02d139eff5aab Mon Sep 17 00:00:00 2001 From: Joni Shkurti Date: Sat, 25 Apr 2015 23:16:12 +0200 Subject: [PATCH 04/10] doesnt scale an app in fork_mode --- lib/CLI.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/CLI.js b/lib/CLI.js index 0d609d8e..d9f3dd96 100644 --- a/lib/CLI.js +++ b/lib/CLI.js @@ -1243,6 +1243,11 @@ CLI.scale = function(app_name, number, cb) { return cb ? cb({msg: 'App not found'}) : exitCli(cst.ERROR_EXIT); } + if (procs[0].pm2_env.exec_mode !== 'cluster_mode') { + printError(cst.PREFIX_MSG_ERR + 'Application %s is not in cluster mode', app_name); + return cb ? cb({msg: 'App not in cluster mode'}) : exitCli(cst.ERROR_EXIT); + } + var proc_number = procs.length; if (typeof(number) === 'string' && number.indexOf('+') >= 0) { From 011f33cbf0b883d22d67abd03d978fcc22f97637 Mon Sep 17 00:00:00 2001 From: jshkurti Date: Tue, 28 Apr 2015 16:07:54 +0200 Subject: [PATCH 05/10] force vizion when app restarted manually --- lib/God/ActionMethods.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/God/ActionMethods.js b/lib/God/ActionMethods.js index 8a8f2f14..061f407d 100644 --- a/lib/God/ActionMethods.js +++ b/lib/God/ActionMethods.js @@ -247,6 +247,7 @@ module.exports = function(God) { console.log('Stopping app:%s id:%s', proc.pm2_env.name, proc.pm2_env.pm_id); proc.pm2_env.status = cst.STOPPING_STATUS; + proc.pm2_env.vizion_running = false; if (!proc.process.pid) { proc.pm2_env.status = cst.STOPPED_STATUS; From dffd8296f968bb161b9299f1c77393e4a4ba7af2 Mon Sep 17 00:00:00 2001 From: Alexandre Strzelewicz Date: Tue, 28 Apr 2015 10:47:00 -0400 Subject: [PATCH 06/10] Update README.md [ci skip] --- README.md | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ab98fe77..0860ced3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ![PM2](https://github.com/unitech/pm2/raw/master/pres/pm2.20d3ef.png) -PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. +**P**(rocess) **M**(anager) **2** + +PM2 is a production process manager for Node.js / io.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. Starting an application in production mode is as easy as: @@ -35,6 +37,23 @@ $ pm2 start app.js Your app is now put in background, kept alive forever and monitored. +Or you can use pm2 programmatically: + +```javascript +var pm2 = require('pm2'); + +pm2.connect(function() { + pm2.start({ + script : 'app.js', // Script to be run + exec_mode : 'cluster', // Allow your app to be clustered + instances : 4, // Optional: Scale your app by 4 + max_memory_restart : '100M' // Optional: Restart your app if it reaches 100Mo + }, function(err, apps) { + pm2.disconnect(); + }); +}); +``` + ## Main features ### Process management From 9fd489090dfa5afafca6493b28df2c7c0654b14f Mon Sep 17 00:00:00 2001 From: jshkurti Date: Wed, 29 Apr 2015 15:57:11 +0200 Subject: [PATCH 07/10] v0.12.13 --- CHANGELOG.md | 6 ++++-- README.md | 12 +++++++----- bin/pm2 | 2 +- package.json | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e84bd4a..7efae73c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,14 +5,16 @@ - YAML support for apps declarations - Improve app declaration file parsing (log_file, out_file, error_file) -# 0.12.13 (In progress) +# 0.12.13 (Current Stable) +- Enhanced : PM2 doesn't leave processes behind when it crashes - Enhanced : Call reload instead of restart when max-memory-limit reached - Enhanced : Modules are compatible ES6 by default by adding --harmony flag - Enhanced : Dump feature is now smarter - Fix #1206 : fix `pm2 logs` bug when merged_logs +- Fix : pm2 scale doesn't try to scale a fork_mode process -# 0.12.12 (Current stable) +# 0.12.12 - `pm2 logs --raw` flag : show logs in raw format - New command: pm2 scale - scale up/down an application diff --git a/README.md b/README.md index 0cc406ef..0860ced3 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ ![PM2](https://github.com/unitech/pm2/raw/master/pres/pm2.20d3ef.png) -PM2 is a production process manager for Node.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. +**P**(rocess) **M**(anager) **2** + +PM2 is a production process manager for Node.js / io.js applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks. Starting an application in production mode is as easy as: @@ -42,10 +44,10 @@ var pm2 = require('pm2'); pm2.connect(function() { pm2.start({ - script : 'app.js', - exec_mode : 'cluster', - instances : 4, - max_memory_restart : '100M' + script : 'app.js', // Script to be run + exec_mode : 'cluster', // Allow your app to be clustered + instances : 4, // Optional: Scale your app by 4 + max_memory_restart : '100M' // Optional: Restart your app if it reaches 100Mo }, function(err, apps) { pm2.disconnect(); }); diff --git a/bin/pm2 b/bin/pm2 index 194555a1..b67198fb 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -217,7 +217,7 @@ commander.command('restart ') // // Scale up/down a process in cluster mode // -commander.command('scale ') +commander.command('scale ') .description('scale up/down a process in cluster mode depending on total_number param') .action(function(app_name, number) { CLI.scale(app_name, number); diff --git a/package.json b/package.json index 7e91414e..05cff6cb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "pm2", "preferGlobal": "true", - "version": "0.12.12", + "version": "0.12.13", "engines": { "node": ">=0.10" }, From e0570b1a06c3efd74fa0a2b5d7be7b095ac679fd Mon Sep 17 00:00:00 2001 From: jshkurti Date: Wed, 29 Apr 2015 16:39:18 +0200 Subject: [PATCH 08/10] completely removed ilogs feature --- ADVANCED_README.md | 1 - README.md | 2 +- bin/pm2 | 6 ------ lib/CLI.js | 11 ----------- 4 files changed, 1 insertion(+), 19 deletions(-) diff --git a/ADVANCED_README.md b/ADVANCED_README.md index 81d3f3e0..15fcee38 100644 --- a/ADVANCED_README.md +++ b/ADVANCED_README.md @@ -118,7 +118,6 @@ $ pm2 monit # Monitor all processes # Logs $ pm2 logs [--raw] # Display all processes logs in streaming -$ pm2 ilogs # Advanced termcaps interface to display logs $ pm2 flush # Empty all log file $ pm2 reloadLogs # Reload all logs diff --git a/README.md b/README.md index 0860ced3..daade7eb 100644 --- a/README.md +++ b/README.md @@ -158,7 +158,7 @@ Thanks in advance and we hope that you like PM2! - [Using PM2 in your code](https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#programmatic-example) - [Deployment workflow](https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#deployment) - [Startup script generation (SystemV/Ubuntu/Gentoo/AWS)](https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#startup-script) -- [Advanced log management (flush, reload, ilogs)](https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#a9) +- [Advanced log management (flush, reload, logs)](https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#a9) - [GracefullReload](https://github.com/Unitech/PM2/blob/master/ADVANCED_README.md#a690) ## PM2 Full documentation diff --git a/bin/pm2 b/bin/pm2 index b67198fb..5a99c6df 100755 --- a/bin/pm2 +++ b/bin/pm2 @@ -580,12 +580,6 @@ commander.command('logs [id|name]') CLI.streamLogs(id, line, raw); }); -commander.command('ilogs') - .description('advanced interface to display logs') - .action(function(id) { - CLI.ilogs(id); - }); - // // Kill diff --git a/lib/CLI.js b/lib/CLI.js index d9f3dd96..1928a063 100644 --- a/lib/CLI.js +++ b/lib/CLI.js @@ -1507,17 +1507,6 @@ function printLogs(id, lines, proc, raw) { } } -CLI.ilogs = function() { - try { - var logs = require('pm2-logs').init({ - format: 'MMMM Do YYYY, h:mm:ss a' - }); - } catch(e) { - printOut('pm2-logs module is not installed'); - CLI.streamLogs(); - } -}; - /** * Description * @method killDaemon From f2caa0e8c568f571e34c46d386225b1b185ef3df Mon Sep 17 00:00:00 2001 From: jshkurti Date: Wed, 29 Apr 2015 16:40:14 +0200 Subject: [PATCH 09/10] updated changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7efae73c..ebbc5df8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ - YAML support for apps declarations - Improve app declaration file parsing (log_file, out_file, error_file) +# 0.12.14 (Next release) + +- `ilogs` is no longer part of PM2 + # 0.12.13 (Current Stable) - Enhanced : PM2 doesn't leave processes behind when it crashes From ef61ec9b5927a305b156ac16348ace55ee7de0ce Mon Sep 17 00:00:00 2001 From: jshkurti Date: Wed, 29 Apr 2015 17:37:56 +0200 Subject: [PATCH 10/10] reinforced crash handling --- lib/Satan.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/Satan.js b/lib/Satan.js index c4a4762c..b6fa6f63 100644 --- a/lib/Satan.js +++ b/lib/Satan.js @@ -624,7 +624,7 @@ Satan.unlock = function(opts, cb) { if (require.main === module) { var pkg = require('../package.json'); - var God = require('./God.js');; + var God = require('./God.js'); process.title = 'PM2 v' + pkg.version + ': God Daemon'; @@ -637,6 +637,11 @@ if (require.main === module) { d.once('error', function(err) { console.error('[PM2] Error caught by domain:\n' + (err.stack || err)); + process.once('uncaughtException', function() { + console.error('[PM2] Automatic `pm2 update` failed. Killing PM2 daemon and its processes...'); + process.emit('SIGTERM'); + }); + God.dumpProcessList(function() { require('child_process').spawn('node', [process.env['_'], 'update'], { detached: true,