|
@ -1516,25 +1516,94 @@ app.get('/runeditor', (req, res, next) => { |
|
|
RES.instance = req.query["instance"] |
|
|
RES.instance = req.query["instance"] |
|
|
RES.error = false |
|
|
RES.error = false |
|
|
RES.error_msg = "ok" |
|
|
RES.error_msg = "ok" |
|
|
RES.error_msg0 = "" |
|
|
|
|
|
RES.data = "All_services_are_running"; |
|
|
RES.data = "All_services_are_running"; |
|
|
var showexec = `./swarmlab_editor_service.sh ${RES.instance}` |
|
|
const apptest = require('express')(); |
|
|
var runpath = `.` |
|
|
var newport1 = '' |
|
|
var runpathfile = `./swarmlab_editor_service.sh` |
|
|
const servertest1 = apptest.listen(0, () => { |
|
|
|
|
|
servertest1.close(); |
|
|
|
|
|
}) |
|
|
|
|
|
newport1 = servertest1.address().port |
|
|
|
|
|
var showexec = `./swarmlab_editor_service.sh ${RES.instance} ${newport1}` |
|
|
|
|
|
//var runpath = `.`
|
|
|
|
|
|
//var runpathfile = `./swarmlab_editor_service.sh`
|
|
|
|
|
|
|
|
|
// console.log(runpath)
|
|
|
// console.log(runpath)
|
|
|
console.log(showexec) |
|
|
// console.log(showexec)
|
|
|
|
|
|
|
|
|
var buildoutdir = `${runpath}/logs/build-out.log` |
|
|
|
|
|
var builderrdir = `${runpath}/logs/build-out.log` |
|
|
log = spawn(showexec, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
//cwd: services_path,
|
|
|
|
|
|
detached: false, |
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('message_out', n); |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
//console.log('data')
|
|
|
|
|
|
|
|
|
|
|
|
var filter = `start:${RES.instance}` |
|
|
|
|
|
var grep = new RegExp(filter); |
|
|
|
|
|
if(grep.test(n.data)){ |
|
|
|
|
|
n.start = `${RES.instance}` |
|
|
|
|
|
n.port = `${newport1}` |
|
|
|
|
|
io.emit('message_exec_editor', n); |
|
|
|
|
|
|
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
//console.log('close')
|
|
|
|
|
|
io.emit('message_err', n); |
|
|
|
|
|
RES.error = false |
|
|
|
|
|
RES.error_msg = 'ok' |
|
|
|
|
|
RES.data = n.data |
|
|
|
|
|
RES.port = newport1 |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('message_err', n); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
log.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
|
|
|
|
|
|
//RES.error = false
|
|
|
|
|
|
//RES.error_msg = "ok"
|
|
|
|
|
|
//RES.data = code;
|
|
|
|
|
|
//res.json(RES)
|
|
|
|
|
|
/* |
|
|
|
|
|
RES.error = false |
|
|
|
|
|
RES.error_msg = 'no' |
|
|
|
|
|
RES.port = newport1 |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
*/ |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//var buildoutdir = `${runpath}/logs/build-out.log`
|
|
|
|
|
|
//var builderrdir = `${runpath}/logs/build-out.log`
|
|
|
//const buildout = fs.openSync(buildoutdir, 'a');
|
|
|
//const buildout = fs.openSync(buildoutdir, 'a');
|
|
|
//const builderr = fs.openSync(builderrdir, 'a');
|
|
|
//const builderr = fs.openSync(builderrdir, 'a');
|
|
|
|
|
|
/* |
|
|
try { |
|
|
try { |
|
|
const buildout = fs.openSync(buildoutdir, 'a'); |
|
|
//const buildout = fs.openSync(buildoutdir, 'a');
|
|
|
const builderr = fs.openSync(builderrdir, 'a'); |
|
|
//const builderr = fs.openSync(builderrdir, 'a');
|
|
|
|
|
|
|
|
|
var buildimage = `echo "EXEC PID: $$"; ${showexec}` |
|
|
var buildimage = `echo "EXEC PID: $$"; ${showexec}` |
|
|
//var buildimage = `echo "EXEC PID: $$"; docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"`
|
|
|
|
|
|
const run_buildimage = spawn(buildimage, { |
|
|
const run_buildimage = spawn(buildimage, { |
|
|
detached: true, |
|
|
detached: true, |
|
|
shell: true, |
|
|
shell: true, |
|
@ -1555,33 +1624,35 @@ try { |
|
|
n.data = 'If this fails, try:' |
|
|
n.data = 'If this fails, try:' |
|
|
io.emit('message_out', n); |
|
|
io.emit('message_out', n); |
|
|
|
|
|
|
|
|
var buildtmpexec = `${mypath1}/swarmlab_editor_service.sh ${RES.instance}` |
|
|
var buildtmpexec = `${mypath1}/swarmlab_editor_service.sh ${RES.instance} ${newport1}` |
|
|
//buildtmpexec = fs.readFileSync(runpathfile, {encoding:'utf8', flag:'r'});
|
|
|
|
|
|
|
|
|
|
|
|
//var buildtmpexec = `docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix microservice-firefox /bin/sh -c "firefox"`
|
|
|
|
|
|
|
|
|
|
|
|
n.data = buildtmpexec |
|
|
n.data = buildtmpexec |
|
|
io.emit('message_out', n); |
|
|
io.emit('message_out', n); |
|
|
|
|
|
|
|
|
|
|
|
n.data = 'close!' |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
|
|
|
|
|
|
n.start = `${RES.instance}` |
|
|
|
|
|
n.port = `${newport1}` |
|
|
|
|
|
io.emit('message_exec_editor', n); |
|
|
|
|
|
|
|
|
run_buildimage.on('exit', (data) => { |
|
|
run_buildimage.on('exit', (data) => { |
|
|
//console.log('exit '+data);
|
|
|
//console.log('exit '+data);
|
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = 'exit!' |
|
|
n.data = 'exit!' |
|
|
io.emit('message_close', n); |
|
|
io.emit('message_close', n); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
run_buildimage.on('close', (data) => { |
|
|
run_buildimage.on('close', (data) => { |
|
|
//console.log('close '+data);
|
|
|
//console.log('close '+data);
|
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = 'close!' |
|
|
n.data = `close!` |
|
|
io.emit('message_close', n); |
|
|
io.emit('message_close', n); |
|
|
|
|
|
|
|
|
n.name = `${RES.instance}` |
|
|
n.name = `${RES.instance}` |
|
|
n.dir = `${runpath}` |
|
|
n.dir = `${runpath}` |
|
|
io.emit('message_close_build', n); |
|
|
io.emit('message_close_build', n); |
|
|
RES.error = false |
|
|
|
|
|
RES.error_msg = 'no' |
|
|
|
|
|
RES.data = 'no' |
|
|
|
|
|
res.json(RES) |
|
|
|
|
|
}); |
|
|
}); |
|
|
console.log(run_buildimage.pid); |
|
|
console.log(run_buildimage.pid); |
|
|
run_buildimage.unref(); |
|
|
run_buildimage.unref(); |
|
@ -1592,6 +1663,7 @@ try { |
|
|
RES.data = 'no' |
|
|
RES.data = 'no' |
|
|
res.json(RES) |
|
|
res.json(RES) |
|
|
} |
|
|
} |
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -1788,12 +1860,14 @@ app.get('/getlogs', (req, res, next) => { |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = data.toString() |
|
|
n.data = data.toString() |
|
|
io.emit('message_out', n); |
|
|
io.emit('message_out', n); |
|
|
|
|
|
//console.log('logdata')
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
log.stderr.on('data', function (data) { |
|
|
log.stderr.on('data', function (data) { |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = data.toString() |
|
|
n.data = data.toString() |
|
|
io.emit('message_err', n); |
|
|
io.emit('message_err', n); |
|
|
|
|
|
//console.log('logdataerr')
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
log.on('close', function (code) { |
|
|
log.on('close', function (code) { |
|
@ -1804,6 +1878,7 @@ app.get('/getlogs', (req, res, next) => { |
|
|
RES.error_msg = "ok" |
|
|
RES.error_msg = "ok" |
|
|
RES.data = code; |
|
|
RES.data = code; |
|
|
res.json(RES) |
|
|
res.json(RES) |
|
|
|
|
|
//console.log('logdataclose')
|
|
|
}); |
|
|
}); |
|
|
/* |
|
|
/* |
|
|
exec(showexec, (err, stdout, stderr) => { |
|
|
exec(showexec, (err, stdout, stderr) => { |
|
|