new features log and bash
This commit is contained in:
@@ -5,6 +5,7 @@ module.exports = function() {
|
||||
module.connection = function(socket) {
|
||||
|
||||
//var sys = require('sys');
|
||||
var pty = require('pty.js');
|
||||
var proc = require('child_process');
|
||||
|
||||
console.log("new client");
|
||||
@@ -60,9 +61,7 @@ module.exports = function() {
|
||||
|
||||
function modify(cmd, name) {
|
||||
if (!name.match(/^[a-z0-9][-_:.+a-z0-9]*$/i))
|
||||
return fail("illegal instance name", {
|
||||
error: error, stderr: stderr, stdout: stdout
|
||||
});
|
||||
return fail("illegal instance name");
|
||||
exec("docker "+cmd+" "+name, updatecontainers);
|
||||
}
|
||||
|
||||
@@ -96,14 +95,62 @@ module.exports = function() {
|
||||
modify("rm", name);
|
||||
}
|
||||
|
||||
function logs(name) {
|
||||
console.log("-> logs("+name+")");
|
||||
var l = proc.spawn("docker", ["logs", "-f", name])
|
||||
.on('close', function(code) {
|
||||
emit('logs', {name: name, type: 'done'});
|
||||
});
|
||||
l.stdout.on('data', function(data) {
|
||||
emit('logs', {name: name, type: 'stdout', text: data.toString()});
|
||||
});
|
||||
l.stderr.on('data', function(data) {
|
||||
emit('logs', {name: name, type: 'stderr', text: data.toString()});
|
||||
});
|
||||
}
|
||||
|
||||
var bash_connections = {};
|
||||
|
||||
function bash_start(name) {
|
||||
console.log("-> bash-start("+name+")");
|
||||
if (!name.match(/^[a-z0-9][-_:.+a-z0-9]*$/i))
|
||||
return fail("illegal instance name");
|
||||
if (bash_connections[name]) return fail("bash already open");
|
||||
bash_connections[name] =
|
||||
pty.spawn("docker", ["exec", "-it", name, "bash", "-i"]);
|
||||
bash_connections[name].stdout.on('data', function(data) {
|
||||
emit('bash-data', {name: name, type: 'stdout', text: data.toString()});
|
||||
});
|
||||
// bash_connections[name].stderr.on('data', function(data) {
|
||||
// emit('bash-data', {name: name, type: 'stdout', text: data.toString()});
|
||||
// });
|
||||
}
|
||||
|
||||
function bash_input(data) {
|
||||
console.log("-> bash-input("+data.name+", "+data.text+")");
|
||||
if (!bash_connections[data.name]) return fail("bash not open");
|
||||
bash_connections[data.name].stdin.resume();
|
||||
bash_connections[data.name].stdin.write(data.text);
|
||||
}
|
||||
|
||||
// function bash_end(name, text) {
|
||||
// console.log("-> bash-end("+name+")");
|
||||
// if (!bash_connections[name]) return fail("bash not open");
|
||||
// bash_connections[name].stdin.close();
|
||||
// }
|
||||
|
||||
socket
|
||||
.on("containers", containers)
|
||||
.on("start", start)
|
||||
.on("stop", stop)
|
||||
.on("pause", pause)
|
||||
.on("unpause", unpause)
|
||||
.on("remove", remove);
|
||||
|
||||
.on("remove", remove)
|
||||
.on('logs', logs)
|
||||
.on('bash-start', bash_start)
|
||||
.on('bash-input', bash_input);
|
||||
//.on('bash-end', bash_end);
|
||||
|
||||
}
|
||||
|
||||
return module;
|
||||
|
Reference in New Issue
Block a user