Merge pull request #1300 from docker/fix-vtx-exec

Dont track VTX as an error & fix bugs relating to exec on windows
This commit is contained in:
Jeffrey Morgan 2015-12-13 18:21:19 -08:00
commit fe50b66c88
5 changed files with 39 additions and 53 deletions

View File

@ -2,7 +2,6 @@ import React from 'react/addons';
import remote from 'remote'; import remote from 'remote';
import RetinaImage from 'react-retina-image'; import RetinaImage from 'react-retina-image';
import ipc from 'ipc'; import ipc from 'ipc';
var autoUpdater = remote.require('auto-updater');
import util from '../utils/Util'; import util from '../utils/Util';
import metrics from '../utils/MetricsUtil'; import metrics from '../utils/MetricsUtil';
var Menu = remote.require('menu'); var Menu = remote.require('menu');
@ -32,7 +31,6 @@ var Header = React.createClass({
updateAvailable: true updateAvailable: true
}); });
}); });
autoUpdater.checkForUpdates();
}, },
componentWillUnmount: function () { componentWillUnmount: function () {
document.removeEventListener('keyup', this.handleDocumentKeyUp, false); document.removeEventListener('keyup', this.handleDocumentKeyUp, false);

View File

@ -22,7 +22,7 @@ var DockerMachine = {
return fs.existsSync(this.command()); return fs.existsSync(this.command());
}, },
version: function () { version: function () {
return util.exec([this.command(), '-v']).then(stdout => { return util.execFile([this.command(), '-v']).then(stdout => {
try { try {
var matchlist = stdout.match(/(\d+\.\d+\.\d+).*/); var matchlist = stdout.match(/(\d+\.\d+\.\d+).*/);
if (!matchlist || matchlist.length < 2) { if (!matchlist || matchlist.length < 2) {
@ -57,40 +57,40 @@ var DockerMachine = {
}); });
}, },
create: function (machineName = this.name()) { create: function (machineName = this.name()) {
return util.exec([this.command(), '-D', 'create', '-d', 'virtualbox', '--virtualbox-memory', '2048', machineName]); return util.execFile([this.command(), '-D', 'create', '-d', 'virtualbox', '--virtualbox-memory', '2048', machineName]);
}, },
start: function (machineName = this.name()) { start: function (machineName = this.name()) {
return util.exec([this.command(), '-D', 'start', machineName]); return util.execFile([this.command(), '-D', 'start', machineName]);
}, },
stop: function (machineName = this.name()) { stop: function (machineName = this.name()) {
return util.exec([this.command(), 'stop', machineName]); return util.execFile([this.command(), 'stop', machineName]);
}, },
upgrade: function (machineName = this.name()) { upgrade: function (machineName = this.name()) {
return util.exec([this.command(), 'upgrade', machineName]); return util.execFile([this.command(), 'upgrade', machineName]);
}, },
rm: function (machineName = this.name()) { rm: function (machineName = this.name()) {
return util.exec([this.command(), 'rm', '-f', machineName]); return util.execFile([this.command(), 'rm', '-f', machineName]);
}, },
ip: function (machineName = this.name()) { ip: function (machineName = this.name()) {
return util.exec([this.command(), 'ip', machineName]).then(stdout => { return util.execFile([this.command(), 'ip', machineName]).then(stdout => {
return Promise.resolve(stdout.trim().replace('\n', '')); return Promise.resolve(stdout.trim().replace('\n', ''));
}); });
}, },
url: function (machineName = this.name()) { url: function (machineName = this.name()) {
return util.exec([this.command(), 'url', machineName]).then(stdout => { return util.execFile([this.command(), 'url', machineName]).then(stdout => {
return Promise.resolve(stdout.trim().replace('\n', '')); return Promise.resolve(stdout.trim().replace('\n', ''));
}); });
}, },
regenerateCerts: function (machineName = this.name()) { regenerateCerts: function (machineName = this.name()) {
return util.exec([this.command(), 'tls-regenerate-certs', '-f', machineName]); return util.execFile([this.command(), 'tls-regenerate-certs', '-f', machineName]);
}, },
status: function (machineName = this.name()) { status: function (machineName = this.name()) {
return util.exec([this.command(), 'status', machineName]).then(stdout => { return util.execFile([this.command(), 'status', machineName]).then(stdout => {
return Promise.resolve(stdout.trim().replace('\n', '')); return Promise.resolve(stdout.trim().replace('\n', ''));
}); });
}, },
disk: function (machineName = this.name()) { disk: function (machineName = this.name()) {
return util.exec([this.command(), 'ssh', machineName, 'df']).then(stdout => { return util.execFile([this.command(), 'ssh', machineName, 'df']).then(stdout => {
try { try {
var lines = stdout.split('\n'); var lines = stdout.split('\n');
var dataline = _.find(lines, function (line) { var dataline = _.find(lines, function (line) {
@ -114,7 +114,7 @@ var DockerMachine = {
}); });
}, },
memory: function (machineName = this.name()) { memory: function (machineName = this.name()) {
return util.exec([this.command(), 'ssh', machineName, 'free -m']).then(stdout => { return util.execFile([this.command(), 'ssh', machineName, 'free -m']).then(stdout => {
try { try {
var lines = stdout.split('\n'); var lines = stdout.split('\n');
var dataline = _.find(lines, function (line) { var dataline = _.find(lines, function (line) {
@ -155,11 +155,11 @@ var DockerMachine = {
cmd = cmd || process.env.SHELL; cmd = cmd || process.env.SHELL;
var terminal = util.linuxTerminal(); var terminal = util.linuxTerminal();
if (terminal) if (terminal)
util.exec(terminal.concat([cmd])).then(() => {}); util.execFile(terminal.concat([cmd])).then(() => {});
} else { } else {
cmd = cmd || process.env.SHELL; cmd = cmd || process.env.SHELL;
this.url(machineName).then(machineUrl => { this.url(machineName).then(machineUrl => {
util.exec([path.join(process.env.RESOURCES_PATH, 'terminal'), `DOCKER_HOST=${machineUrl} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machineName)} DOCKER_TLS_VERIFY=1 ${cmd}`]).then(() => {}); util.execFile([path.join(process.env.RESOURCES_PATH, 'terminal'), `DOCKER_HOST=${machineUrl} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machineName)} DOCKER_TLS_VERIFY=1 ${cmd}`]).then(() => {});
}); });
} }
}, },

View File

@ -137,9 +137,9 @@ export default {
let tries = 80, ip = null; let tries = 80, ip = null;
while (!ip && tries > 0) { while (!ip && tries > 0) {
try { try {
tries -= 1;
console.log('Trying to fetch machine IP, tries left: ' + tries); console.log('Trying to fetch machine IP, tries left: ' + tries);
ip = await machine.ip(); ip = await machine.ip();
tries -= 1;
await Promise.delay(1000); await Promise.delay(1000);
} catch (err) {} } catch (err) {}
} }
@ -153,11 +153,12 @@ export default {
break; break;
} catch (error) { } catch (error) {
router.get().transitionTo('setup'); router.get().transitionTo('setup');
metrics.track('Setup Failed', {
let novtx = error.message.indexOf('This computer doesn\'t have VT-X/AMD-v enabled') !== -1;
metrics.track(novtx ? 'Setup Halted' : 'Setup Failed', {
virtualBoxVersion, virtualBoxVersion,
machineVersion machineVersion
}); });
setupServerActions.error({error});
let message = error.message.split('\n'); let message = error.message.split('\n');
let lastLine = message.length > 1 ? message[message.length - 2] : 'Docker Machine encountered an error.'; let lastLine = message.length > 1 ? message[message.length - 2] : 'Docker Machine encountered an error.';
@ -170,6 +171,8 @@ export default {
groupingHash: machineVersion groupingHash: machineVersion
}, 'info'); }, 'info');
setupServerActions.error({error: new Error(lastLine)});
this.clearTimers(); this.clearTimers();
await this.pause(); await this.pause();
} }

View File

@ -8,20 +8,20 @@ var dialog = remote.require('dialog');
var app = remote.require('app'); var app = remote.require('app');
module.exports = { module.exports = {
exec: function (args, options) { execFile: function (args, options) {
options = options || {};
// Add resources dir to exec path for Windows
if (this.isWindows()) {
options.env = options.env || {};
if (!options.env.PATH) {
options.env.PATH = process.env.RESOURCES_PATH + ';' + process.env.PATH;
}
}
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
var cmd = Array.isArray(args) ? args.join(' ') : args; child_process.execFile(args[0], args.slice(1), options, (error, stdout, stderr) => {
child_process.exec(cmd, options, (error, stdout, stderr) => { if (error) {
reject(new Error('Encountered an error: ' + error));
} else {
resolve(stdout);
}
});
});
},
exec: function (args, options) {
return new Promise((resolve, reject) => {
child_process.exec(args, options, (error, stdout, stderr) => {
if (error) { if (error) {
reject(new Error('Encountered an error: ' + error)); reject(new Error('Encountered an error: ' + error));
} else { } else {

View File

@ -16,13 +16,16 @@ var VirtualBox = {
} }
}, },
installed: function () { installed: function () {
if (util.isWindows() && !process.env.VBOX_INSTALL_PATH && !process.env.VBOX_MSI_INSTALL_PATH) {
return false;
}
return fs.existsSync(this.command()); return fs.existsSync(this.command());
}, },
active: function () { active: function () {
return fs.existsSync('/dev/vboxnetctl'); return fs.existsSync('/dev/vboxnetctl');
}, },
version: function () { version: function () {
return util.exec([this.command(), '-v']).then(stdout => { return util.execFile([this.command(), '-v']).then(stdout => {
let matchlist = stdout.match(/(\d+\.\d+\.\d+).*/); let matchlist = stdout.match(/(\d+\.\d+\.\d+).*/);
if (!matchlist || matchlist.length < 2) { if (!matchlist || matchlist.length < 2) {
Promise.reject('VBoxManage -v output format not recognized.'); Promise.reject('VBoxManage -v output format not recognized.');
@ -32,29 +35,11 @@ var VirtualBox = {
return Promise.resolve(null); return Promise.resolve(null);
}); });
}, },
poweroffall: function () {
return util.exec(this.command() + ' list runningvms | sed -E \'s/.*\\{(.*)\\}/\\1/\' | xargs -L1 -I {} ' + this.command() + ' controlvm {} poweroff');
},
mountSharedDir: function (vmName, pathName, hostPath) { mountSharedDir: function (vmName, pathName, hostPath) {
return util.exec([this.command(), 'sharedfolder', 'add', vmName, '--name', pathName, '--hostpath', hostPath, '--automount']); return util.execFile([this.command(), 'sharedfolder', 'add', vmName, '--name', pathName, '--hostpath', hostPath, '--automount']);
},
killall: function () {
if (util.isWindows()) {
return this.poweroffall().then(() => {
return util.exec(['powershell.exe', '\"get-process VBox* | stop-process\"']);
}).catch(() => {});
} else {
return this.poweroffall().then(() => {
return util.exec(['pkill', 'VirtualBox']);
}).then(() => {
return util.exec(['pkill', 'VBox']);
}).catch(() => {
});
}
}, },
vmExists: function (name) { vmExists: function (name) {
return util.exec([this.command(), 'showvminfo', name]).then(() => { return util.execFile([this.command(), 'showvminfo', name]).then(() => {
return true; return true;
}).catch((err) => { }).catch((err) => {
return false; return false;