Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Choices for when to restart, fixes #14

  • Loading branch information...
commit 2953c77345bb1ef47b3d5cf772374cd368541231 1 parent a6356f6
@iangreenleaf iangreenleaf authored
Showing with 16 additions and 17 deletions.
  1. +6 −6 README.md
  2. +10 −11 lib/supervisor.js
View
12 README.md
@@ -34,12 +34,12 @@ clean up all the inter-module references, and without a whole new
-x|--exec <executable>
The executable that runs the specified program.
Default is 'node'
-
- -r|--restart-on-error")
- Will automatically restart the supervised program.
- as soon as it ends unexpectedly with an exit code other than 0.
- When not specified supervisor will wait for another change in the
- source files, after the program crashed.
+
+ -n|--no-restart-on error|exit
+ Don't automatically restart the supervised program if it ends.
+ Supervisor will wait for a change in the source files.
+ If "error", an exit code of 0 will still restart.
+ If "exit", no restart regardless of exit code.
-h|--help|-?
Display these usage instructions.
View
21 lib/supervisor.js
@@ -3,7 +3,7 @@ var fs = require("fs");
var spawn = require("child_process").spawn;
var fileExtensionPattern;
var startChildProcess;
-var restartOnError = false;
+var noRestartOn = null;
var debug = true;
exports.run = run;
@@ -25,8 +25,8 @@ function run (args) {
extensions = args.shift();
} else if (arg === "--exec" || arg === "-x") {
executor = args.shift();
- } else if (arg === "--restart-on-error" || arg === "-r") {
- restartOnError = true;
+ } else if (arg === "--no-restart-on" || arg === "-n") {
+ noRestartOn = args.shift();
} else if (arg === "--") {
// Remaining args are: program [args, ...]
program = args.shift();
@@ -127,11 +127,11 @@ function help () {
(" The executable that runs the specified program.")
(" Default is 'node'")
("")
- (" -r|--restart-on-error")
- (" Will automatically restart the supervised program")
- (" as soon as it ends unexpectedly with an exit code other than 0.")
- (" When not specified supervisor will wait for another change in the")
- (" source files, after the program crashed.")
+ (" -n|--no-restart-on error|exit")
+ (" Don't automatically restart the supervised program if it ends.")
+ (" Supervisor will wait for a change in the source files.")
+ (" If \"error\", an exit code of 0 will still restart.")
+ (" If \"exit\", no restart regardless of exit code.")
("")
(" -h|--help|-?")
(" Display these usage instructions.")
@@ -157,11 +157,10 @@ function startProgram (prog, exec, args) {
child.stdout.addListener("data", function (chunk) { chunk && util.print(chunk); });
child.stderr.addListener("data", function (chunk) { chunk && util.debug(chunk); });
child.addListener("exit", function (code) {
- if (!crash_queued && code !== 0) {
- // error code, do not restart right now, wait for the file-watcher to call the restart
+ if (!crash_queued) {
util.debug("Program " + prog + " exited with code " + code + "\n");
exports.child = null;
- if (!restartOnError) return;
+ if (noRestartOn == "exit" || noRestartOn == "error" && code !== 0) return;
}
crash_queued = false;
startProgram(prog, exec, args);
Please sign in to comment.
Something went wrong with that request. Please try again.