1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Added a lot of the load-balancing support

This commit is contained in:
Ylian Saint-Hilaire 2017-09-13 11:25:57 -07:00
parent 6347eb7e4a
commit fb5114399f
10 changed files with 2198 additions and 108 deletions

13
db.js
View file

@ -18,6 +18,8 @@
module.exports.CreateDB = function (args, datapath) {
var obj = {};
obj.path = require('path');
obj.identifier = null;
if (args.mongodb) {
// Use MongoDB
obj.databaseType = 2;
@ -35,6 +37,17 @@ module.exports.CreateDB = function (args, datapath) {
}
obj.SetupDatabase = function (func) {
// Check if the database unique identifier is present
// This is used to check that in server peering mode, everyone is using the same database.
obj.Get('DatabaseIdentifier', function (err, docs) {
if ((docs.length == 1) && (docs[0].value != null)) {
obj.identifier = docs[0].value;
} else {
obj.identifier = new Buffer(require('crypto').randomBytes(32), 'binary').toString('hex');
obj.Set({ _id: 'DatabaseIdentifier', value: obj.identifier });
}
});
// Load database schema version and check if we need to update
obj.Get('SchemaVersion', function (err, docs) {
var ver = 0;