diff --git a/server-ce/Gruntfile.coffee b/server-ce/Gruntfile.coffee index 201f351646..b30c403709 100644 --- a/server-ce/Gruntfile.coffee +++ b/server-ce/Gruntfile.coffee @@ -8,6 +8,7 @@ knox = require "knox" crypto = require "crypto" async = require "async" settings = require("settings-sharelatex") +_ = require("underscore") SERVICES = require("./config/services") @@ -101,7 +102,7 @@ module.exports = (grunt) -> grunt.registerTask 'default', 'run' grunt.registerTask "check:redis", "Check that redis is installed and running", () -> - Helpers.checkRedis @async() + Helpers.checkRedisConnect @async() grunt.registerTask "check:latexmk", "Check that latexmk is installed", () -> Helpers.checkLatexmk @async() grunt.registerTask "check:s3", "Check that Amazon S3 credentials are configured", () -> @@ -113,6 +114,9 @@ module.exports = (grunt) -> grunt.registerTask "check:make", "Check that make is installed", () -> Helpers.checkMake @async() + grunt.registerTask "check:mongo", "Check that make is installed", () -> + Helpers.checkMongoConnect @async() + grunt.registerTask "check", "Check that you have the required dependencies installed", ["check:redis", "check:latexmk", "check:s3", "check:fs", "check:aspell"] @@ -347,3 +351,46 @@ module.exports = (grunt) -> grunt.log.write "OK." return callback() + + checkMongoConnect: (callback = (error) ->) -> + grunt.log.write "Checking can connect to mongo" + mongojs = require("mongojs") + db = mongojs.connect(settings.mongo.url, ["tags"]) + db.runCommand { ping: 1 }, (err, res) -> + if !err and res.ok + grunt.log.write "OK." + return callback() + db.on 'error', (err)-> + err = "Can not connect to mongodb" + grunt.log.error "FAIL." + grunt.log.errorlns """ + + ShareLaTeX can not talk to the mongdb instance + + Check the mongodb instance is running and accessible on env var SHARELATEX_MONGO_URL + + """ + return callback(err) + + checkRedisConnect: (callback = (error) ->) -> + grunt.log.write "Checking can connect to redis\n" + rclient = require("redis").createClient(settings.redis.web) + + rclient.ping (err, res) -> + if !err? + grunt.log.write "OK." + else + throw new Error("hllll") + return callback() + errorHandler = _.once (err)-> + err = "Can not connect to redis" + grunt.log.error "FAIL." + grunt.log.errorlns """ + + ShareLaTeX can not talk to the redis instance + + Check the redis instance is running and accessible on env var SHARELATEX_REDIS_URL + + """ + return callback(err) + rclient.on 'error', errorHandler diff --git a/server-ce/package.json b/server-ce/package.json index 112c9adcf6..851b4d8af9 100644 --- a/server-ce/package.json +++ b/server-ce/package.json @@ -10,6 +10,7 @@ "load-grunt-config": "^0.19.2", "lodash": "^3.0.0", "mongojs": "^0.18.1", + "redis": "^2.6.2", "rimraf": "~2.2.6", "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git", "underscore": "^1.7.0"