Fixing remaining installer bugs

This commit is contained in:
Jeff Morgan 2014-09-01 15:42:15 -07:00
parent b66bbc2c0d
commit ebfbdc4182
6 changed files with 63 additions and 60 deletions

View File

@ -81,6 +81,7 @@ Boot2Docker.start = function (callback) {
// Success as well // Success as well
if (!err || (err.indexOf('Waiting for VM to be started') !== -1 || err.indexOf('..........') !== -1)) { if (!err || (err.indexOf('Waiting for VM to be started') !== -1 || err.indexOf('..........') !== -1)) {
self.correct(function (err) { self.correct(function (err) {
if (err) { callback(err); return; }
self.injectUtilities(function (err) { self.injectUtilities(function (err) {
callback(err); callback(err);
}); });
@ -96,17 +97,14 @@ Boot2Docker.correct = function (callback) {
Boot2Docker.setIp('eth2', Boot2Docker.REQUIRED_IP, function(err) { Boot2Docker.setIp('eth2', Boot2Docker.REQUIRED_IP, function(err) {
if (err) { callback(err); return; } if (err) { callback(err); return; }
VirtualBox.removeDHCP(function (err) { VirtualBox.removeDHCP(function (err) {
callback(err); callback();
}); });
}); });
}; };
Boot2Docker.state = function (callback) { Boot2Docker.state = function (callback) {
this.exec('info', function (err, stdout) { this.exec('info', function (err, stdout, stderr) {
if (err) { if (err) { callback(err, null); return; }
callback(err, null);
return;
}
try { try {
var info = JSON.parse(stdout); var info = JSON.parse(stdout);
callback(null, info.State); callback(null, info.State);
@ -177,23 +175,21 @@ Boot2Docker.memoryUsage = function (callback) {
}; };
Boot2Docker.stats = function (callback) { Boot2Docker.stats = function (callback) {
this.state(function (err, state) { var self = this;
if (err) { self.state(function (err, state) {
callback(err, null); if (err) { callback(err, null); return; }
return;
}
if (state === 'poweroff') { if (state === 'poweroff') {
callback(null, {state: state}); callback(null, {state: state});
return; return;
} }
this.memoryUsage(function (err, mem) { self.memoryUsage(function (err, mem) {
if (err) { if (err) {
callback(null, {state: state}); callback(null, {state: state});
return; return;
} }
this.diskUsage(function (err, disk) { self.diskUsage(function (err, disk) {
if (err) { if (err) {
callback(null, {state: state}); callback(null, {state: state, memory: mem});
return; return;
} }
callback(null, { callback(null, {

View File

@ -24,7 +24,7 @@ Installer.steps = [
callback(err); callback(err);
return; return;
} }
var needsUpdate = Utilities.compareVersions(installedVersion, VirtualBox.REQUIRED_VERSION) < 0; var needsUpdate = Util.compareVersions(installedVersion, VirtualBox.REQUIRED_VERSION) < 0;
if (needsUpdate) { if (needsUpdate) {
VirtualBox.install(function (err) { VirtualBox.install(function (err) {
callback(err); callback(err);
@ -44,16 +44,14 @@ Installer.steps = [
{ {
run: function (callback) { run: function (callback) {
Boot2Docker.exists(function (err, exists) { Boot2Docker.exists(function (err, exists) {
if (err) { if (err) { callback(err); return; }
callback(err);
return;
}
if (!exists) { if (!exists) {
Boot2Docker.init(function (err) { Boot2Docker.init(function (err) {
callback(err); callback(err);
}); });
} else { } else {
Boot2Docker.stop(function (err) { Boot2Docker.stop(function (err) {
if (err) { callback(err); return; }
Boot2Docker.upgrade(function (err) { Boot2Docker.upgrade(function (err) {
callback(err); callback(err);
}); });
@ -66,24 +64,24 @@ Installer.steps = [
futureMessage: 'Set up the Boot2Docker VM(if required)' futureMessage: 'Set up the Boot2Docker VM(if required)'
}, },
// Set up the routing.
{ {
run: function (callback) { run: function (callback) {
VirtualBox.setupRouting('boot2docker-vm', function (err, ifname) { VirtualBox.addCustomHostAdapter('boot2docker-vm', function (err, ifname) {
callback(err); callback(err);
}); });
}, },
pastMessage: 'Container routing set up.', pastMessage: 'Added custom host adapter to the Boot2Docker VM',
message: 'Setting up container routing (root required).', message: 'Adding custom host adapter to the Boot2Docker VM',
subMessage: '(This may take a few minutes)', futureMessage: 'Add custom host adapter to the Boot2Docker VM'
futureMessage: 'Set up container routing to VM (root required).'
}, },
// Start the Kitematic VM // Start the Kitematic VM
{ {
run: function (callback) { run: function (callback) {
Boot2Docker.state(function (err, state) { Boot2Docker.state(function (err, state) {
if (err) { callback(err); return; }
if (state !== 'running') { if (state !== 'running') {
console.log('starting');
Boot2Docker.start(function (err) { Boot2Docker.start(function (err) {
callback(err); callback(err);
}); });
@ -96,10 +94,20 @@ Installer.steps = [
}, },
pastMessage: 'Started the Boot2Docker VM', pastMessage: 'Started the Boot2Docker VM',
message: 'Starting the Boot2Docker VM', message: 'Starting the Boot2Docker VM',
subMessage: '(This may take a few minutes)',
futureMessage: 'Start the Kitematic VM', futureMessage: 'Start the Kitematic VM',
}, },
{
run: function (callback) {
VirtualBox.setupRouting('boot2docker-vm', function (err, ifname) {
callback(err);
});
},
pastMessage: 'Container routing set up',
message: 'Setting up container routing (root required)',
futureMessage: 'Set up container routing to VM (root required)'
},
// Set up the default Kitematic images // Set up the default Kitematic images
{ {
run: function (callback) { run: function (callback) {

View File

@ -106,16 +106,12 @@ VirtualBox.hostOnlyAdapter = function (callback) {
if (!iface) { if (!iface) {
self.exec('hostonlyif create', function (err, stdout, stderr) { self.exec('hostonlyif create', function (err, stdout, stderr) {
var match = stdout.match(/Interface '(vboxnet\d+)' was successfully created/); var match = stdout.match(/Interface '(vboxnet\d+)' was successfully created/);
console.log(match);
if (!match) { if (!match) {
callback('Could not parse output of hostonlyif create'); callback('Could not parse output of hostonlyif create');
return; return;
} }
self.exec('hostonlyif ipconfig ' + match[1] + ' --ip ' + VirtualBox.HOSTONLY_HOSTIP + ' --netmask ' + VirtualBox.HOSTONLY_NETWORKMASK, function(err, stdout, stderr) { self.exec('hostonlyif ipconfig ' + match[1] + ' --ip ' + VirtualBox.HOSTONLY_HOSTIP + ' --netmask ' + VirtualBox.HOSTONLY_NETWORKMASK, function(err, stdout, stderr) {
if (err) { if (err) { callback(err); return; }
callback(err);
return;
}
callback(null, match[1]); callback(null, match[1]);
}); });
}); });
@ -128,10 +124,7 @@ VirtualBox.hostOnlyAdapter = function (callback) {
VirtualBox.addCustomHostAdapter = function (vm, callback) { VirtualBox.addCustomHostAdapter = function (vm, callback) {
var self = this; var self = this;
self.hostOnlyAdapter(function (err, ifname) { self.hostOnlyAdapter(function (err, ifname) {
if (err) { if (err) { callback(err); return; }
callback(err);
return;
}
self.exec('modifyvm ' + vm + ' --nic3 hostonly --nictype3 virtio --cableconnected3 on --hostonlyadapter3 ' + ifname, function (err, stdout, stderr) { self.exec('modifyvm ' + vm + ' --nic3 hostonly --nictype3 virtio --cableconnected3 on --hostonlyadapter3 ' + ifname, function (err, stdout, stderr) {
callback(err, ifname); callback(err, ifname);
}); });
@ -143,7 +136,7 @@ VirtualBox.setupRouting = function (vm, callback) {
this.addCustomHostAdapter(vm, function (err, ifname) { this.addCustomHostAdapter(vm, function (err, ifname) {
var installFile = path.join(Util.getBinDir(), 'install'); var installFile = path.join(Util.getBinDir(), 'install');
var cocoaSudo = path.join(Util.getBinDir(), 'cocoasudo'); var cocoaSudo = path.join(Util.getBinDir(), 'cocoasudo');
var execCommand = cocoaSudo + ' --prompt="Kitematic needs your password to allow routing *.dev requests to containers." ' + installFile; var execCommand = cocoaSudo + ' --prompt="Kitematic needs your password to allow routing *.kite requests to containers." ' + installFile;
exec(execCommand, {env: {IFNAME: ifname, GATEWAY: Boot2Docker.REQUIRED_IP}}, function (error, stdout, stderr) { exec(execCommand, {env: {IFNAME: ifname, GATEWAY: Boot2Docker.REQUIRED_IP}}, function (error, stdout, stderr) {
if (error) { if (error) {
callback(error); callback(error);

View File

@ -126,17 +126,17 @@ fixDefaultContainers = function (callback) {
Meteor.setInterval(function () { Meteor.setInterval(function () {
Boot2Docker.exists(function (err, exists) { Boot2Docker.exists(function (err, exists) {
if (err) { return; } if (err) { console.log(err); return; }
if (exists) { if (exists) {
Boot2Docker.state(function (err, state) { Boot2Docker.state(function (err, state) {
if (err) { return; } if (err) { console.log(err); return; }
Session.set('boot2dockerState', state);
if (state === 'running') { if (state === 'running') {
Boot2Docker.info(function (err, info) { Boot2Docker.stats(function (err, stats) {
if (err) { return; } if (err) { console.log(err); return; }
Session.set('boot2dockerState', info.state); if (stats.state !== 'poweroff' && stats.memory && stats.disk) {
if (info.state !== 'poweroff' && info.memory && info.disk) { Session.set('boot2dockerMemoryUsage', stats.memory);
Session.set('boot2dockerMemoryUsage', info.memory); Session.set('boot2dockerDiskUsage', stats.disk);
Session.set('boot2dockerDiskUsage', info.disk);
} }
}); });
} }
@ -148,6 +148,7 @@ Meteor.setInterval(function () {
Meteor.setInterval(function () { Meteor.setInterval(function () {
if (Installs.findOne()) { if (Installs.findOne()) {
resolveWatchers(function () {}); resolveWatchers(function () {});
if (!Session.get('boot2dockerOff')) {
fixBoot2DockerVM(function (err) { fixBoot2DockerVM(function (err) {
if (err) { console.log(err); return; } if (err) { console.log(err); return; }
Meteor.call('recoverApps'); Meteor.call('recoverApps');
@ -159,5 +160,6 @@ Meteor.setInterval(function () {
}); });
}); });
} }
}
}, 5000); }, 5000);

View File

@ -3,18 +3,22 @@ Template.dashboard_settings.events({
var $btn = $(e.currentTarget); var $btn = $(e.currentTarget);
$btn.html('Starting Boot2Docker...'); $btn.html('Starting Boot2Docker...');
$btn.attr("disabled", "disabled"); $btn.attr("disabled", "disabled");
//startFixInterval(); Session.set('boot2dockerOff', false);
startBoot2Docker(function (err) { Boot2Docker.start(function (err) {
if (err) { console.error(err); } if (err) {
console.log(err);
}
}); });
}, },
'click .btn-stop-boot2docker': function (e) { 'click .btn-stop-boot2docker': function (e) {
var $btn = $(e.currentTarget); var $btn = $(e.currentTarget);
$btn.html('Stopping Boot2Docker...'); $btn.html('Stopping Boot2Docker...');
$btn.attr("disabled", "disabled"); $btn.attr("disabled", "disabled");
stopFixInterval(); Session.set('boot2dockerOff', true);
stopBoot2Docker(function (err) { Boot2Docker.stop(function (err) {
if (err) { console.error(err); } if (err) {
console.log(err);
}
}); });
} }
}); });

View File

@ -1,13 +1,13 @@
#!/bin/sh #!/bin/sh
# This script must be run as root and sets up Mac OS X to route all .dev domains to the virtual box VM with the name # This script must be run as root and sets up Mac OS X to route all .kite domains to the virtual box VM with the name
# 'boot2docker-vm'. It does the following: # 'boot2docker-vm'. It does the following:
# 1) Adds a file under /etc/resolver/dev # 1) Adds a file under /etc/resolver/kite
# 2) Sets up a LaunchAgent for adding entries to the route table to route all requests to the Docker subnet (172.17.0.0/16) # 2) Sets up a LaunchAgent for adding entries to the route table to route all requests to the Docker subnet (172.17.0.0/16)
# And expects the $IFNAME variable to contain the interface on which to send traffic to the boot2docker VM. # And expects the $IFNAME variable to contain the interface on which to send traffic to the boot2docker VM.
mkdir -p /etc/resolver mkdir -p /etc/resolver
echo "nameserver 172.17.42.1" > /etc/resolver/dev echo "nameserver 172.17.42.1" > /etc/resolver/kite
DIR=$(dirname "$0") DIR=$(dirname "$0")
USER=`w -h | sort -u -t' ' -k1,1 | awk '{print $1}'` USER=`w -h | sort -u -t' ' -k1,1 | awk '{print $1}'`