Skip to content

Commit

Permalink
Merge pull request #32 from huseyinkozan/master
Browse files Browse the repository at this point in the history
Verbosity and halt command
  • Loading branch information
johnnyman727 committed Apr 8, 2016
2 parents 83b63e5 + a668005 commit 018abef
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 5 deletions.
10 changes: 8 additions & 2 deletions etc.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ function exec (p, args, opts) {

// windows may or may not have vbox, and that depending on your flavor of Git, that shell may or may not have your Windows user %path% exported into it
// it's much safer to just assume vbox is in the path from the create.js insurePath check on startup
function startvm (name) {
return spawn('vboxheadless', ['-s', name]);
function startvm (name, verbose) {
verbose = typeof verbose !== 'undefined' ? verbose : false;
return spawn('vboxheadless', ['-s', name, '--vrde', verbose ? 'on': 'off']);
}

function stopvm (name) {
return spawn('vboxmanage', ['controlvm', name, 'poweroff']);
}

function seekDevice (hostname, next) {
Expand Down Expand Up @@ -117,4 +122,5 @@ exports.VM_URL = "http://storage.googleapis.com/tessel-builds/ccc157a289db14791e
exports.exec = exec;
exports.chunks = chunks;
exports.startvm = startvm;
exports.stopvm = stopvm;
exports.seekDevice = seekDevice;
48 changes: 48 additions & 0 deletions halt.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var spawn = require('child_process').spawn
, mdns = require('mdns-js')
, etc = require('./etc')
, fs = require('fs')
, concat = require('concat-stream')

try {
var hostname = fs.readFileSync(etc.PATH_VM_NAME, 'utf-8');
} catch (err) {
console.error('No VM found. Please run `t2-vm create` first');
process.exit(1);
}

setTimeout(function () {
if (!isonline) {
console.error('ERROR The VM failed to connect to the network.')
console.error('ERROR Please re-run this command and hope for the best.')
console.error('ERROR Ensure your Wifi policy allows connections to other')
console.error('ERROR devices on the network.')
process.exit(1);
}
}, 60*1000)

console.log('INFO Halting VM ...');
var p = etc.stopvm(etc.VM_NAME);
p.stdout.pipe(concat(function (data) {
if (module.parent.verbose)
console.log(data.toString());
if (data.toString().match(/invalid machine name/i)) {
console.error('ERR No VM exists. Run t2-vm create first.')
process.exit(1);
}
}))
p.stderr.pipe(concat(function(data) {
if (module.parent.verbose)
console.log(data.toString());
}))
p.on('exit', function () {
console.log('INFO VM terminated.');
process.exit();
})

etc.seekDevice(hostname, function (err, data) {
console.error('INFO VM is now online.');
console.log(hostname);
console.log(data.addresses[0]);
isonline = true;
})
24 changes: 23 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,33 @@ parser.command('create')
.help('creates the vm image')

parser.command('launch')
.callback(function () {
.options({
verbose: {
abbr: 'v',
flag: true,
help: "Show VBoxManage output."
}
})
.callback(function (opt) {
module.verbose = opt.verbose;
require('./run');
})
.help('launches the vm for testing')

parser.command('halt')
.options({
verbose: {
abbr: 'v',
flag: true,
help: "show vboxheadless output"
}
})
.callback(function (opt) {
module.verbose = opt.verbose;
require('./halt');
})
.help('halts the vm')

parser.command('run')
.callback(function () {
console.error('DEPRECATED: Use the command "t2-vm launch" instead.');
Expand Down
11 changes: 9 additions & 2 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,28 @@ setTimeout(function () {
}, 60*1000)

console.log('INFO Booting VM (may take up to a minute)...');
var p = etc.startvm(etc.VM_NAME);
var p = etc.startvm(etc.VM_NAME, module.parent.verbose);
p.stdout.pipe(concat(function (data) {
if (module.parent.verbose)
console.log(data.toString());
if (data.toString().match(/invalid machine name/i)) {
console.error('ERR No VM exists. Run t2-vm create first.')
process.exit(1);
}
}))
p.stderr.pipe(concat(function(data) {
if (module.parent.verbose)
console.log(data.toString());
}))
p.on('exit', function () {
console.log('INFO VM terminated.');
process.exit();
})

console.log("Seeking the device ...");
etc.seekDevice(hostname, function (err, data) {
console.error('INFO VM is now online.');
console.log(hostname);
console.log(data.addresses[0]);
isonline = true;
})

0 comments on commit 018abef

Please sign in to comment.