[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é !'));
|
||||
};
|
||||
|
||||
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) => {
|
||||
let execCmd = 'cd ~/docker/hosts/*/ && ';
|
||||
switch (req.params.cmd) {
|
||||
@ -86,22 +105,7 @@ const serverCommand = (req, res) => {
|
||||
default:
|
||||
execCmd = '/bin/true';
|
||||
}
|
||||
if (sshConn) {
|
||||
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;
|
||||
});
|
||||
});
|
||||
}
|
||||
execCommand(execCmd, res);
|
||||
};
|
||||
|
||||
const odooAction = (req, res) => {
|
||||
@ -118,10 +122,13 @@ const odooAction = (req, res) => {
|
||||
// Install or update
|
||||
odooCmd += (req.body.action == 'install') ? '-i ' : '-u ';
|
||||
odooCmd += req.body.modules;
|
||||
// TODO: multi databases
|
||||
if (req.body.databases.length == 1) {
|
||||
odooCmd += ' -d ' + req.body.databases[0];
|
||||
}
|
||||
const odooCmdCached = odooCmd;
|
||||
// Handle multi databases
|
||||
odooCmd = [];
|
||||
req.body.databases.forEach((dbname) => {
|
||||
odooCmd.push(odooCmdCached + ' -d ' + dbname);
|
||||
});
|
||||
odooCmd = odooCmd.join(' && ');
|
||||
if (req.body.stop) {
|
||||
execCmd += 'docker-compose stop golem && '
|
||||
execCmd += 'docker-compose run --rm golem bash -c \'bash genconf.sh && ' + odooCmd + '\' && ';
|
||||
@ -129,9 +136,8 @@ const odooAction = (req, res) => {
|
||||
} else {
|
||||
execCmd += 'docker-compose exec golem bash -c \'' + odooCmd + '\'';
|
||||
}
|
||||
console.log(odooCmd);
|
||||
console.log(execCmd);
|
||||
res.end(sendJSON(res, 200, 'OK'));
|
||||
execCommand(execCmd, res);
|
||||
};
|
||||
|
||||
polka({ server })
|
||||
|
Loading…
x
Reference in New Issue
Block a user