Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'master' of github.com:stonecobra/node-supervisor

  • Loading branch information...
commit c4c376b33284f5a3a9654969c579332244a1cdaf 2 parents 11318ac + 3cad4aa
Scott Sanders authored August 04, 2012
21  README.md
Source Rendered
@@ -14,6 +14,7 @@ clean up all the inter-module references, and without a whole new
14 14
 
15 15
     Usage:
16 16
       supervisor [options] <program>
  17
+      supervisor [options] -- <program> [args ...]
17 18
 
18 19
     Required:
19 20
       <program>
@@ -33,21 +34,25 @@ clean up all the inter-module references, and without a whole new
33 34
       -x|--exec <executable>
34 35
         The executable that runs the specified program.
35 36
         Default is 'node'
36  
-        
37  
-      -r|--restart-on-error")
38  
-        Will automatically restart the supervised program.
39  
-        as soon as it ends unexpectedly with an exit code other than 0.
40  
-        When not specified supervisor will wait for another change in the
41  
-        source files, after the program crashed.
  37
+
  38
+      -n|--no-restart-on error|exit
  39
+        Don't automatically restart the supervised program if it ends.
  40
+        Supervisor will wait for a change in the source files.
  41
+        If "error", an exit code of 0 will still restart.
  42
+        If "exit", no restart regardless of exit code.
42 43
 
43 44
       -h|--help|-?
44 45
         Display these usage instructions.
45 46
 
  47
+      -q|--quiet
  48
+        Suppress DEBUG messages
  49
+
46 50
     Examples:
47 51
       supervisor myapp.js
48 52
       supervisor myapp.coffee
49 53
       supervisor -w scripts -e myext -x myrunner myapp
50  
-      supervisor -w lib -w server.js -w config.js server.js
  54
+      supervisor -w lib,server.js,config.js server.js
  55
+      supervisor -- server.js -h host -p port
51 56
 
52 57
 
53 58
 ## Simple Install
@@ -62,7 +67,7 @@ You don't even need to download or fork this repo at all.
62 67
 
63 68
 Get this code, install npm, and then do this:
64 69
 
65  
-		npm link
  70
+    npm link
66 71
 
67 72
 ## todo
68 73
 
45  lib/supervisor.js
@@ -3,7 +3,8 @@ var fs = require("fs");
3 3
 var spawn = require("child_process").spawn;
4 4
 var fileExtensionPattern;
5 5
 var startChildProcess;
6  
-var restartOnError = false;
  6
+var noRestartOn = null;
  7
+var debug = true;
7 8
 
8 9
 exports.run = run;
9 10
 
