mirror of https://github.com/docker/docs.git
Merge pull request #63 from pengux/master
Added feature to start/stop apps
This commit is contained in:
commit
bd339c8f5c
|
@ -10,6 +10,5 @@ iron-router
|
|||
handlebar-helpers
|
||||
underscore-string-latest
|
||||
collection-helpers
|
||||
octicons
|
||||
fast-render
|
||||
iron-router-ga
|
||||
|
|
|
@ -47,6 +47,45 @@ AppUtil.restartHelper = function (app) {
|
|||
}
|
||||
};
|
||||
|
||||
AppUtil.start = function (appId) {
|
||||
var app = Apps.findOne(appId);
|
||||
if (app && app.docker) {
|
||||
Apps.update(app._id, {$set: {
|
||||
status: 'STARTING'
|
||||
}});
|
||||
Docker.getContainerData(app.docker.Id, function (err, data) {
|
||||
if (err) { console.error(err); }
|
||||
// Use dig to refresh the DNS
|
||||
exec('/usr/bin/dig ' + app.name + '.kite @172.17.42.1', function(err, stdout, stderr) {
|
||||
console.log(err);
|
||||
console.log(stdout);
|
||||
console.log(stderr);
|
||||
Apps.update(app._id, {$set: {
|
||||
status: 'READY',
|
||||
docker: data
|
||||
}});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
AppUtil.stop = function (appId) {
|
||||
var app = Apps.findOne(appId);
|
||||
if (app && app.docker) {
|
||||
Apps.update(app._id, {$set: {
|
||||
status: 'STOPPING'
|
||||
}});
|
||||
Docker.stopContainer(app.docker.Id, function (err) {
|
||||
if (err) { console.error(err); }
|
||||
Meteor.setTimeout(function () {
|
||||
Apps.update(app._id, {$set: {
|
||||
status: 'STOPPED'
|
||||
}});
|
||||
}, 2500);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
AppUtil.restart = function (appId) {
|
||||
var app = Apps.findOne(appId);
|
||||
if (app && app.docker) {
|
||||
|
@ -115,7 +154,7 @@ AppUtil.recover = function () {
|
|||
}
|
||||
var container = Docker.client().getContainer(app.docker.Id);
|
||||
container.inspect(function (err, data) {
|
||||
if (app.status !== 'STARTING' && data && data.State && !data.State.Running) {
|
||||
if (app.status !== 'STARTING' && app.status !== 'STOPPING' && app.status !== 'STOPPED' && data && data.State && !data.State.Running) {
|
||||
console.log('Restarting: ' + app.name);
|
||||
console.log(app.docker.Id);
|
||||
AppUtil.restartHelper(app, function (err) {
|
||||
|
|
|
@ -81,6 +81,32 @@ Docker.runContainer = function (app, image, callback) {
|
|||
});
|
||||
};
|
||||
|
||||
Docker.startContainer = function (containerId, callback) {
|
||||
var container = docker.getContainer(containerId);
|
||||
container.stop(function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
console.log('Started container: ' + containerId);
|
||||
callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Docker.stopContainer = function (containerId, callback) {
|
||||
var container = docker.getContainer(containerId);
|
||||
container.stop(function (err) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
callback(err);
|
||||
return;
|
||||
}
|
||||
console.log('Stopped container: ' + containerId);
|
||||
callback(null);
|
||||
});
|
||||
};
|
||||
|
||||
Docker.restartContainer = function (containerId, callback) {
|
||||
var container = docker.getContainer(containerId);
|
||||
container.restart(function (err) {
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
{{else}}
|
||||
{{#if $eq status 'STARTING'}}
|
||||
<span style="color: #D6D6D6;" class="status starting"><i class="fa fa-circle-o-notch fa-spin"></i></span>
|
||||
{{else}}
|
||||
{{#if $eq status 'STOPPING'}}
|
||||
<span style="color: #D6D6D6;" class="status stopping"><i class="fa fa-circle-o-notch fa-spin"></i></span>
|
||||
{{else}}
|
||||
{{#if $eq status 'ERROR'}}
|
||||
<span style="color: #F74B1F;" class="status"><i class="fa fa-circle-o"></i></span>
|
||||
|
@ -14,11 +17,16 @@
|
|||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<a onclick="trackLink('app detail')" href="/apps/{{name}}" class="name">{{name}}</a>
|
||||
<small><a onclick="trackLink('app image detail')" href="/images/{{image._id}}">{{image.meta.name}}</a></small>
|
||||
</h5>
|
||||
<div class="options">
|
||||
{{#if $eq status 'STOPPED'}}
|
||||
<a href="#" onclick="trackLink('start app')" class="btn-icon btn-start" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Start App"><span class="typcn typcn-media-play-outline"></span></a>
|
||||
{{/if}}
|
||||
{{#if $eq status 'READY'}}
|
||||
<a href="#" onclick="trackLink('stop app')" class="btn-icon btn-stop" target="_blank" data-toggle="tooltip" data-placement="bottom" title="Stop App"><span class="typcn typcn-media-stop"></span></a>
|
||||
{{#if url}}
|
||||
<a href="{{url}}" onclick="trackLink('view app')" class="btn-icon btn-view" target="_blank" data-toggle="tooltip" data-placement="bottom" title="View App"><span class="typcn typcn-eye-outline"></span></a>
|
||||
{{/if}}
|
||||
|
|
|
@ -32,6 +32,14 @@ Template.dashboard_single_app.events({
|
|||
}
|
||||
});
|
||||
},
|
||||
'click .btn-start': function () {
|
||||
AppUtil.start(this._id);
|
||||
$('.btn-icon').tooltip('hide');
|
||||
},
|
||||
'click .btn-stop': function () {
|
||||
AppUtil.stop(this._id);
|
||||
$('.btn-icon').tooltip('hide');
|
||||
},
|
||||
'click .btn-restart': function () {
|
||||
AppUtil.restart(this._id);
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue