Skip to content

Commit

Permalink
Merge pull request #149 from maxlath/master
Browse files Browse the repository at this point in the history
addin a --save-pid <path> option
  • Loading branch information
petruisfan committed Jul 2, 2015
2 parents 43e6ca3 + a1d3713 commit d628506
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -42,6 +42,9 @@ clean up all the inter-module references, and without a whole new
The executable that runs the specified program.
Default is 'node'

-pid|--save-pid <path>
Save supervisor's process id to a file at the given path.

--debug
Start node with --debug flag.

Expand Down
16 changes: 15 additions & 1 deletion lib/supervisor.js
Expand Up @@ -14,7 +14,7 @@ var log = console.log;
exports.run = run;

function run (args) {
var arg, next, watch, ignore, program, extensions, executor, poll_interval, debugFlag, debugBrkFlag, debugBrkFlagArg, harmony;
var arg, next, watch, ignore, pidFilePath, program, extensions, executor, poll_interval, debugFlag, debugBrkFlag, debugBrkFlagArg, harmony;
while (arg = args.shift()) {
if (arg === "--help" || arg === "-h" || arg === "-?") {
return help();
Expand All @@ -29,6 +29,8 @@ function run (args) {
watch = args.shift();
} else if (arg === "--ignore" || arg === "-i") {
ignore = args.shift();
} else if (arg === "--save-pid" || arg === "-pid") {
pidFilePath = args.shift();
} else if (arg === "--poll-interval" || arg === "-p") {
poll_interval = parseInt(args.shift());
} else if (arg === "--extensions" || arg === "-e") {
Expand Down Expand Up @@ -96,6 +98,12 @@ function run (args) {
// coffee does not understand debug or debug-brk, make coffee pass options to node
program.unshift("--nodejs")
}
if (pidFilePath) {
var pid = process.pid;
fs.writeFileSync(pidFilePath, pid + '\n');
}

var deletePidFile = function(){ fs.unlinkSync(pidFilePath); };

try {
// Pass kill signals through to child
Expand All @@ -106,6 +114,9 @@ function run (args) {
log("Sending "+signal+" to child...");
child.kill(signal);
}
if (pidFilePath){
deletePidFile();
}
process.exit();
});
});
Expand All @@ -121,6 +132,9 @@ function run (args) {
if (ignore) {
log(" --ignore '" + ignore + "'");
}
if (pidFilePath){
log(" --save-pid '" + pidFilePath + "'");
}
log(" --extensions '" + extensions + "'");
log(" --exec '" + executor + "'");
log("");
Expand Down

0 comments on commit d628506

Please sign in to comment.