db upgrade: stop containers only after exporting
we cannot export if the containers were nuked in the platform logic. for this reason, move the removal near the place where they get started.
This commit is contained in:
+29
-9
@@ -852,7 +852,7 @@ function startServices(existingInfra, callback) {
|
||||
} else {
|
||||
assert.strictEqual(typeof existingInfra.images, 'object');
|
||||
|
||||
if (!existingInfra.images.turn || infra.images.turn.tag !== existingInfra.images.turn.tag) startFuncs.push(startTurn.bind(null, existingInfra));
|
||||
if (infra.images.turn.tag !== existingInfra.images.turn.tag) startFuncs.push(startTurn.bind(null, existingInfra));
|
||||
if (infra.images.mysql.tag !== existingInfra.images.mysql.tag) startFuncs.push(startMysql.bind(null, existingInfra));
|
||||
if (infra.images.postgresql.tag !== existingInfra.images.postgresql.tag) startFuncs.push(startPostgresql.bind(null, existingInfra));
|
||||
if (infra.images.mongodb.tag !== existingInfra.images.mongodb.tag) startFuncs.push(startMongodb.bind(null, existingInfra));
|
||||
@@ -1192,7 +1192,11 @@ function startMysql(existingInfra, callback) {
|
||||
--label isCloudronManaged=true \
|
||||
--read-only -v /tmp -v /run "${tag}"`;
|
||||
|
||||
shell.exec('startMysql', cmd, function (error) {
|
||||
async.series([
|
||||
shell.exec.bind(null, 'stopMysql', 'docker stop mysql || true'),
|
||||
shell.exec.bind(null, 'removeMysql', 'docker rm -f mysql || true'),
|
||||
shell.exec.bind(null, 'startMysql', cmd)
|
||||
], function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
waitForContainer('mysql', 'CLOUDRON_MYSQL_TOKEN', function (error) {
|
||||
@@ -1408,7 +1412,11 @@ function startPostgresql(existingInfra, callback) {
|
||||
--label isCloudronManaged=true \
|
||||
--read-only -v /tmp -v /run "${tag}"`;
|
||||
|
||||
shell.exec('startPostgresql', cmd, function (error) {
|
||||
async.series([
|
||||
shell.exec.bind(null, 'stopPostgresql', 'docker stop postgresql || true'),
|
||||
shell.exec.bind(null, 'removePostgresql', 'docker rm -f postgresql || true'),
|
||||
shell.exec.bind(null, 'startPostgresql', cmd)
|
||||
], function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
waitForContainer('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN', function (error) {
|
||||
@@ -1564,8 +1572,6 @@ function startTurn(existingInfra, callback) {
|
||||
const memoryLimit = 256;
|
||||
const realm = settings.adminFqdn();
|
||||
|
||||
if (existingInfra.version === infra.version && existingInfra.images.turn && infra.images.turn.tag === existingInfra.images.turn.tag) return callback();
|
||||
|
||||
// this exports 3478/tcp, 5349/tls and 50000-51000/udp
|
||||
const cmd = `docker run --restart=always -d --name="turn" \
|
||||
--hostname turn \
|
||||
@@ -1583,7 +1589,11 @@ function startTurn(existingInfra, callback) {
|
||||
--label isCloudronManaged=true \
|
||||
--read-only -v /tmp -v /run "${tag}"`;
|
||||
|
||||
shell.exec('startTurn', cmd, callback);
|
||||
async.series([
|
||||
shell.exec.bind(null, 'stopTurn', 'docker stop turn || true'),
|
||||
shell.exec.bind(null, 'removeTurn', 'docker rm -f turn || true'),
|
||||
shell.exec.bind(null, 'startTurn', cmd)
|
||||
], callback);
|
||||
}
|
||||
|
||||
function startMongodb(existingInfra, callback) {
|
||||
@@ -1622,7 +1632,11 @@ function startMongodb(existingInfra, callback) {
|
||||
--label isCloudronManaged=true \
|
||||
--read-only -v /tmp -v /run "${tag}"`;
|
||||
|
||||
shell.exec('startMongodb', cmd, function (error) {
|
||||
async.series([
|
||||
shell.exec.bind(null, 'stopMongodb', 'docker stop mongodb || true'),
|
||||
shell.exec.bind(null, 'removeMongodb', 'docker rm -f mongodb || true'),
|
||||
shell.exec.bind(null, 'startMongodb', cmd)
|
||||
], function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
waitForContainer('mongodb', 'CLOUDRON_MONGODB_TOKEN', function (error) {
|
||||
@@ -1773,13 +1787,19 @@ function startRedis(existingInfra, callback) {
|
||||
async.eachSeries(allApps, function iterator (app, iteratorCallback) {
|
||||
if (!('redis' in app.manifest.addons)) return iteratorCallback(); // app doesn't use the addon
|
||||
|
||||
setupRedis(app, app.manifest.addons.redis, iteratorCallback);
|
||||
const redisName = 'redis-' + app.id;
|
||||
|
||||
async.series([
|
||||
shell.exec.bind(null, 'stopRedis', `docker stop ${redisName} || true`),
|
||||
shell.exec.bind(null, 'removeRedis', `docker rm -f ${redisName} || true`),
|
||||
setupRedis.bind(null, app, app.manifest.addons.redis) // starts the container
|
||||
], iteratorCallback);
|
||||
}, function (error) {
|
||||
if (error) return callback(error);
|
||||
|
||||
if (!upgrading) return callback();
|
||||
|
||||
importDatabase('redis', callback); // setupRedis currently starts the app container
|
||||
importDatabase('redis', callback);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user