From 43b90c5679541af7bf72663bfa255be6dfe1f28c Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 5 Jun 2015 13:33:58 -0400 Subject: [PATCH] fixed #3218 Conflicts: src/database/mongo.js --- app.js | 13 +++++++++---- src/database/mongo.js | 13 +++++++++++++ src/database/redis.js | 12 ++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/app.js b/app.js index 8ff5647023..7c9ac8f4d8 100644 --- a/app.js +++ b/app.js @@ -108,6 +108,7 @@ function loadConfig() { function start() { loadConfig(); + var db = require('./src/database'); // nconf defaults, if not set in config if (!nconf.get('upload_path')) { @@ -175,9 +176,8 @@ function start() { }); async.waterfall([ - function(next) { - require('./src/database').init(next); - }, + async.apply(db.init), + async.apply(db.checkCompatibility), function(next) { require('./src/meta').configs.init(next); }, @@ -203,7 +203,12 @@ function start() { } ], function(err) { if (err) { - winston.error(err.stack); + if (err.stacktrace !== false) { + winston.error(err.stack); + } else { + winston.error(err.message); + } + process.exit(); } }); diff --git a/src/database/mongo.js b/src/database/mongo.js index cc9bacec1c..ecae3402e7 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -7,6 +7,7 @@ async = require('async'), nconf = require('nconf'), session = require('express-session'), + semver = require('semver'), db, mongoClient; module.questions = [ @@ -131,6 +132,7 @@ } function createIndices() { + winston.info('[database] Checking database indices.') async.parallel([ async.apply(createIndex, 'objects', {_key: 1, score: -1}, {background: true}), async.apply(createIndex, 'objects', {_key: 1, value: -1}, {background: true, unique: true, sparse: true}), @@ -158,6 +160,17 @@ }); }; + module.checkCompatibility = function(callback) { + // For MongoDB, we need to ensure that the mongodb package is >= 2.0.0 + var mongoPkg = require.main.require('./node_modules/mongodb/package.json'), + err = semver.lt(mongoPkg.version, '2.0.0') ? new Error('The `mongodb` package is out-of-date, please run `./nodebb setup` again.') : null; + + if (err) { + err.stacktrace = false; + } + callback(err); + }; + module.info = function(db, callback) { db.stats({scale:1024}, function(err, stats) { if(err) { diff --git a/src/database/redis.js b/src/database/redis.js index 1c224276cc..673bf1f14a 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -5,6 +5,7 @@ var winston = require('winston'), nconf = require('nconf'), path = require('path'), + semver = require('semver'), session = require('express-session'), utils = require('./../../public/src/utils.js'), redis, @@ -111,6 +112,17 @@ return cxn; }; + module.checkCompatibility = function(callback) { + // Redis requires v2.8.9 + module.info(module.client, function(err, info) { + var err = semver.lt(info.redis_version, '2.8.9') ? new Error('Your Redis version is not new enough to support NodeBB, please upgrade Redis to v2.8.9 or higher.') : null; + if (err) { + err.stacktrace = false; + } + callback(err); + }); + }; + module.close = function() { redisClient.quit(); };