From e092778ba6bc5ab9bb9c14885ed60bb2876229c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 15 Jan 2018 15:05:33 -0500 Subject: [PATCH] closes #6200 --- install/web.js | 6 ++++-- src/database/redis.js | 36 ++++++++++++++++++++++-------------- src/install.js | 9 +++++---- 3 files changed, 31 insertions(+), 20 deletions(-) diff --git a/install/web.js b/install/web.js index 92dcdb17d3..d63db06ca3 100644 --- a/install/web.js +++ b/install/web.js @@ -10,6 +10,7 @@ var less = require('less'); var async = require('async'); var uglify = require('uglify-js'); var nconf = require('nconf'); +var _ = require('lodash'); var Benchpress = require('benchpressjs'); var app = express(); @@ -103,14 +104,15 @@ function welcome(req, res) { } function install(req, res) { + var setupEnvVars = _.assign({}, process.env); for (var i in req.body) { if (req.body.hasOwnProperty(i) && !process.env.hasOwnProperty(i)) { - process.env[i.replace(':', '__')] = req.body[i]; + setupEnvVars[i.replace(':', '__')] = req.body[i]; } } var child = require('child_process').fork('app', ['--setup'], { - env: process.env, + env: setupEnvVars, }); child.on('close', function (data) { diff --git a/src/database/redis.js b/src/database/redis.js index e45f8f0ef8..70a8ffbd53 100644 --- a/src/database/redis.js +++ b/src/database/redis.js @@ -37,19 +37,22 @@ redisModule.questions = [ ]; redisModule.init = function (callback) { - redisClient = redisModule.connect(); + callback = callback || function () { }; + redisClient = redisModule.connect({}, function (err) { + if (err) { + winston.error('NodeBB could not connect to your Redis database. Redis returned the following error', err); + return callback(err); + } + redisModule.client = redisClient; + + require('./redis/main')(redisClient, redisModule); + require('./redis/hash')(redisClient, redisModule); + require('./redis/sets')(redisClient, redisModule); + require('./redis/sorted')(redisClient, redisModule); + require('./redis/list')(redisClient, redisModule); - redisModule.client = redisClient; - - require('./redis/main')(redisClient, redisModule); - require('./redis/hash')(redisClient, redisModule); - require('./redis/sets')(redisClient, redisModule); - require('./redis/sorted')(redisClient, redisModule); - require('./redis/list')(redisClient, redisModule); - - if (typeof callback === 'function') { callback(); - } + }); }; redisModule.initSessionStore = function (callback) { @@ -66,7 +69,8 @@ redisModule.initSessionStore = function (callback) { } }; -redisModule.connect = function (options) { +redisModule.connect = function (options, callback) { + callback = callback || function () {}; var redis_socket_or_host = nconf.get('redis:host'); var cxn; @@ -88,7 +92,11 @@ redisModule.connect = function (options) { cxn.on('error', function (err) { winston.error(err.stack); - process.exit(1); + callback(err); + }); + + cxn.on('ready', function () { + callback(); }); if (nconf.get('redis:password')) { @@ -99,7 +107,7 @@ redisModule.connect = function (options) { if (dbIdx >= 0) { cxn.select(dbIdx, function (err) { if (err) { - winston.error('NodeBB could not connect to your Redis database. Redis returned the following error', err); + winston.error('NodeBB could not select Redis database. Redis returned the following error', err); throw err; } }); diff --git a/src/install.js b/src/install.js index 2906adc9e8..33bd5a58d1 100644 --- a/src/install.js +++ b/src/install.js @@ -157,16 +157,17 @@ function completeConfigSetup(config, next) { } } + nconf.overrides(config); async.waterfall([ - function (next) { - install.save(config, next); - }, function (next) { require('./database').init(next); }, function (next) { require('./database').createIndices(next); }, + function (next) { + install.save(config, next); + }, ], next); } @@ -523,7 +524,7 @@ install.setup = function (callback) { ], function (err, results) { if (err) { winston.warn('NodeBB Setup Aborted.\n ' + err.stack); - process.exit(); + process.exit(1); } else { var data = {}; if (results[6]) {