From 96526a37a3cd64a866f3fc14a71cc327234d9a7d Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 5 Jun 2015 13:33:58 -0400 Subject: [PATCH] fixed #3218 --- 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 4e677df7c1..78f9e01188 100644 --- a/app.js +++ b/app.js @@ -109,6 +109,7 @@ function loadConfig() { function start() { loadConfig(); + var db = require('./src/database'); // nconf defaults, if not set in config if (!nconf.get('upload_path')) { @@ -176,9 +177,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); }, @@ -204,7 +204,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 9b0cd64842..9ddd7bfca5 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -8,6 +8,7 @@ nconf = require('nconf'), session = require('express-session'), _ = require('underscore'), + semver = require('semver'), db, mongoClient; _.mixin(require('underscore.deep')); @@ -137,6 +138,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}), @@ -164,6 +166,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(); };