[WIP]Add Odoo install / update commands
* Handle install or update ; * Handle stop before or not.
This commit is contained in:
parent
e4a58bd800
commit
25215c116b
45
index.jsx
45
index.jsx
@ -13,7 +13,7 @@ function createLocalState(initState) {
|
|||||||
|
|
||||||
const initialState = {
|
const initialState = {
|
||||||
address: '', port: '', username: '', key: '', database: '',
|
address: '', port: '', username: '', key: '', database: '',
|
||||||
databases: [], modules: '', serverlog: '', connected: false
|
databases: [], modules: '', serverlog: '', connected: false, stop: false
|
||||||
};
|
};
|
||||||
const [isConnected, setIsConnected] = createSignal(false);
|
const [isConnected, setIsConnected] = createSignal(false);
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ const OdooDockerSshAdminActions = () => {
|
|||||||
const webStop = cmdFetch('webstop');
|
const webStop = cmdFetch('webstop');
|
||||||
const webRestart = cmdFetch('webrestart');
|
const webRestart = cmdFetch('webrestart');
|
||||||
const odooStart = cmdFetch('odoostart');
|
const odooStart = cmdFetch('odoostart');
|
||||||
const odooStop = cmdFetch('odoostop');
|
const stop = cmdFetch('odoostop');
|
||||||
const odooRestart = cmdFetch('odoorestart');
|
const odooRestart = cmdFetch('odoorestart');
|
||||||
const dbStart = cmdFetch('dbstart');
|
const dbStart = cmdFetch('dbstart');
|
||||||
const dbStop = cmdFetch('dbstop');
|
const dbStop = cmdFetch('dbstop');
|
||||||
@ -198,7 +198,7 @@ const OdooDockerSshAdminActions = () => {
|
|||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="col">
|
<div class="col">
|
||||||
<button type="button" class="button clear" onClick={odooStop}>
|
<button type="button" class="button clear" onClick={stop}>
|
||||||
⏹ Odoo : arrêter
|
⏹ Odoo : arrêter
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
@ -254,6 +254,34 @@ const OdooDockerSshAdminModules = () => {
|
|||||||
return names.length ? names.join(', ') : 'Aucune base sélectionnée';
|
return names.length ? names.join(', ') : 'Aucune base sélectionnée';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const odooCmd = (action) => {
|
||||||
|
return () => {
|
||||||
|
if (!isConnected()) {
|
||||||
|
humane.log('Non connecté : impossible de lancer une commande Odoo.');
|
||||||
|
} else {
|
||||||
|
humane.log('Commande lancée, veuillez patienter.');
|
||||||
|
fetch('/odooaction', {
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({
|
||||||
|
stop: state.stop,
|
||||||
|
databases: state.databases.filter((db) => db.checked).map((db) => db.name),
|
||||||
|
modules: state.modules,
|
||||||
|
action: action
|
||||||
|
}),
|
||||||
|
headers: {'Content-Type': 'application/json'}
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (response.status != 200) { humane.log('Erreur : voyez le retour serveur'); }
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(body => {
|
||||||
|
humane.log('Commande terminée.');
|
||||||
|
setState('serverlog', state.serverlog + body);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
return <div>
|
return <div>
|
||||||
<h2>🗄 Modules</h2>
|
<h2>🗄 Modules</h2>
|
||||||
<form name="modules-form">
|
<form name="modules-form">
|
||||||
@ -266,11 +294,16 @@ const OdooDockerSshAdminModules = () => {
|
|||||||
</div>
|
</div>
|
||||||
<div class="col-6">
|
<div class="col-6">
|
||||||
<label for="stop">❗ Arrêt serveur préalable ?</label>
|
<label for="stop">❗ Arrêt serveur préalable ?</label>
|
||||||
<input type="checkbox" name="stop" value={(state.stop)} />
|
<input type="checkbox" name="stop" checked={(state.stop)}
|
||||||
|
onChange={(e) => setState('stop', e.target.checked)} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button type="button" class="button primary outline">Installer</button>
|
<button type="button" class="button primary outline" onClick={odooCmd('install')}>
|
||||||
<button type="button" class="button primary">Mettre à jour</button>
|
Installer
|
||||||
|
</button>
|
||||||
|
<button type="button" class="button primary" onClick={odooCmd('update')}>
|
||||||
|
Mettre à jour
|
||||||
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
};
|
};
|
||||||
|
129
server.js
129
server.js
@ -54,58 +54,84 @@ const disconnect = (req, res) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const serverCommand = (req, res) => {
|
const serverCommand = (req, res) => {
|
||||||
if (!req.params.cmd) {
|
let execCmd = 'cd ~/docker/hosts/*/ && ';
|
||||||
res.end(sendJSON(res, 403, 'Pas de commande à exécuter'));
|
switch (req.params.cmd) {
|
||||||
} else {
|
case 'webstart':
|
||||||
let execCmd = 'cd ~/docker/hosts/*/ && ';
|
execCmd += 'docker-compose start nginx';
|
||||||
switch (req.params.cmd) {
|
break;
|
||||||
case 'webstart':
|
case 'webstop':
|
||||||
execCmd += 'docker-compose start nginx';
|
execCmd += 'docker-compose stop nginx';
|
||||||
break;
|
break;
|
||||||
case 'webstop':
|
case 'webrestart':
|
||||||
execCmd += 'docker-compose stop nginx';
|
execCmd += 'docker-compose restart nginx';
|
||||||
break;
|
break;
|
||||||
case 'webrestart':
|
case 'odoostart':
|
||||||
execCmd += 'docker-compose restart nginx';
|
execCmd += 'docker-compose start golem';
|
||||||
break;
|
break;
|
||||||
case 'odoostart':
|
case 'odoostop':
|
||||||
execCmd += 'docker-compose start golem';
|
execCmd += 'docker-compose stop golem';
|
||||||
break;
|
break;
|
||||||
case 'odoostop':
|
case 'odoorestart':
|
||||||
execCmd += 'docker-compose stop golem';
|
execCmd += 'docker-compose restart golem';
|
||||||
break;
|
break;
|
||||||
case 'odoorestart':
|
case 'dbstart':
|
||||||
execCmd += 'docker-compose restart golem';
|
execCmd += 'docker-compose start pggolem';
|
||||||
break;
|
break;
|
||||||
case 'dbstart':
|
case 'dbstop':
|
||||||
execCmd += 'docker-compose start pggolem';
|
execCmd += 'docker-compose stop pggolem';
|
||||||
break;
|
break;
|
||||||
case 'dbstop':
|
case 'dbrestart':
|
||||||
execCmd += 'docker-compose stop pggolem';
|
execCmd += 'docker-compose restart pggolem';
|
||||||
break;
|
break;
|
||||||
case 'dbrestart':
|
default:
|
||||||
execCmd += 'docker-compose restart pggolem';
|
execCmd = '/bin/true';
|
||||||
break;
|
|
||||||
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;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const odooAction = (req, res) => {
|
||||||
|
console.log(req.body);
|
||||||
|
if (!req.body.databases.length) {
|
||||||
|
res.end(sendJSON(res, 500, 'Erreur : pas de base de données sélectionnée.\n'));
|
||||||
|
}
|
||||||
|
if (!req.body.modules.length) {
|
||||||
|
res.end(sendJSON(res, 500, 'Erreur : aucun module fourni.\n'));
|
||||||
|
}
|
||||||
|
let execCmd = 'cd ~/docker/hosts/*/ && ';
|
||||||
|
// Base command
|
||||||
|
let odooCmd = 'OCB/odoo-bin -c odoo.conf --no-xmlrpc --stop-after-init ';
|
||||||
|
// 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];
|
||||||
|
}
|
||||||
|
if (req.body.stop) {
|
||||||
|
execCmd += 'docker-compose stop golem && '
|
||||||
|
execCmd += 'docker-compose run --rm golem bash -c \'bash genconf.sh && ' + odooCmd + '\' && ';
|
||||||
|
execCmd += 'docker-compose start golem'
|
||||||
|
} else {
|
||||||
|
execCmd += 'docker-compose exec golem bash -c \'' + odooCmd + '\'';
|
||||||
|
}
|
||||||
|
console.log(odooCmd);
|
||||||
|
console.log(execCmd);
|
||||||
|
res.end(sendJSON(res, 200, 'OK'));
|
||||||
};
|
};
|
||||||
|
|
||||||
polka({ server })
|
polka({ server })
|
||||||
@ -113,6 +139,7 @@ polka({ server })
|
|||||||
.post('/connect', connect)
|
.post('/connect', connect)
|
||||||
.get('/disconnect', disconnect)
|
.get('/disconnect', disconnect)
|
||||||
.get('/cmd/:cmd', serverCommand)
|
.get('/cmd/:cmd', serverCommand)
|
||||||
|
.post('/odooaction', odooAction)
|
||||||
.listen(PORT, err => {
|
.listen(PORT, err => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
console.log(`> Running on localhost:${PORT}`);
|
console.log(`> Running on localhost:${PORT}`);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user