|
@ -7,6 +7,8 @@ var app = express(); |
|
|
const cors = require('cors') |
|
|
const cors = require('cors') |
|
|
const helmet = require('helmet'); |
|
|
const helmet = require('helmet'); |
|
|
var MongoClient = require('mongodb').MongoClient; |
|
|
var MongoClient = require('mongodb').MongoClient; |
|
|
|
|
|
const yaml = require('js-yaml'); |
|
|
|
|
|
var mpath = require("path"); |
|
|
|
|
|
|
|
|
var allowedOrigins = [ |
|
|
var allowedOrigins = [ |
|
|
'http://localhost:3080', |
|
|
'http://localhost:3080', |
|
@ -713,6 +715,163 @@ app.get('/getwginterfacesstats', (req, res, next) => { |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.get('/dockerservices', (req, res, next) => { |
|
|
|
|
|
var RES = new Object(); |
|
|
|
|
|
const page = req.query["page"] |
|
|
|
|
|
const per_page = req.query["per_page"] |
|
|
|
|
|
var sort = req.query["sort"] |
|
|
|
|
|
var filter = req.query["filter"] |
|
|
|
|
|
var type = req.query["type"] |
|
|
|
|
|
var sort = req.query["sort"] |
|
|
|
|
|
var sorttmp1 = sort.split('|'); |
|
|
|
|
|
var sortname = sorttmp1[0]; |
|
|
|
|
|
var sortorder = sorttmp1[1]; |
|
|
|
|
|
var showexec = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s ` |
|
|
|
|
|
exec(showexec, (err, stdout, stderr) => { |
|
|
|
|
|
if (err) { |
|
|
|
|
|
console.error(`exec error: ${err}`); |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
var nn = [] |
|
|
|
|
|
var string = stdout.toString() |
|
|
|
|
|
var datajson = JSON.parse(string); |
|
|
|
|
|
|
|
|
|
|
|
var results1 = [] |
|
|
|
|
|
var grep1 = new RegExp('swlabadminvenus'); |
|
|
|
|
|
var datalenth = datajson.length |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!grep1.test(datajson[i]['Names'])){ |
|
|
|
|
|
results1.push(datajson[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
datajson=results1 |
|
|
|
|
|
var results2 = [] |
|
|
|
|
|
var grep2 = new RegExp('swlabmongovenus'); |
|
|
|
|
|
datalenth = datajson.length |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!grep2.test(datajson[i]['Names'])){ |
|
|
|
|
|
results2.push(datajson[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
datajson=results2 |
|
|
|
|
|
|
|
|
|
|
|
var results3 = [] |
|
|
|
|
|
var grep3 = new RegExp('swarmlabwg-'); |
|
|
|
|
|
datalenth = datajson.length |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!grep3.test(datajson[i]['Names'])){ |
|
|
|
|
|
results3.push(datajson[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
datajson=results3 |
|
|
|
|
|
|
|
|
|
|
|
var results4 = [] |
|
|
|
|
|
var grep4 = new RegExp('swarmlab-hybrid-agent'); |
|
|
|
|
|
datalenth = datajson.length |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(!grep4.test(datajson[i]['Names'])){ |
|
|
|
|
|
results4.push(datajson[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
datajson=results4 |
|
|
|
|
|
|
|
|
|
|
|
var results = [] |
|
|
|
|
|
if(filter !== 'NULL'){ |
|
|
|
|
|
var grep = new RegExp(filter); |
|
|
|
|
|
var datalenth = datajson.length |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(grep.test(datajson[i]['Names'])){ |
|
|
|
|
|
results.push(datajson[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
datajson=results |
|
|
|
|
|
} |
|
|
|
|
|
if(sortname == 'Names'){ |
|
|
|
|
|
datajson.sort(function (a, b) { |
|
|
|
|
|
if(sortorder == 'asc'){ |
|
|
|
|
|
return a.Names.localeCompare(b.Names); |
|
|
|
|
|
}else{ |
|
|
|
|
|
return b.Names.localeCompare(a.Names); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
}else if(sortname == 'Status'){ |
|
|
|
|
|
datajson.sort(function (a, b) { |
|
|
|
|
|
if(sortorder == 'asc'){ |
|
|
|
|
|
return a.Status.localeCompare(b.Status); |
|
|
|
|
|
}else{ |
|
|
|
|
|
return b.Status.localeCompare(a.Status); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
var resultid = [] |
|
|
|
|
|
var datalenth2 = datajson.length |
|
|
|
|
|
for (var i=0 ; i < datalenth2 ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
datajson[i].id=i |
|
|
|
|
|
datajson[i]._id=i |
|
|
|
|
|
resultid.push(datajson[i]); |
|
|
|
|
|
} |
|
|
|
|
|
datajson=resultid |
|
|
|
|
|
var total = datajson.length; |
|
|
|
|
|
var perpage = per_page |
|
|
|
|
|
var lastpage = total/perpage; |
|
|
|
|
|
|
|
|
|
|
|
if(lastpage <= 1) { |
|
|
|
|
|
lastpage=1 |
|
|
|
|
|
}else{ |
|
|
|
|
|
lastpage++ |
|
|
|
|
|
} |
|
|
|
|
|
lastpage = Math.trunc(lastpage); |
|
|
|
|
|
var next=(page+1); |
|
|
|
|
|
if(next >= lastpage){ |
|
|
|
|
|
next=lastpage; |
|
|
|
|
|
} |
|
|
|
|
|
var prev=(page-1); |
|
|
|
|
|
if(prev == 0){ |
|
|
|
|
|
prev=1; |
|
|
|
|
|
} |
|
|
|
|
|
var from=((page-1)*perpage)+1; |
|
|
|
|
|
var to=(perpage*page) |
|
|
|
|
|
var myplaybooks = new Object(); |
|
|
|
|
|
var links = ` |
|
|
|
|
|
{ |
|
|
|
|
|
"pagination": { |
|
|
|
|
|
"total": ${total}, |
|
|
|
|
|
"per_page": ${perpage}, |
|
|
|
|
|
"current_page": ${page}, |
|
|
|
|
|
"last_page": ${lastpage}, |
|
|
|
|
|
"next_page_url": "?page=${next}", |
|
|
|
|
|
"prev_page_url": "?page=${prev}", |
|
|
|
|
|
"from": ${from}, |
|
|
|
|
|
"to": ${to}, |
|
|
|
|
|
"frommongo": ${from}, |
|
|
|
|
|
"tomongo": ${to} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
` |
|
|
|
|
|
myplaybooks.links = JSON.parse(links); |
|
|
|
|
|
from-- |
|
|
|
|
|
myplaybooks.data = datajson.slice(from,to); |
|
|
|
|
|
var RES = new Object(); |
|
|
|
|
|
RES.code = req.query["action"] |
|
|
|
|
|
RES.token = req.query["token"] |
|
|
|
|
|
RES.error = false |
|
|
|
|
|
RES.error_msg = "ok" |
|
|
|
|
|
RES.data = myplaybooks; |
|
|
|
|
|
res.json(RES.data) |
|
|
|
|
|
}); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async function mywgStatus(){ |
|
|
async function mywgStatus(){ |
|
|
//var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8'))
|
|
|
//var mongoserver = JSON.parse(fs.readFileSync('./hybrid/venus-stats/config.json', 'utf8'))
|
|
|
var mypath = process.cwd() |
|
|
var mypath = process.cwd() |
|
@ -974,11 +1133,387 @@ setInterval(function(){ |
|
|
mywgRemoveClosedConnection() |
|
|
mywgRemoveClosedConnection() |
|
|
}, 45000) |
|
|
}, 45000) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
io.on('connection', function(socket) { |
|
|
io.on('connection', function(socket) { |
|
|
console.log('new connection'); |
|
|
console.log('new connection'); |
|
|
socket.on('start', (value) => { |
|
|
socket.on('start', (value) => { |
|
|
console.log('start'+ value); |
|
|
console.log('start'+ value); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
socket.on('share_app_info', (value) => { |
|
|
|
|
|
var service = {} |
|
|
|
|
|
var mypath = process.cwd() |
|
|
|
|
|
try { |
|
|
|
|
|
service.Name = value.Names |
|
|
|
|
|
console.log(JSON.stringify(value)); |
|
|
|
|
|
var showexec = `docker inspect --format '{{json .Config.Labels}}' ${service.Name}` |
|
|
|
|
|
log = spawn(showexec, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: mypath, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'data' |
|
|
|
|
|
n.exec = 'inspect' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
var interfaces = JSON.parse(n.data); |
|
|
|
|
|
io.emit('share_app_res', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'inspect' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('share_app_reserror', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'close' |
|
|
|
|
|
n.exec = 'inspect' |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('share_app_resclose', n); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var showexec1 = `docker ps --format '{"ID":"{{ .ID }}", "Image": "{{ .Image }}", "Names":"{{ .Names }}", "Ports":"{{.Ports}}", "Networks":"{{.Networks}}", "Status":"{{.Status}}","RunningFor":"{{.RunningFor}}","CreatedAt":"{{.CreatedAt}}"}' | jq . -s ` |
|
|
|
|
|
log1 = spawn(showexec1, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: mypath, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log1.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'data' |
|
|
|
|
|
n.exec = 'ps' |
|
|
|
|
|
var string = data.toString() |
|
|
|
|
|
var datajson = JSON.parse(string); |
|
|
|
|
|
|
|
|
|
|
|
var results = [] |
|
|
|
|
|
var filter = `swarmlabwg-` |
|
|
|
|
|
var grep = new RegExp(filter); |
|
|
|
|
|
var datalenth = datajson.length |
|
|
|
|
|
for (var i=0 ; i < datalenth ; i++) |
|
|
|
|
|
{ |
|
|
|
|
|
if(grep.test(datajson[i]['Names'])){ |
|
|
|
|
|
results.push(datajson[i]); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
n.data = results |
|
|
|
|
|
io.emit('share_app_res', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log1.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'ps' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('share_app_reserror', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log1.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'close' |
|
|
|
|
|
n.exec = 'ps' |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('share_app_resclose', n); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.log(err.stack || String(err)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
socket.on('share_app', (value) => { |
|
|
|
|
|
var service = {} |
|
|
|
|
|
var mypath = process.cwd() |
|
|
|
|
|
/* |
|
|
|
|
|
* value.c |
|
|
|
|
|
this.dockercompose.stack = 'com.docker.compose.project' |
|
|
|
|
|
this.dockercompose.service = 'com.docker.compose.service' |
|
|
|
|
|
this.dockercompose.file = 'com.docker.compose.project.config_files' |
|
|
|
|
|
this.dockercompose.env = 'com.docker.compose.project.environment_file' |
|
|
|
|
|
this.dockercompose.dir = 'com.docker.compose.project.working_dir' |
|
|
|
|
|
value.s [{"ID":"36be0c53c700","Image":"hub.swarmlab.io:5480/venus-alpine:latest","Names":"swarmlabwg-AcwtSX5hswT4pmObytxBjoCd4rDJMwB1","Ports":"80/tcp, 443/tcp, 8080/tcp, 8088/tcp, 51820/udp","Networks":"swlabAcwtSX5hsw","Status":"Up 35 minutes","RunningFor":"35 minutes ago","CreatedAt":"2021-05-26 13:21:08 +0300 EEST"}] |
|
|
|
|
|
value.n conatiner name |
|
|
|
|
|
*/ |
|
|
|
|
|
console.log(JSON.stringify(value)); |
|
|
|
|
|
try { |
|
|
|
|
|
service.Name = mpath.basename(value.c.file) |
|
|
|
|
|
service.Dir = value.c.dir |
|
|
|
|
|
service.stack = value.c.stack |
|
|
|
|
|
service.env = value.c.env |
|
|
|
|
|
service.service = value.c.service |
|
|
|
|
|
service.network = value.n |
|
|
|
|
|
|
|
|
|
|
|
console.log(JSON.stringify(value.c.statck)); |
|
|
|
|
|
if(value.c.stack){ |
|
|
|
|
|
var filename1 = service.Dir+"/"+service.stack+'_'+service.service+"-venus.yml" |
|
|
|
|
|
var filenamedefault = service.Dir+"/"+service.stack+'_'+service.service+"-venus-default.yml" |
|
|
|
|
|
var filenameyaml = service.Dir+"/"+service.Name |
|
|
|
|
|
var contents = fs.readFileSync(filenameyaml, 'utf8') |
|
|
|
|
|
var yamldata = yaml.load(contents) |
|
|
|
|
|
fs.exists(filenamedefault, (exists) => { |
|
|
|
|
|
if(exists){ |
|
|
|
|
|
}else{ |
|
|
|
|
|
fs.copyFile(filenameyaml, filenamedefault, (err) => { |
|
|
|
|
|
if (err){ |
|
|
|
|
|
console.log('source.txt was not copied to '+ filenamedefault); |
|
|
|
|
|
} |
|
|
|
|
|
console.log('source.txt was copied to '+ filenamedefault); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
console.log(JSON.stringify(yamldata)); |
|
|
|
|
|
|
|
|
|
|
|
delete yamldata.services[service.service].ports |
|
|
|
|
|
delete yamldata.services[service.service].networks |
|
|
|
|
|
//yamldata.services[service.service].network_mode: "service:masternfsserver"
|
|
|
|
|
|
yamldata.services[service.service].network_mode = "container:"+service.network |
|
|
|
|
|
console.log(yamldata.services[service.service]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var yamldata_out = yaml.dump(yamldata, { |
|
|
|
|
|
'styles': { |
|
|
|
|
|
'!!null': '' // dump null as ~
|
|
|
|
|
|
//'!!null': 'canonical' // dump null as ~
|
|
|
|
|
|
}, |
|
|
|
|
|
'sortKeys': false // sort object keys
|
|
|
|
|
|
}); |
|
|
|
|
|
console.log(JSON.stringify(yamldata_out)); |
|
|
|
|
|
fs.writeFileSync(filename1, yamldata_out); |
|
|
|
|
|
//var showexec = `cd ${service.Dir}; docker-compose -f ${filename1} --project-directory ${service.Dir} --env-file ${service.env} up -d ${service.service}`
|
|
|
|
|
|
var showexec = `cd ${service.Dir}; docker-compose -f ${filename1} --project-directory ${service.Dir} up -d ${service.service}` |
|
|
|
|
|
console.log(showexec); |
|
|
|
|
|
log = spawn(showexec, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: service.Dir, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'data' |
|
|
|
|
|
n.exec = 'share' |
|
|
|
|
|
n.compose = 'yes' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('share_app_exec_res', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'share' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
n.compose = 'yes' |
|
|
|
|
|
io.emit('share_app_exec_reserror', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'close' |
|
|
|
|
|
n.exec = 'share' |
|
|
|
|
|
n.compose = 'yes' |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('share_app_exec_resclose', n); |
|
|
|
|
|
}); |
|
|
|
|
|
}else{ |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'close' |
|
|
|
|
|
n.exec = 'share' |
|
|
|
|
|
n.compose = 'no' |
|
|
|
|
|
n.data = 'nodata' |
|
|
|
|
|
io.emit('share_app_exec_resclose', n); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.log(err.stack || String(err)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
socket.on('share_app_default', (value) => { |
|
|
|
|
|
var service = {} |
|
|
|
|
|
var mypath = process.cwd() |
|
|
|
|
|
console.log(JSON.stringify(value)); |
|
|
|
|
|
try { |
|
|
|
|
|
service.Name = mpath.basename(value.c.file) |
|
|
|
|
|
service.Dir = value.c.dir |
|
|
|
|
|
service.stack = value.c.stack |
|
|
|
|
|
service.env = value.c.env |
|
|
|
|
|
service.service = value.c.service |
|
|
|
|
|
service.network = value.n |
|
|
|
|
|
|
|
|
|
|
|
if(value.c.stack){ |
|
|
|
|
|
var filenamedefault = service.Dir+"/"+service.stack+'_'+service.service+"-venus-default.yml" |
|
|
|
|
|
//var showexec = `docker-compose -f ${filenamedefault} --project-directory ${service.Dir} --env-file ${service.env} up -d ${service.service}`
|
|
|
|
|
|
var showexec = `cd ${service.Dir}; docker-compose -f ${filenamedefault} --project-directory ${service.Dir} up -d ${service.service}` |
|
|
|
|
|
console.log(showexec); |
|
|
|
|
|
log = spawn(showexec, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: service.Dir, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'data' |
|
|
|
|
|
n.exec = 'sharedefault' |
|
|
|
|
|
n.compose = 'yes' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('share_app_exec_res', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'sharedefault' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
n.compose = 'yes' |
|
|
|
|
|
io.emit('share_app_exec_reserror', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'close' |
|
|
|
|
|
n.exec = 'sharedefault' |
|
|
|
|
|
n.compose = 'yes' |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('share_app_exec_resclose', n); |
|
|
|
|
|
}); |
|
|
|
|
|
}else{ |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'close' |
|
|
|
|
|
n.exec = 'sharedefault' |
|
|
|
|
|
n.compose = 'no' |
|
|
|
|
|
n.data = 'nodata' |
|
|
|
|
|
io.emit('share_app_exec_resclose', n); |
|
|
|
|
|
} |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.log(err.stack || String(err)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
socket.on('container_info', (value) => { |
|
|
|
|
|
var service = {} |
|
|
|
|
|
var mypath = process.cwd() |
|
|
|
|
|
console.log(JSON.stringify(value)); |
|
|
|
|
|
console.log('-----------------------------------'); |
|
|
|
|
|
try { |
|
|
|
|
|
service.Name = mpath.basename(value.s.Names) |
|
|
|
|
|
service.Dir = value.c.dir |
|
|
|
|
|
var showexec = `docker inspect --format '{{json .HostConfig.NetworkMode}}' ${service.Name}` |
|
|
|
|
|
// ip --brief address show
|
|
|
|
|
|
//var showexec = `docker inspect --format '{{json .Config}}' ${service.Name}`
|
|
|
|
|
|
log = spawn(showexec, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: service.Dir, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'data' |
|
|
|
|
|
n.exec = 'info' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
n.data = n.data.replace(/(\r\n|\n|\r)/gm, ""); |
|
|
|
|
|
n.data = n.data.replace(/["']/g, ""); |
|
|
|
|
|
console.log(JSON.stringify(n.data)); |
|
|
|
|
|
var grep1a = new RegExp(/^container/); |
|
|
|
|
|
var grep1b = new RegExp(/^service/); |
|
|
|
|
|
if(grep1a.test(n.data) || grep1b.test(n.data)){ |
|
|
|
|
|
var ndata = n.data.replace(/["']/g, ""); |
|
|
|
|
|
var grepsplit = new RegExp(':'); |
|
|
|
|
|
if(grepsplit.test(ndata)){ // network_mode container
|
|
|
|
|
|
var split = ndata.split(":") |
|
|
|
|
|
var containername = split[1].replace(/(\r\n|\n|\r)/gm, ""); |
|
|
|
|
|
var showexec2 = `docker exec ${containername} /bin/sh -c "ip -j --brief address show"` |
|
|
|
|
|
//docker exec -it microservice-jupyter26_masterservice_1 /bin/sh -c "jupyter notebook list"
|
|
|
|
|
|
console.log(showexec2) |
|
|
|
|
|
log2 = spawn(showexec2, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: service.Dir, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log2.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'info' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
var nnn = 'yes1' |
|
|
|
|
|
var grepjupyter = new RegExp('microservice-jupyter'); |
|
|
|
|
|
if(grepjupyter.test(service.Name)){ |
|
|
|
|
|
var showexec3 = `docker exec ${service.Name} /bin/sh -c "cat /home/jovyan/.local/share/jupyter/runtime/nbserver-46.json"` |
|
|
|
|
|
log3 = spawn(showexec3, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: service.Dir, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log3.stdout.on('data', function (data) { |
|
|
|
|
|
var nn = {} |
|
|
|
|
|
nn.status = 'error' |
|
|
|
|
|
nn.exec = 'info' |
|
|
|
|
|
nn.data = n.data |
|
|
|
|
|
nn.jupyter = data.toString() |
|
|
|
|
|
console.log(nn) |
|
|
|
|
|
io.emit('container_info_res', nn); |
|
|
|
|
|
}); |
|
|
|
|
|
}else{ |
|
|
|
|
|
io.emit('container_info_res', n); |
|
|
|
|
|
console.log(n.data) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
log2.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'sharedefault' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
console.log(n.data) |
|
|
|
|
|
io.emit('container_info_reserror', n); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} else{ // network mode other
|
|
|
|
|
|
var grep2a = new RegExp(/^microservice-/); |
|
|
|
|
|
var grep2b = new RegExp(/^hybrid-/); |
|
|
|
|
|
if(grep2a.test(n.data) || grep2b.test(n.data)){ |
|
|
|
|
|
var showexec2 = `docker exec ${service.Name} /bin/sh -c "ip -j --brief address show"` |
|
|
|
|
|
log2 = spawn(showexec2, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: service.Dir, |
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
log2.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'info' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
console.log(n) |
|
|
|
|
|
io.emit('container_info_res', n); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//var showexec1 = `docker inspect --format '{{json .HostConfig.NetworkMode}}' ${service.Name}`
|
|
|
|
|
|
//io.emit('container_info_res', n);
|
|
|
|
|
|
}); |
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'error' |
|
|
|
|
|
n.exec = 'info' |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('container_info_reserror', n); |
|
|
|
|
|
}); |
|
|
|
|
|
log.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.status = 'close' |
|
|
|
|
|
n.exec = 'info' |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('container_info_resclose', n); |
|
|
|
|
|
}); |
|
|
|
|
|
} catch (err) { |
|
|
|
|
|
console.log(err.stack || String(err)); |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
server.listen(serverPort, function() { |
|
|
server.listen(serverPort, function() { |
|
|