diff --git a/CHANGES b/CHANGES index f40a0b936..67773e3aa 100644 --- a/CHANGES +++ b/CHANGES @@ -2101,4 +2101,5 @@ * Fix install issue where `/dev/dri` may not be present * import: when importing filesystem backups, the input box is a path * firewall: fix race condition where blocklist was not added in correct position in the FORWARD chain +* services: fix issue where services where scaled up/down too fast diff --git a/src/addons.js b/src/addons.js index e896e438f..38d56a571 100644 --- a/src/addons.js +++ b/src/addons.js @@ -798,7 +798,8 @@ function exportDatabase(addon, callback) { } function updateServiceConfig(platformConfig, callback) { - callback = callback || NOOP_CALLBACK; + assert.strictEqual(typeof platformConfig, 'object'); + assert.strictEqual(typeof callback, 'function'); async.eachSeries([ 'mysql', 'postgresql', 'mail', 'mongodb', 'graphite' ], function iterator(serviceName, iteratorCallback) { const containerConfig = platformConfig[serviceName]; @@ -812,6 +813,8 @@ function updateServiceConfig(platformConfig, callback) { } const args = `update --memory ${memory} --memory-swap ${memorySwap} ${serviceName}`.split(' '); + // scale back db containers, if possible. this is retried because updating memory constraints can fail + // with failed to write to memory.memsw.limit_in_bytes: write /sys/fs/cgroup/memory/docker/xx/memory.memsw.limit_in_bytes: device or resource busy async.retry({ times: 10, interval: 60 * 1000 }, function (retryCallback) { shell.spawn(`updateServiceConfig(${serviceName})`, '/usr/bin/docker', args, { }, retryCallback); }, iteratorCallback); diff --git a/src/platform.js b/src/platform.js index 01927b5fe..21e5691b9 100644 --- a/src/platform.js +++ b/src/platform.js @@ -90,20 +90,11 @@ function onPlatformReady(infraChanged) { } function applyPlatformConfig(callback) { - // scale back db containers, if possible. this is retried because updating memory constraints can fail - // with failed to write to memory.memsw.limit_in_bytes: write /sys/fs/cgroup/memory/docker/xx/memory.memsw.limit_in_bytes: device or resource busy + settings.getPlatformConfig(function (error, platformConfig) { + if (error) return callback(error); - async.retry({ times: 10, interval: 5 * 60 * 1000 }, function (retryCallback) { - settings.getPlatformConfig(function (error, platformConfig) { - if (error) return retryCallback(error); - - addons.updateServiceConfig(platformConfig, function (error) { - if (error) debug('Error updating services. Will rety in 5 minutes', platformConfig, error); - - retryCallback(error); - }); - }); - }, callback); + addons.updateServiceConfig(platformConfig, callback); + }); } function pruneInfraImages(callback) { diff --git a/src/settings.js b/src/settings.js index c099189d9..71deb0724 100644 --- a/src/settings.js +++ b/src/settings.js @@ -113,6 +113,8 @@ exports = module.exports = { _setApiServerOrigin: setApiServerOrigin }; +const NOOP_CALLBACK = function (error) { if (error) debug(error); }; + var addons = require('./addons.js'), assert = require('assert'), backups = require('./backups.js'), @@ -452,7 +454,7 @@ function setPlatformConfig(platformConfig, callback) { callback(null); // updating service config can take a while - addons.updateServiceConfig(platformConfig); + addons.updateServiceConfig(platformConfig, NOOP_CALLBACK); }); }