diff --git a/build/actions/local/common.js b/build/actions/local/common.js index a6801592..be87c7af 100644 --- a/build/actions/local/common.js +++ b/build/actions/local/common.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.12.4 (function() { - var Docker, Promise, _, chalk, form; + var Docker, Promise, _, chalk, filterOutSupervisorContainer, form; Promise = require('bluebird'); @@ -12,15 +12,36 @@ chalk = require('chalk'); + filterOutSupervisorContainer = function(container) { + var i, len, name, ref; + ref = container.Names; + for (i = 0, len = ref.length; i < len; i++) { + name = ref[i]; + if (name.includes('resin_supervisor')) { + return false; + } + } + return true; + }; + module.exports = { - selectContainerFromDevice: Promise.method(function(deviceIp) { + filterOutSupervisorContainer: filterOutSupervisorContainer, + selectContainerFromDevice: Promise.method(function(deviceIp, filterSupervisor) { var docker; + if (filterSupervisor == null) { + filterSupervisor = false; + } docker = new Docker({ host: deviceIp, port: 2375 }); return docker.listContainersAsync({ all: true + }).filter(function(container) { + if (!filterSupervisor) { + return true; + } + return filterOutSupervisorContainer(container); }).then(function(containers) { if (_.isEmpty(containers)) { throw new Error("No containers found in " + deviceIp); diff --git a/build/actions/local/index.js b/build/actions/local/index.js index e40643cd..628b0b79 100644 --- a/build/actions/local/index.js +++ b/build/actions/local/index.js @@ -31,4 +31,6 @@ limitations under the License. exports.push = require('./push'); + exports.stop = require('./stop'); + }).call(this); diff --git a/build/actions/local/stop.js b/build/actions/local/stop.js new file mode 100644 index 00000000..e901e7eb --- /dev/null +++ b/build/actions/local/stop.js @@ -0,0 +1,80 @@ +// Generated by CoffeeScript 1.12.4 + +/* +Copyright 2017 Resin.io + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + */ + +(function() { + module.exports = { + signature: 'local stop [deviceIp]', + description: 'Stop a running container on a resinOS device', + help: '\nExamples:\n\n $ resin local stop\n $ resin local stop --app-name myapp\n $ resin local stop --all\n $ resin local stop 192.168.1.10\n $ resin local stop 192.168.1.10 --app-name myapp', + options: [ + { + signature: 'all', + boolean: true, + description: 'stop all containers' + }, { + signature: 'app-name', + parameter: 'name', + description: 'name of container to stop', + alias: 'a' + } + ], + action: function(params, options, done) { + var Promise, ResinLocalDockerUtils, chalk, config, filterOutSupervisorContainer, forms, ref, ref1, selectContainerFromDevice; + Promise = require('bluebird'); + chalk = require('chalk'); + ref = require('resin-sync'), forms = ref.forms, config = ref.config, ResinLocalDockerUtils = ref.ResinLocalDockerUtils; + ref1 = require('./common'), selectContainerFromDevice = ref1.selectContainerFromDevice, filterOutSupervisorContainer = ref1.filterOutSupervisorContainer; + return Promise["try"](function() { + if (params.deviceIp == null) { + return forms.selectLocalResinOsDevice(); + } + return params.deviceIp; + }).then((function(_this) { + return function(deviceIp) { + var ref2, ref3, ymlConfig; + _this.deviceIp = deviceIp; + _this.docker = new ResinLocalDockerUtils(_this.deviceIp); + if (options.all) { + return _this.docker.docker.listContainersAsync({ + all: false + }).filter(filterOutSupervisorContainer).then(function(containers) { + return Promise.map(containers, function(arg) { + var Id, Names; + Names = arg.Names, Id = arg.Id; + console.log(chalk.yellow.bold("* Stopping container " + Names[0])); + return _this.docker.stopContainer(Id); + }); + }); + } + ymlConfig = config.load(); + _this.appName = (ref2 = options['app-name']) != null ? ref2 : (ref3 = ymlConfig['local_resinos']) != null ? ref3['app-name'] : void 0; + return _this.docker.checkForRunningContainer(_this.appName).then(function(isRunning) { + if (!isRunning) { + return selectContainerFromDevice(_this.deviceIp, true); + } + console.log(chalk.yellow.bold("* Stopping container " + _this.appName)); + return _this.appName; + }).then(function(runningContainerName) { + return _this.docker.stopContainer(runningContainerName); + }); + }; + })(this)); + } + }; + +}).call(this); diff --git a/build/app.js b/build/app.js index 9032df5b..cbfd932c 100644 --- a/build/app.js +++ b/build/app.js @@ -170,6 +170,8 @@ limitations under the License. capitano.command(actions.local.scan); + capitano.command(actions.local.stop); + update.notify(); plugins.register(/^resin-plugin-(.+)$/).then(function() {