|
@ -208,13 +208,48 @@ app.get('/getservicesstatus', (req, res, next) => { |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
function create_project(swarmlabname,project){ |
|
|
|
|
|
|
|
|
|
|
|
var services_path = './instance/'+swarmlabname+'/'+project |
|
|
|
|
|
fs.mkdir(services_path, { recursive: true }, (err) => { |
|
|
|
|
|
|
|
|
|
|
|
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec create' |
|
|
|
|
|
create = spawn(service_up, { |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: services_path, |
|
|
|
|
|
//detached: true,
|
|
|
|
|
|
detached: false, |
|
|
|
|
|
//stdio: [ 'ignore', logout, logerr ]
|
|
|
|
|
|
stdio: 'pipe' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
create.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('message_out', n); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
create.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('message_err', n); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
create.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let child = []; |
|
|
let child = []; |
|
|
var ppid = '' |
|
|
var ppid = '' |
|
|
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') |
|
|
console.log('value '+JSON.stringify(value)) |
|
|
console.log('value '+JSON.stringify(value)) |
|
|
if(value.swarmlabname){ |
|
|
if(value.swarmlabname){ |
|
|
var service = value.swarmlabname |
|
|
var service = value.swarmlabname |
|
@ -241,8 +276,11 @@ REGISTRY_ADDR=localhost |
|
|
REGISTRY_PORT=5000 |
|
|
REGISTRY_PORT=5000 |
|
|
IMAGE_NAME=${service} |
|
|
IMAGE_NAME=${service} |
|
|
SSH_PORT=${service_port} |
|
|
SSH_PORT=${service_port} |
|
|
|
|
|
TEST=${service} |
|
|
` |
|
|
` |
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file); |
|
|
console.log('value1 '+JSON.stringify(ENV_service_file_path)) |
|
|
|
|
|
console.log('value2 '+JSON.stringify(ENV_service_file)) |
|
|
|
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file ,{encoding:'utf8',flag:'w'}); |
|
|
|
|
|
|
|
|
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size |
|
|
var service_up = '/bin/bash ../install/usr/share/swarmlab.io/sec/swarmlab-sec up size='+service_size |
|
|
|
|
|
|
|
@ -311,12 +349,38 @@ SSH_PORT=${service_port} |
|
|
|
|
|
|
|
|
socket.on('install', (value) => { |
|
|
socket.on('install', (value) => { |
|
|
if(value.swarmlabname){ |
|
|
if(value.swarmlabname){ |
|
|
|
|
|
console.log('install') |
|
|
var service = value.swarmlabname |
|
|
var service = value.swarmlabname |
|
|
var service_git = value.git |
|
|
var service_git = value.git |
|
|
var services_path = './instance/'+service |
|
|
var services_path = './instance/'+service |
|
|
var ENV_service_dir = services_path+'/'+service |
|
|
var ENV_service_dir = services_path+'/'+service |
|
|
var ENV_service_file_path = services_path+'/'+service+'/'.env |
|
|
var ENV_service_file_path = services_path+'/'+service+'/'.env |
|
|
if (fs.existsSync(services_path)) { |
|
|
if (fs.existsSync(services_path)) { |
|
|
|
|
|
const git = simpleGit( |
|
|
|
|
|
{ |
|
|
|
|
|
baseDir: services_path, |
|
|
|
|
|
maxConcurrentProcesses: 10 |
|
|
|
|
|
}); |
|
|
|
|
|
try { |
|
|
|
|
|
git.pull() |
|
|
|
|
|
.then((status) => { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = 'Updated' |
|
|
|
|
|
io.emit('message_out', n); |
|
|
|
|
|
n.data = '...' |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
create_project(service,service) |
|
|
|
|
|
}).catch((err) => { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = err.toString() |
|
|
|
|
|
io.emit('message_err', n); |
|
|
|
|
|
console.log('error ' + JSON.stringify(err)) |
|
|
|
|
|
}); |
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = e.toString() |
|
|
|
|
|
io.emit('message_err', n); |
|
|
|
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
fs.mkdir(services_path, { recursive: true }, (err) => { |
|
|
fs.mkdir(services_path, { recursive: true }, (err) => { |
|
|
if (err){ |
|
|
if (err){ |
|
@ -326,27 +390,28 @@ SSH_PORT=${service_port} |
|
|
REGISTRY_ADDR=localhost |
|
|
REGISTRY_ADDR=localhost |
|
|
REGISTRY_PORT=5000 |
|
|
REGISTRY_PORT=5000 |
|
|
IMAGE_NAME=${service} |
|
|
IMAGE_NAME=${service} |
|
|
SSH_PORT=${service_port} |
|
|
SSH_PORT= |
|
|
` |
|
|
` |
|
|
/* |
|
|
const git = simpleGit( |
|
|
const options: SimpleGitOptions = { |
|
|
{ |
|
|
baseDir: process.cwd(), |
|
|
baseDir: '.', |
|
|
binary: 'git', |
|
|
maxConcurrentProcesses: 10 |
|
|
maxConcurrentProcesses: 6, |
|
|
}); |
|
|
}; |
|
|
|
|
|
*/ |
|
|
|
|
|
const git = simpleGit() |
|
|
|
|
|
try { |
|
|
try { |
|
|
git.init(); |
|
|
git.clone(service_git, services_path) |
|
|
git.addRemote('origin', service_git).then(result => { |
|
|
.then((status) => { |
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = result.toString() |
|
|
n.data = 'Installed' |
|
|
io.emit('message_out', n); |
|
|
io.emit('message_out', n); |
|
|
}); |
|
|
n.data = '...' |
|
|
git.clone(service_git, services_path).then(result => { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = result.toString() |
|
|
|
|
|
io.emit('message_out', n); |
|
|
io.emit('message_out', n); |
|
|
|
|
|
fs.writeFileSync(ENV_service_file_path, ENV_service_file); |
|
|
|
|
|
create_project(service,service) |
|
|
|
|
|
}).catch((err) => { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = err.toString() |
|
|
|
|
|
io.emit('message_err', n); |
|
|
|
|
|
console.log('error ' + JSON.stringify(err)) |
|
|
}); |
|
|
}); |
|
|
} catch (e) { |
|
|
} catch (e) { |
|
|
var n = {} |
|
|
var n = {} |
|
@ -354,37 +419,13 @@ SSH_PORT=${service_port} |
|
|
io.emit('message_err', n); |
|
|
io.emit('message_err', n); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//fs.writeFileSync(ENV_service_file_path, ENV_service_file);
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
/* |
|
|
}else{ |
|
|
var services_path = './instance/'+service+'/'+service |
|
|
|
|
|
var containerrm = '/bin/sh ./container-stop.sh '+id |
|
|
|
|
|
const stop = spawn(containerrm, { |
|
|
|
|
|
stdio: 'pipe', |
|
|
|
|
|
shell: true, |
|
|
|
|
|
cwd: services_path |
|
|
|
|
|
}); |
|
|
|
|
|
stop.stdout.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = data.toString() |
|
|
|
|
|
io.emit('message_out', n); |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
stop.stderr.on('data', function (data) { |
|
|
|
|
|
var n = {} |
|
|
var n = {} |
|
|
n.data = data.toString() |
|
|
n.data = 'no services' |
|
|
io.emit('message_err', n); |
|
|
io.emit('message_err', n); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
stop.on('close', function (code) { |
|
|
|
|
|
var n = {} |
|
|
|
|
|
n.data = code |
|
|
|
|
|
io.emit('message_close', n); |
|
|
|
|
|
}); |
|
|
|
|
|
*/ |
|
|
|
|
|
}else{ |
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|