|
|
@ -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 = []; |
|
|
|
var ppid = '' |
|
|
|
io.on('connection', function(socket) { |
|
|
|
console.log('new connection'); |
|
|
|
socket.on('start', (value) => { |
|
|
|
console.log('start') |
|
|
|
console.log('value '+JSON.stringify(value)) |
|
|
|
if(value.swarmlabname){ |
|
|
|
var service = value.swarmlabname |
|
|
@ -241,8 +276,11 @@ REGISTRY_ADDR=localhost |
|
|
|
REGISTRY_PORT=5000 |
|
|
|
IMAGE_NAME=${service} |
|
|
|
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 |
|
|
|
|
|
|
@ -311,12 +349,38 @@ SSH_PORT=${service_port} |
|
|
|
|
|
|
|
socket.on('install', (value) => { |
|
|
|
if(value.swarmlabname){ |
|
|
|
console.log('install') |
|
|
|
var service = value.swarmlabname |
|
|
|
var service_git = value.git |
|
|
|
var services_path = './instance/'+service |
|
|
|
var ENV_service_dir = services_path+'/'+service |
|
|
|
var ENV_service_file_path = services_path+'/'+service+'/'.env |
|
|
|
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{ |
|
|
|
fs.mkdir(services_path, { recursive: true }, (err) => { |
|
|
|
if (err){ |
|
|
@ -326,65 +390,42 @@ SSH_PORT=${service_port} |
|
|
|
REGISTRY_ADDR=localhost |
|
|
|
REGISTRY_PORT=5000 |
|
|
|
IMAGE_NAME=${service} |
|
|
|
SSH_PORT=${service_port} |
|
|
|
SSH_PORT= |
|
|
|
` |
|
|
|
/* |
|
|
|
const options: SimpleGitOptions = { |
|
|
|
baseDir: process.cwd(), |
|
|
|
binary: 'git', |
|
|
|
maxConcurrentProcesses: 6, |
|
|
|
}; |
|
|
|
*/ |
|
|
|
const git = simpleGit() |
|
|
|
const git = simpleGit( |
|
|
|
{ |
|
|
|
baseDir: '.', |
|
|
|
maxConcurrentProcesses: 10 |
|
|
|
}); |
|
|
|
try { |
|
|
|
git.init(); |
|
|
|
git.addRemote('origin', service_git).then(result => { |
|
|
|
var n = {} |
|
|
|
n.data = result.toString() |
|
|
|
io.emit('message_out', n); |
|
|
|
}); |
|
|
|
git.clone(service_git, services_path).then(result => { |
|
|
|
var n = {} |
|
|
|
n.data = result.toString() |
|
|
|
io.emit('message_out', n); |
|
|
|
}); |
|
|
|
git.clone(service_git, services_path) |
|
|
|
.then((status) => { |
|
|
|
var n = {} |
|
|
|
n.data = 'Installed' |
|
|
|
io.emit('message_out', n); |
|
|
|
n.data = '...' |
|
|
|
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) { |
|
|
|
var n = {} |
|
|
|
n.data = e.toString() |
|
|
|
io.emit('message_err', n); |
|
|
|
} |
|
|
|
|
|
|
|
//fs.writeFileSync(ENV_service_file_path, ENV_service_file);
|
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
/* |
|
|
|
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 = {} |
|
|
|
n.data = data.toString() |
|
|
|
io.emit('message_err', n); |
|
|
|
}); |
|
|
|
|
|
|
|
stop.on('close', function (code) { |
|
|
|
var n = {} |
|
|
|
n.data = code |
|
|
|
io.emit('message_close', n); |
|
|
|
}); |
|
|
|
*/ |
|
|
|
}else{ |
|
|
|
var n = {} |
|
|
|
n.data = 'no services' |
|
|
|
io.emit('message_err', n); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|