From 0d5e893e8b073556b9d342df94f83e0dc5d410f9 Mon Sep 17 00:00:00 2001 From: indexzero Date: Thu, 5 Jan 2012 06:25:29 -0500 Subject: [PATCH] [api] Added `forever restartall` and `forever.restartAll()`. Fixes #131 --- README.md | 1 + lib/forever.js | 9 +++++++++ lib/forever/cli.js | 23 ++++++++++++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f2ab6734..2ad87af7 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ You can use forever to run any kind of script continuously (whether it is writte stop Stop the daemon SCRIPT stopall Stop all running forever scripts restart Restart the daemon SCRIPT + restartall Restart all running forever scripts list List all running forever scripts config Lists all forever user configuration set Sets the specified forever config diff --git a/lib/forever.js b/lib/forever.js index 0a9d23a9..a8a761c8 100644 --- a/lib/forever.js +++ b/lib/forever.js @@ -451,6 +451,15 @@ forever.restart = function (target, format) { return stopOrRestart('restart', 'restart', format, target); }; +// +// ### function restartAll (format) +// #### @format {boolean} Value indicating if we should format output +// Restarts all processes managed by forever. +// +forever.restartAll = function (format) { + return stopOrRestart('restart', 'restartAll', format); +}; + // // ### function stopAll (format) // #### @format {boolean} Value indicating if we should format output diff --git a/lib/forever/cli.js b/lib/forever/cli.js index 656debb1..8a8f6695 100644 --- a/lib/forever/cli.js +++ b/lib/forever/cli.js @@ -25,6 +25,7 @@ var help = [ ' stop Stop the daemon SCRIPT', ' stopall Stop all running forever scripts', ' restart Restart the daemon SCRIPT', + ' restartall Restart all running forever scripts', ' list List all running forever scripts', ' config Lists all forever user configuration', ' set Sets the specified forever config ', @@ -78,7 +79,8 @@ var actions = [ 'start', 'stop', 'stopall', - 'restart', + 'restart', + 'restartall', 'list', 'config', 'set', @@ -268,6 +270,25 @@ app.cmd('stopall', cli.stopall = function () { }); }); +// +// ### function stopall () +// Stops all currently running forever processes. +// +app.cmd('restartall', cli.restartAll = function () { + var runner = forever.restartAll(true); + runner.on('restartAll', function (processes) { + if (processes) { + forever.log.info('Forever restarted processes:'); + processes.split('\n').forEach(function (line) { + forever.log.data(line); + }); + } + else { + forever.log.info('No forever processes running'); + } + }); +}); + // // ### function restart (file) // #### @file {string} Target process to restart