Skip to content

Commit

Permalink
Merge pull request #4 from tessel/jon-fix-issues
Browse files Browse the repository at this point in the history
Fixes #1 the proper way with stream signals
  • Loading branch information
johnnyman727 committed Mar 13, 2015
2 parents f522e6c + 8620787 commit 051fbdd
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions lib/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
});
});
});
Expand All @@ -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;

0 comments on commit 051fbdd

Please sign in to comment.