Fixing errors that occur when app has a space in the path

This commit is contained in:
Jeff Morgan 2014-11-29 19:04:10 -05:00
parent 5bf18383ea
commit ffaa2bc565
14 changed files with 67 additions and 69 deletions

View File

@ -182,6 +182,7 @@ AppUtil.sync = function (callback) {
} else {
status = 'ERROR';
}
var appObj = {
name: appName,
docker: container,
@ -190,6 +191,7 @@ AppUtil.sync = function (callback) {
path: appPath,
logs: [],
createdAt: new Date(),
imageId: Images.findOne({'docker.Id': container.Image})._id
};
if (container.HostConfig.Binds && container.HostConfig.Binds.length) {
appObj.volumesEnabled = true;

View File

@ -14,13 +14,15 @@ Boot2Docker.command = function () {
};
Boot2Docker.exec = function (command, callback) {
exec(Boot2Docker.command() + ' ' + command, function(stderr, stdout, code) {
var cmd = [Boot2Docker.command()];
cmd.push.apply(cmd, command);
exec(cmd, function(stderr, stdout, code) {
callback(stderr, stdout, code);
});
};
Boot2Docker.exists = function (callback) {
this.exec('info', function (stderr, stdout, code) {
this.exec(['info'], function (stderr, stdout, code) {
if (stderr) {
callback(null, false);
} else {
@ -30,7 +32,7 @@ Boot2Docker.exists = function (callback) {
};
Boot2Docker.stop = function (callback) {
this.exec('stop', function (stderr, stdout, code) {
this.exec(['stop'], function (stderr, stdout, code) {
if (code) {
callback(stderr);
} else {
@ -41,7 +43,7 @@ Boot2Docker.stop = function (callback) {
Boot2Docker.erase = function (callback) {
var VMFileLocation = path.join(Util.getHomePath(), 'VirtualBox\\ VMs/boot2docker-vm');
exec('rm -rf ' + VMFileLocation, function (stderr) {
exec(['rm', '-rf', VMFileLocation], function (stderr) {
callback(stderr);
});
};
@ -50,7 +52,7 @@ Boot2Docker.upgrade = function (callback) {
var self = this;
self.stop(function (stderr, stdout, code) {
if (code) {callback(stderr); return;}
self.exec('upgrade', function (stderr, stdout, code) {
self.exec(['upgrade'], function (stderr, stdout, code) {
if (code) {
callback(stderr);
} else {
@ -61,7 +63,7 @@ Boot2Docker.upgrade = function (callback) {
};
Boot2Docker.ip = function (callback) {
this.exec('ip', function (stderr, stdout, code) {
this.exec(['ip'], function (stderr, stdout, code) {
if (code) {
callback(stderr, null);
} else {
@ -70,22 +72,8 @@ Boot2Docker.ip = function (callback) {
});
};
Boot2Docker.portOpen = function (port, callback) {
this.exec('nc -vz 127.0.0.1 ' + port, function (stderr, stdout, code) {
});
};
Boot2Docker.setIp = function (ifname, ip, callback) {
Boot2Docker.exec('ssh "sudo ifconfig ' + ifname + ' ' + ip + ' netmask 255.255.255.0"', function (stderr, stdout) {
Boot2Docker.exec('ssh "sudo rm -rf /var/lib/boot2docker/tls/* && sudo /etc/init.d/docker restart"', function (stderr, stdout) {
callback(stderr);
});
});
};
Boot2Docker.init = function (callback) {
this.exec('init', function (stderr, stdout, code) {
this.exec(['init'], function (stderr, stdout, code) {
if (code) {
callback(stderr);
} else {
@ -101,7 +89,7 @@ Boot2Docker.start = function (callback) {
callback('Cannot start if the boot2docker VM doesn\'t exist');
return;
}
self.exec('start', function (stderr, stdout, code) {
self.exec(['start'], function (stderr, stdout, code) {
if (code) {
callback(stderr);
} else {
@ -112,7 +100,7 @@ Boot2Docker.start = function (callback) {
};
Boot2Docker.state = function (callback) {
this.exec('info', function (stderr, stdout, code) {
this.exec(['info'], function (stderr, stdout, code) {
if (code) { callback(stderr, null); return; }
try {
var info = JSON.parse(stdout);
@ -124,7 +112,7 @@ Boot2Docker.state = function (callback) {
};
Boot2Docker.diskUsage = function (callback) {
this.exec('ssh "df"', function (stderr, stdout, code) {
this.exec(['ssh', 'df'], function (stderr, stdout, code) {
if (code) {
callback(stderr, null);
return;
@ -153,7 +141,7 @@ Boot2Docker.diskUsage = function (callback) {
};
Boot2Docker.memoryUsage = function (callback) {
this.exec('ssh "free -m"', function (stderr, stdout, code) {
this.exec(['ssh', 'free -m'], function (stderr, stdout, code) {
if (code) {
callback(stderr, null);
return;
@ -216,7 +204,7 @@ Boot2Docker.sshKeyExists = function () {
};
Boot2Docker.version = function (callback) {
this.exec('version', function (stderr, stdout, code) {
this.exec(['version'], function (stderr, stdout, code) {
if (code) {
callback(stderr);
return;
@ -263,14 +251,14 @@ Boot2Docker.vmUpToDate = function (callback) {
};
Boot2Docker.status = function (callback) {
this.exec('status', function (stderr, stdout, code) {
this.exec(['status'], function (stderr, stdout, code) {
if (code) {callback(stderr); return;}
callback(null, stdout.trim());
});
};
Boot2Docker.portAvailable = function (port, protocol, callback) {
this.exec('ssh netstat -lntu | grep LISTEN | grep ' + protocol + ' | grep -c ":::' + port + '\\s"', function (stdout, stderr, code) {
this.exec(['ssh', 'netstat -lntu | grep LISTEN | grep ' + protocol + ' | grep -c ":::' + port + '\\s"'], function (stdout, stderr, code) {
if (stderr.trim() === '0') {
callback(true);
} else {

View File

@ -184,7 +184,7 @@ ImageUtil.build = function (image, callback) {
}
});
} catch (e) {
console.error(e);
// Ignore misc conversion errors
}
});
response.on('end', function () {
@ -197,7 +197,6 @@ ImageUtil.build = function (image, callback) {
}
var imageData = null;
Docker.getImageData(image.meta.name + ':' + image.meta.version, function (err, data) {
console.log(data);
if (err) {
console.error(err);
Images.update(image._id, {
@ -243,7 +242,7 @@ ImageUtil.remove = function (imageId) {
ImageUtil.sync = function (callback) {
Docker.listImages(function (err, dockerImages) {
if (err) {
console.error(err);
callback(err);
return;
}
var images = Images.find({}).fetch();
@ -254,7 +253,7 @@ ImageUtil.sync = function (callback) {
return image.docker.Id;
}
});
var daemonIds = _.map(daemonIds, function (image) {
var daemonIds = _.map(dockerImages, function (image) {
return image.Id;
});
var diffImages = _.difference(kitematicIds, daemonIds);
@ -319,6 +318,8 @@ ImageUtil.sync = function (callback) {
});
callback();
});
} else {
callback();
}
}, function (err) {
callback(err);

View File

@ -38,7 +38,6 @@ Router.map(function () {
return [Meteor.subscribe('apps'), Meteor.subscribe('images'), Meteor.subscribe('settings')];
},
action: function () {
Session.set('onIntro', true);
if (this.ready()) {
this.render();
Setup.run(function (err) {
@ -50,8 +49,10 @@ Router.map(function () {
if (!settings) {
Settings.insert({tracking: true});
}
Session.set('onIntro', false);
console.log('Starting boot2docker utilization monitor...');
startUpdatingBoot2DockerUtilization();
console.log('Starting CLI sync...');
startSyncingAppState();
Router.go('dashboard_apps');
}

View File

@ -78,7 +78,7 @@ Util.copyVolumes = function (directory, appName, callback) {
};
Util.createTarFile = function (sourcePath, destinationFile, callback) {
exec('tar czf ' + destinationFile + ' -C ' + sourcePath + ' .', function (err) {
exec(['tar', 'czf', destinationFile, '-C', sourcePath, '.'], function (err) {
if (err) {callback(err, null); return;}
console.log('Created tar file: ' + destinationFile);
callback(null, destinationFile);
@ -90,12 +90,11 @@ Util.hasDockerfile = function (directory) {
};
Util.openTerminal = function (command) {
var terminalCmd = path.join(Util.getBinDir(), 'terminal') + ' ' + command;
var exec = require('child_process').exec;
exec(terminalCmd, function (err, stdout) {
console.log(stdout);
if (err) {
console.log(err);
var cmd = [path.join(Util.getBinDir(), 'terminal')];
cmd.push.apply(cmd, command);
exec(cmd, function (stderr, stdout, code) {
if (code) {
console.log(stderr);
}
});
};

View File

@ -16,7 +16,7 @@ VirtualBox.installed = function () {
};
VirtualBox.exec = function (command, callback) {
exec('/usr/bin/VBoxManage ' + command, function (stderr, stdout, code) {
exec(['/usr/bin/VBoxManage', command], function (stderr, stdout, code) {
callback(stderr, stdout, code);
});
};

View File

@ -82,8 +82,8 @@ updateBoot2DockerUtilization = function (callback) {
if (stats.state !== 'poweroff' && stats.memory && stats.disk) {
Session.set('boot2dockerMemoryUsage', stats.memory);
Session.set('boot2dockerDiskUsage', stats.disk);
callback();
}
callback();
});
} else {
callback();
@ -95,7 +95,8 @@ updateBoot2DockerUtilization = function (callback) {
startUpdatingBoot2DockerUtilization = function () {
updateBoot2DockerUtilization(function (err) {
Meteor.setTimeout(updateBoot2DockerUtilization, 5000);
if (err) {console.log(err);}
Meteor.setTimeout(startUpdatingBoot2DockerUtilization, 2000);
});
};
@ -104,7 +105,7 @@ startSyncingAppState = function () {
if (err) {console.log(err);}
AppUtil.sync(function (err) {
if (err) {console.log(err);}
Meteor.setTimeout(startSyncingAppState, 5000);
Meteor.setTimeout(startSyncingAppState, 2000);
});
});
};

View File

@ -1,12 +1,12 @@
Template.dashboardSingleApp.events({
'click .btn-view-port': function (e) {
try {
var open = require('open');
var exec = require('exec');
e.preventDefault();
e.stopPropagation();
var $btn = $(e.currentTarget);
var url = $btn.attr('href');
open(url);
exec(['open', url]);
} catch (exception) {
console.log(exception);
}

View File

@ -60,7 +60,9 @@
{{#if $eq status 'STOPPED'}}
<a href="#" onclick="trackLink('start container')" class="btn-icon btn-start" data-toggle="tooltip" data-placement="bottom" title="Start"><span class="typcn typcn-media-play-outline"></span></a>
{{/if}}
{{#if $eq status 'READY'}}
<a href="#" onclick="trackLink('restart container')" class="btn-icon btn-restart" data-toggle="tooltip" data-placement="bottom" title="Restart"><span class="typcn typcn-refresh-outline"></span></a>
{{/if}}
<a href="/apps/{{name}}/logs" onclick="trackLink('container logs')" class="btn-icon btn-logs" data-toggle="tooltip" data-placement="bottom" title="Logs"><span class="typcn typcn-document-text"></span></a>
<a href="/apps/{{name}}/settings" onclick="trackLink('container settings')" class="btn-icon" data-toggle="tooltip" data-placement="bottom" title="Settings"><span class="typcn typcn-cog-outline"></span></a>
</div>

View File

@ -1,6 +1,6 @@
var remote = require('remote');
var dialog = remote.require('dialog');
var exec = require('child_process').exec;
var exec = require('exec');
var path = require('path');
Template.dashboardSingleApp.rendered = function () {
@ -22,19 +22,19 @@ Template.dashboardSingleApp.helpers({
Template.dashboardSingleApp.events({
'click .btn-view': function (e) {
try {
var open = require('open');
e.preventDefault();
e.stopPropagation();
var $btn = $(e.currentTarget);
var url = $btn.attr('href');
open(url);
exec(['open', url], function (err) {
if (err) { throw err; }
});
} catch (exception) {
console.log(exception);
}
},
'click .btn-terminal': function () {
var app = this;
var cmd = Boot2Docker.command() + ' ssh -t "sudo docker exec -i -t ' + app.docker.Id + ' bash"';
var cmd = [Boot2Docker.command(), 'ssh', '-t', 'sudo docker exec -i -t ' + this.docker.Id + ' bash'];
Util.openTerminal(cmd);
},
'click .btn-start': function (e) {
@ -62,19 +62,19 @@ Template.dashboardSingleApp.events({
var appPath = path.join(Util.KITE_PATH, app.name);
if (app.docker.Volumes.length) {
if (app.docker.Volumes[0].Value.indexOf(path.join(Util.getHomePath(), 'Kitematic')) !== -1) {
exec('open ' + appPath, function (err) {
if (err) { throw err; }
exec(['open', appPath], function (stderr, stdout, code) {
if (code) { throw stderr; }
});
return;
} else {
exec('open ' + app.docker.Volumes[0].Value, function (err) {
if (err) { throw err; }
exec(['open', app.docker.Volumes[0].Value], function (stderr, stdout, code) {
if (code) { throw stderr; }
});
return;
}
} else {
exec('open ' + appPath, function (err) {
if (err) { throw err; }
exec(['open', appPath], function (stderr, stdout, code) {
if (code) { throw stderr; }
});
}
};

View File

@ -1,3 +1,5 @@
var exec = require('exec');
Template.dashboardSingleImage.rendered = function () {
Meteor.setInterval(function () {
$('.btn-icon').tooltip();
@ -11,8 +13,7 @@ Template.dashboardSingleImage.events({
$('#image-picker').hide();
},
'click .btn-folder': function () {
var exec = require('child_process').exec;
exec('open ' + this.originPath, function (err) {
exec(['open', this.originPath], function (err) {
if (err) { throw err; }
});
},

View File

@ -22,7 +22,7 @@
{{/if}}
<a onclick="trackLink('open container folder')" href="#" class="btn-folder" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Folder" data-container="body"><span class="typcn typcn-folder-open"></span></a>
{{#if $eq status 'READY'}}
<a href="#" onclick="trackLink('stop container')" class="btn-icon btn-stop" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Stop"><span class="typcn typcn-media-pause-outline"></span></a>
<a href="#" onclick="trackLink('stop container')" class="btn-icon btn-stop" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Stop"><span class="typcn typcn-media-stop-outline"></span></a>
{{/if}}
{{#if $eq status 'STOPPED'}}
<a href="#" onclick="trackLink('start container')" class="btn-icon btn-start" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Start"><span class="typcn typcn-media-play-outline"></span></a>

View File

@ -1,3 +1,6 @@
var exec = require('exec');
var path = require('path');
Template.dashboardAppsLayout.rendered = function () {
Meteor.setInterval(function () {
$('.header .icons a').tooltip();
@ -7,12 +10,13 @@ Template.dashboardAppsLayout.rendered = function () {
Template.dashboardAppsLayout.events({
'click .btn-view': function (e) {
try {
var open = require('open');
e.preventDefault();
e.stopPropagation();
var $btn = $(e.currentTarget);
var url = $btn.attr('href');
open(url);
exec(['open', url], function (err) {
if (err) { throw err; }
});
} catch (exception) {
console.log(exception);
}
@ -24,16 +28,15 @@ Template.dashboardAppsLayout.events({
AppUtil.logs(this._id);
},
'click .btn-terminal': function () {
var cmd = Boot2Docker.command() + ' ssh -t "sudo docker-enter ' + this.docker.Id + '"';
var cmd = [Boot2Docker.command(), 'ssh', '-t', 'sudo docker exec -i -t ' + this.docker.Id + ' bash'];
Util.openTerminal(cmd);
},
'click .btn-restart': function () {
AppUtil.restart(this._id);
AppUtil.run(this, function (err) {});
},
'click .btn-folder': function () {
var exec = require('child_process').exec;
var appPath = path.join(Util.KITE_PATH, this.name);
exec('open ' + appPath, function (err) {
exec(['open', appPath], function (err) {
if (err) { throw err; }
});
},

View File

@ -11,8 +11,8 @@ Template.dashboardImagesLayout.events({
$('#image-picker').hide();
},
'click .btn-folder': function () {
var exec = require('child_process').exec;
exec('open ' + this.originPath, function (err) {
var exec = require('exec');
exec(['open', this.originPath], function (err) {
if (err) { throw err; }
});
},