From 69099b136cacd3f348ddad96377968089ed60fb8 Mon Sep 17 00:00:00 2001
From: Sean McArthur <sean.monstar@gmail.com>
Date: Thu, 19 Jul 2012 13:40:07 -0700
Subject: [PATCH] fixes to get it running on Windows

- Windows doesn't have signals, so process.on("SIGINT") throws
- changing process.env.PATH is a bad idea
---
 lib/shutdown.js        |  6 +++++-
 package.json           |  2 +-
 scripts/run_locally.js | 14 ++++++++++----
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/lib/shutdown.js b/lib/shutdown.js
index 7fa3c2fde..26ef5af42 100644
--- a/lib/shutdown.js
+++ b/lib/shutdown.js
@@ -75,5 +75,9 @@ exports.handleTerminationSignals = function(app, callback) {
     };
   }
 
-  process.on('SIGINT', endIt('INT')).on('SIGTERM', endIt('TERM')).on('SIGQUIT', endIt('QUIT'));
+  try {
+    process.on('SIGINT', endIt('INT')).on('SIGTERM', endIt('TERM')).on('SIGQUIT', endIt('QUIT'));
+  } catch (noSignals) {
+    // Window doesn't support signals
+  }
 };
diff --git a/package.json b/package.json
index 1e45de688..ceaad9b77 100644
--- a/package.json
+++ b/package.json
@@ -43,7 +43,7 @@
     "scripts": {
         "postinstall": "./scripts/generate_ephemeral_keys.sh",
         "test": "./scripts/test",
-        "start": "./scripts/run_locally.js"
+        "start": "node ./scripts/run_locally.js"
     },
     "engines": {
         "node": ">= 0.6.2"
diff --git a/scripts/run_locally.js b/scripts/run_locally.js
index 028ccfd21..064212819 100755
--- a/scripts/run_locally.js
+++ b/scripts/run_locally.js
@@ -80,6 +80,7 @@ if (config.get('env').substr(0,5) === 'test_') {
 
 function runDaemon(daemon, cb) {
   Object.keys(daemonsToRun[daemon]).forEach(function(ek) {
+    if (ek === 'path') return; // this blows away the Window PATH
     process.env[ek] = daemonsToRun[daemon][ek];
   });
   var pathToScript = daemonsToRun[daemon].path || path.join(__dirname, "..", "bin", daemon);
@@ -104,6 +105,7 @@ function runDaemon(daemon, cb) {
 
   console.log("spawned", daemon, "("+pathToScript+") with pid", p.pid);
   Object.keys(daemonsToRun[daemon]).forEach(function(ek) {
+    if (ek === 'path') return; // don't kill the Windows PATH
     delete process.env[ek];
   });
 
@@ -133,7 +135,11 @@ daemonNames.forEach(function(dn) {
   });
 });
 
-process.on('SIGINT', function () {
-  console.log('\nSIGINT recieved! trying to shut down gracefully...');
-  Object.keys(daemons).forEach(function (k) { daemons[k].kill('SIGINT'); });
-});
+try {
+  process.on('SIGINT', function () {
+    console.log('\nSIGINT recieved! trying to shut down gracefully...');
+    Object.keys(daemons).forEach(function (k) { daemons[k].kill('SIGINT'); });
+  });
+} catch (noSignals) {
+  // Windows doesn't have signal support, so node explodes
+}
-- 
GitLab