1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2025-12-19 09:43:20 +00:00

Added Docker container detection

This commit is contained in:
Bryan Roe
2020-04-24 19:34:24 -07:00
parent 9682464cb6
commit 26e48ff044
2 changed files with 16 additions and 4 deletions

File diff suppressed because one or more lines are too long

View File

@@ -196,6 +196,16 @@ switch(process.platform)
module.exports = { get: function () { throw ('Unsupported Platform'); } }; module.exports = { get: function () { throw ('Unsupported Platform'); } };
break; break;
} }
module.exports.isDocker = function isDocker()
{
if (process.platform != 'linux') { return (false); }
var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write("cat /proc/self/cgroup | tr '\n' '`' | awk -F'`' '{ split($1, res, " + '"/"); if(res[2]=="docker"){print "1";} }\'\nexit\n');
child.waitExit();
return (child.stdout.str != '');
};
module.exports.isVM = function isVM() module.exports.isVM = function isVM()
{ {
var ret = false; var ret = false;
@@ -228,8 +238,10 @@ module.exports.isVM = function isVM()
break; break;
} }
} }
if (!ret) { ret = this.isDocker(); }
return (ret); return (ret);
} };
// bios_date = BIOS->ReleaseDate // bios_date = BIOS->ReleaseDate