diff --git a/src/services.js b/src/services.js index cfdb563a6..8714a8c4b 100644 --- a/src/services.js +++ b/src/services.js @@ -281,6 +281,12 @@ function requiresUpgrade(existingObjOrImageName, currentImageName) { return etag.version.major !== ctag.version.major; } +async function hasAVX() { + // mongodb 5 and above requires AVX + const [error] = await safe(shell.exec('hasAVX', 'grep -q avx /proc/cpuinfo', {})); + return !error; +} + // paths for dumps function dumpPath(addon, appId) { switch (addon) { @@ -763,6 +769,11 @@ async function applyMemoryLimit(id) { containerName = `${name}-${instance}`; memoryLimit = serviceConfig && serviceConfig.memoryLimit ? serviceConfig.memoryLimit : APP_SERVICES[name].defaultMemoryLimit; } else if (SERVICES[name]) { + if (name === 'mongodb' && !await hasAVX()) { + debug('applyMemoryLimit: skipping mongodb because CPU does not have AVX'); + return; + } + containerName = name; memoryLimit = serviceConfig && serviceConfig.memoryLimit ? serviceConfig.memoryLimit : SERVICES[name].defaultMemoryLimit; } else { @@ -1488,12 +1499,6 @@ async function restorePostgreSql(app, options) { await pipeFileToRequest(dumpPath('postgresql', app.id), `http://${result.ip}:3000/databases/${database}/restore?access_token=${result.token}&username=${username}`); } -async function hasAVX() { - // mongodb 5 and above requires AVX - const [error] = await safe(shell.exec('hasAVX', 'grep -q avx /proc/cpuinfo', {})); - return !error; -} - async function startMongodb(existingInfra) { assert.strictEqual(typeof existingInfra, 'object');