diff --git a/meteor/client/lib/apputil.js b/meteor/client/lib/apputil.js index 9639c3f196..c3e9b19aaa 100644 --- a/meteor/client/lib/apputil.js +++ b/meteor/client/lib/apputil.js @@ -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; diff --git a/meteor/client/lib/boot2docker.js b/meteor/client/lib/boot2docker.js index f9e1fdc0df..36c44ad89d 100644 --- a/meteor/client/lib/boot2docker.js +++ b/meteor/client/lib/boot2docker.js @@ -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 { diff --git a/meteor/client/lib/imageutil.js b/meteor/client/lib/imageutil.js index edcf3713d6..ff4804b0d8 100644 --- a/meteor/client/lib/imageutil.js +++ b/meteor/client/lib/imageutil.js @@ -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); diff --git a/meteor/client/lib/router.js b/meteor/client/lib/router.js index 7c1ebb9063..401d8c96f7 100755 --- a/meteor/client/lib/router.js +++ b/meteor/client/lib/router.js @@ -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'); } diff --git a/meteor/client/lib/util.js b/meteor/client/lib/util.js index 8d8c54a33f..a1edeb2bc2 100755 --- a/meteor/client/lib/util.js +++ b/meteor/client/lib/util.js @@ -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); } }); }; diff --git a/meteor/client/lib/virtualbox.js b/meteor/client/lib/virtualbox.js index 39099cb87e..17ed9066a2 100644 --- a/meteor/client/lib/virtualbox.js +++ b/meteor/client/lib/virtualbox.js @@ -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); }); }; diff --git a/meteor/client/main.js b/meteor/client/main.js index 8b50603a96..d7414d568f 100755 --- a/meteor/client/main.js +++ b/meteor/client/main.js @@ -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); }); }); }; \ No newline at end of file diff --git a/meteor/client/views/dashboard/apps/dashboard-apps.ports.js b/meteor/client/views/dashboard/apps/dashboard-apps.ports.js index ec985d8603..7c0d4ee78e 100644 --- a/meteor/client/views/dashboard/apps/dashboard-apps.ports.js +++ b/meteor/client/views/dashboard/apps/dashboard-apps.ports.js @@ -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); } diff --git a/meteor/client/views/dashboard/apps/dashboard-single-app.html b/meteor/client/views/dashboard/apps/dashboard-single-app.html index e2bbe6eba7..bc383acfe5 100755 --- a/meteor/client/views/dashboard/apps/dashboard-single-app.html +++ b/meteor/client/views/dashboard/apps/dashboard-single-app.html @@ -60,7 +60,9 @@ {{#if $eq status 'STOPPED'}} {{/if}} + {{#if $eq status 'READY'}} + {{/if}} diff --git a/meteor/client/views/dashboard/apps/dashboard-single-app.js b/meteor/client/views/dashboard/apps/dashboard-single-app.js index e22467020c..6335295448 100755 --- a/meteor/client/views/dashboard/apps/dashboard-single-app.js +++ b/meteor/client/views/dashboard/apps/dashboard-single-app.js @@ -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; } }); } }; diff --git a/meteor/client/views/dashboard/images/dashboard-single-image.js b/meteor/client/views/dashboard/images/dashboard-single-image.js index 99ef0207f3..481420dced 100755 --- a/meteor/client/views/dashboard/images/dashboard-single-image.js +++ b/meteor/client/views/dashboard/images/dashboard-single-image.js @@ -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; } }); }, diff --git a/meteor/client/views/dashboard/layouts/dashboard-apps-layout.html b/meteor/client/views/dashboard/layouts/dashboard-apps-layout.html index 67e40418ff..796a5159a4 100755 --- a/meteor/client/views/dashboard/layouts/dashboard-apps-layout.html +++ b/meteor/client/views/dashboard/layouts/dashboard-apps-layout.html @@ -22,7 +22,7 @@ {{/if}} {{#if $eq status 'READY'}} - + {{/if}} {{#if $eq status 'STOPPED'}} diff --git a/meteor/client/views/dashboard/layouts/dashboard-apps-layout.js b/meteor/client/views/dashboard/layouts/dashboard-apps-layout.js index f1b46ab48a..033e923be5 100644 --- a/meteor/client/views/dashboard/layouts/dashboard-apps-layout.js +++ b/meteor/client/views/dashboard/layouts/dashboard-apps-layout.js @@ -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; } }); }, diff --git a/meteor/client/views/dashboard/layouts/dashboard-images-layout.js b/meteor/client/views/dashboard/layouts/dashboard-images-layout.js index d7e709624e..45dd30c0e5 100755 --- a/meteor/client/views/dashboard/layouts/dashboard-images-layout.js +++ b/meteor/client/views/dashboard/layouts/dashboard-images-layout.js @@ -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; } }); },