refactor into docker.update

This commit is contained in:
Girish Ramakrishnan
2021-01-20 12:01:15 -08:00
parent 0d535d2d5c
commit a14dbbe77a
2 changed files with 18 additions and 9 deletions

View File

@@ -29,7 +29,8 @@ exports = module.exports = {
memoryUsage,
createVolume,
removeVolume,
clearVolume
clearVolume,
update
};
var addons = require('./addons.js'),
@@ -699,3 +700,17 @@ function info(callback) {
callback(null, result);
});
}
function update(name, memory, memorySwap, callback) {
assert.strictEqual(typeof name, 'string');
assert.strictEqual(typeof memory, 'number');
assert.strictEqual(typeof memorySwap, 'number');
assert.strictEqual(typeof callback, 'function');
const args = `update --memory ${memory} --memory-swap ${memorySwap} ${name}`.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(`update(${name})`, '/usr/bin/docker', args, { }, retryCallback);
}, callback);
}