diff --git a/src/mail.js b/src/mail.js index 7aa6b19d9..b2cc0468c 100644 --- a/src/mail.js +++ b/src/mail.js @@ -28,7 +28,7 @@ exports = module.exports = { setMailEnabled, setBanner, - startMail: restartMail, + startMail, restartMail, handleCertChanged, getMailAuth, @@ -746,6 +746,12 @@ async function restartMail() { await configureMail(settings.mailFqdn(), settings.dashboardDomain(), mailConfig); } +async function startMail(existingInfra) { + assert.strictEqual(typeof existingInfra, 'object'); + + await restartMail(); +} + async function restartMailIfActivated() { const activated = await users.isActivated(); diff --git a/src/services.js b/src/services.js index 6155c7d08..fd1b19a3c 100644 --- a/src/services.js +++ b/src/services.js @@ -500,11 +500,9 @@ async function rebuildService(id, auditSource) { // this attempts to recreate the service docker container if they don't exist but platform infra version is unchanged // passing an infra version of 'none' will not attempt to purge existing data - const serviceConfig = await getServiceConfig(id); - switch (id) { case 'turn': - await startTurn({ version: 'none' }, serviceConfig); + await startTurn({ version: 'none' }); break; case 'mongodb': await startMongodb({ version: 'none' }); @@ -516,10 +514,10 @@ async function rebuildService(id, auditSource) { await startMysql({ version: 'none' }); break; case 'sftp': - await sftp.rebuild(serviceConfig, { /* options */ }); + await sftp.start({ version: 'none' }); break; case 'graphite': - await startGraphite({ version: 'none' }, serviceConfig); + await startGraphite({ version: 'none' }); break; default: // nothing to rebuild for now. @@ -781,51 +779,45 @@ async function applyServiceConfig(id, serviceConfig) { async function startServices(existingInfra) { assert.strictEqual(typeof existingInfra, 'object'); - const servicesConfig = await settings.getServicesConfig(); - - let startFuncs = [ ]; + const startFuncs = []; // always start addons on any infra change, regardless of minor or major update if (existingInfra.version !== infra.version) { debug(`startServices: ${existingInfra.version} -> ${infra.version}. starting all services`); startFuncs.push( mail.startMail, // start this first to reduce email downtime - startTurn.bind(null, existingInfra, servicesConfig['turn'] || {}), - startMysql.bind(null, existingInfra), - startPostgresql.bind(null, existingInfra), - startMongodb.bind(null, existingInfra), - startRedis.bind(null, existingInfra), - startGraphite.bind(null, existingInfra, servicesConfig['graphite'] || {}), - sftp.start.bind(null, existingInfra, servicesConfig['sftp'] || {}), + startTurn, + startMysql, + startPostgresql, + startMongodb, + startRedis, + startGraphite, + sftp.start, ); } else { assert.strictEqual(typeof existingInfra.images, 'object'); if (infra.images.mail.tag !== existingInfra.images.mail.tag) startFuncs.push(mail.startMail); // start this first to reduce email downtime - if (infra.images.turn.tag !== existingInfra.images.turn.tag) startFuncs.push(startTurn.bind(null, existingInfra, servicesConfig['turn'] || {})); - 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)); - if (infra.images.redis.tag !== existingInfra.images.redis.tag) startFuncs.push(startRedis.bind(null, existingInfra)); - if (infra.images.graphite.tag !== existingInfra.images.graphite.tag) startFuncs.push(startGraphite.bind(null, existingInfra, servicesConfig['graphite'] || {})); - if (infra.images.sftp.tag !== existingInfra.images.sftp.tag) startFuncs.push(sftp.start.bind(null, existingInfra, servicesConfig['sftp'] || {})); + if (infra.images.turn.tag !== existingInfra.images.turn.tag) startFuncs.push(startTurn); + if (infra.images.mysql.tag !== existingInfra.images.mysql.tag) startFuncs.push(startMysql); + if (infra.images.postgresql.tag !== existingInfra.images.postgresql.tag) startFuncs.push(startPostgresql); + if (infra.images.mongodb.tag !== existingInfra.images.mongodb.tag) startFuncs.push(startMongodb); + if (infra.images.redis.tag !== existingInfra.images.redis.tag) startFuncs.push(startRedis); + if (infra.images.graphite.tag !== existingInfra.images.graphite.tag) startFuncs.push(startGraphite); + if (infra.images.sftp.tag !== existingInfra.images.sftp.tag) startFuncs.push(sftp.start); debug('startServices: existing infra. incremental service create %j', startFuncs.map(function (f) { return f.name; })); } for (const func of startFuncs) { - await func(); + await func(existingInfra); } // we always start db containers with unlimited memory. we then scale them down per configuration - let updateFuncs = [ - applyServiceConfig.bind(null, 'mysql', servicesConfig['mysql'] || {}), - applyServiceConfig.bind(null, 'postgresql', servicesConfig['postgresql'] || {}), - applyServiceConfig.bind(null, 'mongodb', servicesConfig['mongodb'] || {}), - ]; - - for (const updateFunc of updateFuncs) { - safe(updateFunc()); // no waiting. and it's ok if applying service configs fails + const servicesConfig = await settings.getServicesConfig(); + for (const id of [ 'mysql', 'postgresql', 'mongodb' ]) { + const serviceConfig = servicesConfig[id] || {}; + safe(applyServiceConfig(id, serviceConfig), { debug }); // no waiting. and it's ok if applying service configs fails } } @@ -914,10 +906,10 @@ async function setupTurn(app, options) { await addonConfigs.set(app.id, 'turn', env); } -async function startTurn(existingInfra, serviceConfig) { +async function startTurn(existingInfra) { assert.strictEqual(typeof existingInfra, 'object'); - assert.strictEqual(typeof serviceConfig, 'object'); + const serviceConfig = await getServiceConfig('turn'); const tag = infra.images.turn.tag; const memoryLimit = serviceConfig.memoryLimit || SERVICES['turn'].defaultMemoryLimit; const memory = system.getMemoryAllocation(memoryLimit); @@ -1631,10 +1623,10 @@ async function restoreMongoDb(app, options) { }); } -async function startGraphite(existingInfra, serviceConfig) { +async function startGraphite(existingInfra) { assert.strictEqual(typeof existingInfra, 'object'); - assert.strictEqual(typeof serviceConfig, 'object'); + const serviceConfig = await getServiceConfig('graphite'); const tag = infra.images.graphite.tag; const memoryLimit = serviceConfig.memoryLimit || 256 * 1024 * 1024; const memory = system.getMemoryAllocation(memoryLimit); diff --git a/src/sftp.js b/src/sftp.js index 6ec9c2208..9cbde5817 100644 --- a/src/sftp.js +++ b/src/sftp.js @@ -2,7 +2,6 @@ exports = module.exports = { start, - rebuild, DEFAULT_MEMORY_LIMIT: 256 * 1024 * 1024 }; @@ -13,19 +12,20 @@ const apps = require('./apps.js'), debug = require('debug')('box:sftp'), hat = require('./hat.js'), infra = require('./infra_version.js'), - path = require('path'), paths = require('./paths.js'), safe = require('safetydance'), + settings = require('./settings.js'), shell = require('./shell.js'), system = require('./system.js'), volumes = require('./volumes.js'); -async function rebuild(serviceConfig, options) { - assert.strictEqual(typeof serviceConfig, 'object'); - assert.strictEqual(typeof options, 'object'); +async function start(existingInfra) { + assert.strictEqual(typeof existingInfra, 'object'); - debug('rebuilding container'); + debug('start: re-creating container'); + const servicesConfig = await settings.getServicesConfig(); + const serviceConfig = servicesConfig['sftp'] || {}; const tag = infra.images.sftp.tag; const memoryLimit = serviceConfig.memoryLimit || exports.DEFAULT_MEMORY_LIMIT; const memory = system.getMemoryAllocation(memoryLimit); @@ -95,10 +95,3 @@ async function rebuild(serviceConfig, options) { await shell.promises.exec('removeSftp', 'docker rm -f sftp || true'); await shell.promises.exec('startSftp', cmd); } - -async function start(existingInfra, serviceConfig) { - assert.strictEqual(typeof existingInfra, 'object'); - assert.strictEqual(typeof serviceConfig, 'object'); - - await rebuild(serviceConfig, { force: true }); // force rebuild when infra changed -}