@@ -12,6 +13,10 @@ function run (args) {
12 13
   while (arg = args.shift()) {
13 14
     if (arg === "--help" || arg === "-h" || arg === "-?") {
14 15
       return help();
  16
+    } else if (arg === "--quiet" || arg === "-q") {
  17
+      debug = false;
  18
+      util.debug = function(){};
  19
+      util.puts = function(){};
15 20
     } else if (arg === "--watch" || arg === "-w") {
16 21
       watch = args.shift();
17 22
     } else if (arg === "--poll-interval" || arg === "-p") {
@@ -20,8 +25,8 @@ function run (args) {
20 25
       extensions = args.shift();
21 26
     } else if (arg === "--exec" || arg === "-x") {
22 27
       executor = args.shift();
23  
-    } else if (arg === "--restart-on-error" || arg === "-r") {
24  
-      restartOnError = true;
  28
+    } else if (arg === "--no-restart-on" || arg === "-n") {
  29
+      noRestartOn = args.shift();
25 30
     } else if (arg === "--") {
26 31
       // Remaining args are: program [args, ...]
27 32
       program = args.shift();
@@ -65,15 +70,15 @@ function run (args) {
65 70
   util.debug("  --extensions '" + extensions + "'");
66 71
   util.debug("  --exec '" + executor + "'");
67 72
   util.puts("");
68  
-  
  73
+
69 74
   // store the call to startProgramm in startChildProcess
70 75
   // in order to call it later
71 76
   startChildProcess = function() { startProgram(program, executor, programArgs); };
72  
-  
  77
+
73 78
   // if we have a program, then run it, and restart when it crashes.
74 79
   // if we have a watch folder, then watch the folder for changes and restart the prog
75 80
   startChildProcess();
76  
-  
  81
+
77 82
   var watchItems = watch.split(',');
78 83
   watchItems.forEach(function (watchItem) {
79 84
     if (!watchItem.match(/^\/.*/)) { // watch is not an absolute path
@@ -97,6 +102,7 @@ function help () {
97 102
     ("")
98 103
     ("Usage:")
99 104
     ("  supervisor [options] <program>")
  105
+    ("  supervisor [options] -- <program> [args ...]")
100 106
     ("")
101 107
     ("Required:")
102 108
     ("  <program>")
@@ -121,19 +127,23 @@ function help () {
121 127
     ("    The executable that runs the specified program.")
122 128
     ("    Default is 'node'")
123 129
     ("")
124  
-    ("  -r|--restart-on-error")
125  
-    ("    Will automatically restart the supervised program")
126  
-    ("    as soon as it ends unexpectedly with an exit code other than 0.")
127  
-    ("    When not specified supervisor will wait for another change in the")
128  
-    ("    source files, after the program crashed.")
  130
+    ("  -n|--no-restart-on error|exit")
  131
+    ("    Don't automatically restart the supervised program if it ends.")
  132
+    ("    Supervisor will wait for a change in the source files.")
  133
+    ("    If \"error\", an exit code of 0 will still restart.")
  134
+    ("    If \"exit\", no restart regardless of exit code.")
129 135
     ("")
130 136
     ("  -h|--help|-?")
131 137
     ("    Display these usage instructions.")
132 138
     ("")
  139
+    ("  -q|--quiet")
  140
+    ("    Suppress DEBUG messages")
  141
+    ("")
133 142
     ("Examples:")
134 143
     ("  supervisor myapp.js")
135 144
     ("  supervisor myapp.coffee")
136 145
     ("  supervisor -w scripts -e myext -x myrunner myapp")
  146
+    ("  supervisor -- server.js -h host -p port")
137 147
     ("");
138 148
 };
139 149
 
@@ -143,18 +153,17 @@ function startProgram (prog, exec, args) {
143 153
   else
144 154
     util.debug("Starting child process with '" + exec + " " + prog + "'");
145 155
   var spawnme = args ? [prog].concat(args) : [prog];
  156
+  crash_queued = false;
146 157
   var child = exports.child = spawn(exec, spawnme);
147 158
   child.stdout.addListener("data", function (chunk) { chunk && util.print(chunk); });
148 159
   child.stderr.addListener("data", function (chunk) { chunk && util.debug(chunk); });
149  
-  child.addListener("exit", function (code) { 
150  
-    if (!crash_queued && code !== 0) {
151  
-      // error code, do not restart right now, wait for the file-watcher to call the restart
  160
+  child.addListener("exit", function (code) {
  161
+    if (!crash_queued) {
152 162
       util.debug("Program " + prog + " exited with code " + code + "\n");
153 163
       exports.child = null;
154  
-      if (!restartOnError) return;
  164
+      if (noRestartOn == "exit" || noRestartOn == "error" && code !== 0) return;
155 165
     }
156  
-    crash_queued = false;
157  
-    startProgram(prog, exec, args); 
  166
+    startProgram(prog, exec, args);
158 167
   });
159 168
 }
160 169
 
@@ -206,7 +215,7 @@ var findAllWatchFiles = function(path, callback) {
206 215
       if (stats.isDirectory()) {
207 216
         fs.readdir(path, function(err, fileNames) {
208 217
           if(err) {
209  
-            util.puts('Error reading path: ' + path);
  218
+            util.error('Error reading path: ' + path);
210 219
           }
211 220
           else {
212 221
             fileNames.forEach(function (fileName) {
2  package.json
... ...
@@ -1,5 +1,5 @@
1 1
 { "name" : "supervisor"
2  
-, "version" : "0.2.0"
  2
+, "version" : "0.3.0"
3 3
 , "description" : "A supervisor program for running nodejs programs"
4 4
 , "author" : "Isaac Z. Schlueter <i@izs.me>"
5 5
 , "contributors" : [ "Brian Ehmann <behmann@gmail.com>"

0 notes on commit c4c376b

Please sign in to comment.
Something went wrong with that request. Please try again.