diff --git a/src/addons.js b/src/addons.js index c095eb3cc..e2be8acc0 100644 --- a/src/addons.js +++ b/src/addons.js @@ -821,8 +821,8 @@ function restorePostgreSql(app, options, callback) { getAddonDetails('postgresql', 'CLOUDRON_POSTGRESQL_TOKEN', function (error, result) { if (error) return callback(error); - var input = fs.createReadStream(path.join(paths.APPS_DATA_DIR, app.id, 'postgresqldump')); - input.on('error', callback); + var input = fs.createReadStream(path.join(paths.APPS_DATA_DIR, app.id, 'postgresqldump')); + input.on('error', callback); const restoreReq = request.post(`https://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}&username=${username}`, { rejectUnauthorized: false }, function (error, response) { if (error) return callback(error); @@ -1024,7 +1024,7 @@ function setupRedis(app, options, callback) { async.series([ shell.execSync.bind(null, 'startRedis', cmd), appdb.setAddonConfig.bind(null, app.id, 'redis', env), - function (next) { setTimeout(next, 3000); } // waitForRedis + waitForRedis.bind(null, app) ], function (error) { if (error) debug('Error setting up redis: ', error); callback(error); @@ -1033,6 +1033,26 @@ function setupRedis(app, options, callback) { }); } +function waitForRedis(app, callback) { + assert.strictEqual(typeof app, 'object'); + assert.strictEqual(typeof callback, 'function'); + + debugApp(app, 'Waiting for redis'); + + getAddonDetails('redis-' + app.id, 'CLOUDRON_REDIS_TOKEN', function (error, result) { + if (error) return callback(error); + + async.retry({ times: 10, interval: 5000 }, function (retryCallback) { + request.get(`https://${result.ip}:3000/healthcheck?access_token=${result.token}`, { json: true, rejectUnauthorized: false }, function (error, response) { + if (error) return retryCallback(new Error(`Error waiting for redis: ${error.message}`)); + if (response.statusCode !== 200) return retryCallback(new Error(`Error waiting for redis. Status code: ${response.statusCode} message: ${response.body.message}`)); + + retryCallback(null); + }); + }, callback); + }); +} + function clearRedis(app, options, callback) { assert.strictEqual(typeof app, 'object'); assert.strictEqual(typeof options, 'object'); diff --git a/src/infra_version.js b/src/infra_version.js index 4ed5baffa..27db4689f 100644 --- a/src/infra_version.js +++ b/src/infra_version.js @@ -18,7 +18,7 @@ exports = module.exports = { 'mysql': { repo: 'cloudron/mysql', tag: 'cloudron/mysql:2.0.1@sha256:42c861338d93beadc11438031ad7f68a10b1582fc27c8432173910d6b4f0e15d' }, 'postgresql': { repo: 'cloudron/postgresql', tag: 'cloudron/postgresql:2.0.1@sha256:a40096896960594411864aac1890e2a883639d6df810c2ae7b720ffa52be3681' }, 'mongodb': { repo: 'cloudron/mongodb', tag: 'cloudron/mongodb:2.0.1@sha256:b320fdea0d256fca73de40370c1029e2624c52620ec178716f59db152aef2d15' }, - 'redis': { repo: 'cloudron/redis', tag: 'cloudron/redis:2.0.2@sha256:c062cd77f40da784bd0a3b92b81cfc639e86233a3f04d3f4542749bb0bb422fa' }, + 'redis': { repo: 'cloudron/redis', tag: 'cloudron/redis:2.0.1@sha256:ac936cecbbdda8dc25d3ff08e958282190b96538628f10ad5bb55ae513a043b1' }, 'mail': { repo: 'cloudron/mail', tag: 'cloudron/mail:1.4.0@sha256:28e65b446569a324f4b28e920d43ac9723f9aa9699a629bec7368a2a74669f88' }, 'graphite': { repo: 'cloudron/graphite', tag: 'cloudron/graphite:1.0.0@sha256:196bf1d19782a015b361da48d06ba1017b3d04b4256d93fbb9c0b50599f69f5d' } }