[IMP]ODSA Server : handle multi-databases
This commit is contained in:
parent
cce16b634b
commit
2bc4964e23
50
server.js
50
server.js
@ -53,6 +53,25 @@ const disconnect = (req, res) => {
|
|||||||
res.end(sendJSON(res, 200, 'OK, déconnecté !'));
|
res.end(sendJSON(res, 200, 'OK, déconnecté !'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const execCommand = (cmd, res) => {
|
||||||
|
if (sshConn) {
|
||||||
|
sshConn.exec(cmd, (err, stream) => {
|
||||||
|
if (err) throw err;
|
||||||
|
let std = '';
|
||||||
|
stream.on('close', function(code, signal) {
|
||||||
|
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
|
||||||
|
res.end(sendJSON(res, 200, std));
|
||||||
|
}).on('data', function(data) {
|
||||||
|
console.log('STDOUT: ' + data);
|
||||||
|
std += data;
|
||||||
|
}).stderr.on('data', function(data) {
|
||||||
|
console.log('STDERR: ' + data);
|
||||||
|
std += data;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const serverCommand = (req, res) => {
|
const serverCommand = (req, res) => {
|
||||||
let execCmd = 'cd ~/docker/hosts/*/ && ';
|
let execCmd = 'cd ~/docker/hosts/*/ && ';
|
||||||
switch (req.params.cmd) {
|
switch (req.params.cmd) {
|
||||||
@ -86,22 +105,7 @@ const serverCommand = (req, res) => {
|
|||||||
default:
|
default:
|
||||||
execCmd = '/bin/true';
|
execCmd = '/bin/true';
|
||||||
}
|
}
|
||||||
if (sshConn) {
|
execCommand(execCmd, res);
|
||||||
sshConn.exec(execCmd, (err, stream) => {
|
|
||||||
if (err) throw err;
|
|
||||||
let std = '';
|
|
||||||
stream.on('close', function(code, signal) {
|
|
||||||
console.log('Stream :: close :: code: ' + code + ', signal: ' + signal);
|
|
||||||
res.end(sendJSON(res, 200, std));
|
|
||||||
}).on('data', function(data) {
|
|
||||||
console.log('STDOUT: ' + data);
|
|
||||||
std += data;
|
|
||||||
}).stderr.on('data', function(data) {
|
|
||||||
console.log('STDERR: ' + data);
|
|
||||||
std += data;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const odooAction = (req, res) => {
|
const odooAction = (req, res) => {
|
||||||
@ -118,10 +122,13 @@ const odooAction = (req, res) => {
|
|||||||
// Install or update
|
// Install or update
|
||||||
odooCmd += (req.body.action == 'install') ? '-i ' : '-u ';
|
odooCmd += (req.body.action == 'install') ? '-i ' : '-u ';
|
||||||
odooCmd += req.body.modules;
|
odooCmd += req.body.modules;
|
||||||
// TODO: multi databases
|
const odooCmdCached = odooCmd;
|
||||||
if (req.body.databases.length == 1) {
|
// Handle multi databases
|
||||||
odooCmd += ' -d ' + req.body.databases[0];
|
odooCmd = [];
|
||||||
}
|
req.body.databases.forEach((dbname) => {
|
||||||
|
odooCmd.push(odooCmdCached + ' -d ' + dbname);
|
||||||
|
});
|
||||||
|
odooCmd = odooCmd.join(' && ');
|
||||||
if (req.body.stop) {
|
if (req.body.stop) {
|
||||||
execCmd += 'docker-compose stop golem && '
|
execCmd += 'docker-compose stop golem && '
|
||||||
execCmd += 'docker-compose run --rm golem bash -c \'bash genconf.sh && ' + odooCmd + '\' && ';
|
execCmd += 'docker-compose run --rm golem bash -c \'bash genconf.sh && ' + odooCmd + '\' && ';
|
||||||
@ -129,9 +136,8 @@ const odooAction = (req, res) => {
|
|||||||
} else {
|
} else {
|
||||||
execCmd += 'docker-compose exec golem bash -c \'' + odooCmd + '\'';
|
execCmd += 'docker-compose exec golem bash -c \'' + odooCmd + '\'';
|
||||||
}
|
}
|
||||||
console.log(odooCmd);
|
|
||||||
console.log(execCmd);
|
console.log(execCmd);
|
||||||
res.end(sendJSON(res, 200, 'OK'));
|
execCommand(execCmd, res);
|
||||||
};
|
};
|
||||||
|
|
||||||
polka({ server })
|
polka({ server })
|
||||||
|
Loading…
x
Reference in New Issue
Block a user