Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added shared stdio with monitor child process

  • Loading branch information...
commit 05b1736eb7c40d82cc7dc6df75dc144613f6b9dc 1 parent 04c2a5a
@ritch ritch authored
Showing with 60 additions and 59 deletions.
  1. +2 −56 index.js
  2. +56 −1 lib/monitor.js
  3. +1 −1  lib/start.js
  4. +1 −1  package.json
View
58 index.js
@@ -1,7 +1,6 @@
var Server = require('./lib/server')
, upgrade = require('doh').upgrade
- , Monitor = require('./lib/monitor')
- , EventEmitter = require('events').EventEmitter;
+ , Monitor = require('./lib/monitor');
/**
* export a simple function that constructs a dpd server based on a config
@@ -17,57 +16,4 @@ module.exports = function (config) {
* opt-in process monitoring support
*/
-module.exports.createMonitor = function (config) {
- var keypress = require('keypress');
- var monitor = new Monitor(__dirname + '/lib/start.js')
- , server = new EventEmitter();
-
- keypress(process.stdin);
-
- server.options = config;
-
- server.listen = function () {
- monitor.start(function (err, commands, restarting) {
- commands.start(config, function (err) {
- if(err) {
- server.emit('error', err);
- } else if(!restarting) {
- server.emit('listening');
- }
- });
-
- monitor.child.on('message', function (data) {
- if(data.moduleError) {
- monitor.stop();
- }
- });
- });
-
- return server;
- };
-
- monitor.on('exit', function () {
- console.log();
- process.stdout.write('Press any key to restart... or q to quit: ');
-
- function keypress(key, e) {
- if(e.ctrl) {
- // allow ctr+c, z, etc
- console.log();
- } else if(key == 'q') {
- console.log();
- process.exit();
- } else {
- monitor.start(true);
- }
- process.stdin.pause();
- process.stdin.setRawMode(false);
- }
-
- process.stdin.once('keypress', keypress);
- process.stdin.setRawMode(true);
- process.stdin.resume();
- });
-
- return server;
-};
+module.exports.createMonitor = Monitor.createMonitor;
View
57 lib/monitor.js
@@ -1,6 +1,8 @@
var ForeverMonitor = require('forever-monitor').Monitor
, util = require('util')
- , uuid = require('./util/uuid');
+ , uuid = require('./util/uuid')
+ , keypress = require('keypress')
+ , EventEmitter = require('events').EventEmitter;
function Monitor(script, options) {
options = options || {};
@@ -49,6 +51,11 @@ Monitor.prototype.start = function (fn) {
} else {
start.apply(this, arguments);
}
+ if(!(this.child.stdout && this.child.stdin && this.child.stderr)) {
+ this.child.stdout = process.stdout;
+ this.child.stdin = process.stdin;
+ this.child.stderr = process.stderr;
+ }
if(this.startCallback) {
this.child.once('message', function (data) {
@@ -99,4 +106,52 @@ Monitor.createCommands = function (commands) {
});
process.send({createCommands: commands});
+}
+
+Monitor.createMonitor = function (config) {
+ var opts = {stdio: [process.stdin, process.stdout, process.stderr, 'ipc']}
+ , monitor = new Monitor(__dirname + '/start.js', opts)
+ , server = new EventEmitter();
+
+ keypress(process.stdin);
+ server.options = config;
+
+ server.listen = function () {
+ monitor.start(function (err, commands, restarting) {
+ commands.start(config, function (err) {
+ if(err) {
+ server.emit('error', err);
+ } else if(!restarting) {
+ server.emit('listening');
+ }
+ });
+ });
+
+ return server;
+ };
+
+ monitor.on('exit', function () {
+ console.log();
+ process.stdout.write('Press any key to restart... or q to quit: ');
+
+ function keypress(key, e) {
+ if(e.ctrl) {
+ // allow ctr+c, z, etc
+ console.log();
+ } else if(key == 'q') {
+ console.log();
+ process.exit();
+ } else {
+ monitor.start(true);
+ }
+ process.stdin.pause();
+ process.stdin.setRawMode(false);
+ }
+
+ process.stdin.once('keypress', keypress);
+ process.stdin.setRawMode(true);
+ process.stdin.resume();
+ });
+
+ return server;
}
View
2  lib/start.js
@@ -6,7 +6,7 @@ var Server = require('./server')
/**
* Commands exposed to parent process.
*/
-
+
commands.start = function (config, fn) {
var server = new Server(config);
upgrade(server);
View
2  package.json
@@ -19,7 +19,7 @@
"filed": ">= 0.0.6",
"mkdirp": "*",
"wrench": "1.3.x",
- "debug": "*",
+ "debug": ">= 0.7.0",
"scrubber": "*",
"shelljs": "https://github.com/dallonf/shelljs/tarball/master",
"http-proxy": "0.8.1",
Please sign in to comment.
Something went wrong with that request. Please try again.