From 86207872eb01c5adda0f05f31d4bbcb8e1875987 Mon Sep 17 00:00:00 2001 From: johnnyman727 Date: Fri, 13 Feb 2015 21:12:57 -0800 Subject: [PATCH] Fixes #1 the proper way with stream signals --- lib/deploy.js | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/lib/deploy.js b/lib/deploy.js index a751955e..7eda9349 100644 --- a/lib/deploy.js +++ b/lib/deploy.js @@ -2,7 +2,6 @@ var Client = require('ssh2').Client , fs = require('fs') , tessel = require('tessel') , envfile = require('envfile') - , readLine = require ("readline") , config = envfile.parseFileSync(__dirname + '/../config.env') function sftpDeploy(opts) { @@ -41,11 +40,14 @@ function sftpDeploy(opts) { if (err) throw err; closeRemoteOnInterrupt(conn); stream.on('close', function(code, signal) { + stream.signal('KILL'); conn.end(); }).on('data', function(data) { console.log(data.toString()); }).stderr.on('data', function(data) { console.log("Err: ", data.toString()); + stream.signal('KILL'); + conn.end(); }); }); }); @@ -60,31 +62,4 @@ function sftpDeploy(opts) { }); } -function closeRemoteOnInterrupt(conn) { - if (process.platform === "win32"){ - var rl = readLine.createInterface ({ - input: process.stdin, - output: process.stdout - }); - - rl.on("SIGINT", function (){ - killRemoteNode(function() { process.emit ("SIGINT"); }); - }); - } - else { - process.on("SIGINT", function(){ - killRemoteNode(function() { process.exit(); }); - }); - } - - function killRemoteNode(cb) { - // There has got to be a better way to do this... - conn.exec('killall node nodejs', function(err, stream) { - if (err) throw err; - stream.end(); - cb && cb(); - }); - } -} - module.exports.sftpDeploy = sftpDeploy; \ No newline at end of file