add checkMongoConnect and checkRedisConnect funcs to grunt

This commit is contained in:
Henry Oswald 2016-09-20 17:07:52 +01:00
parent 0dfd8f9d88
commit 7d4286d368
2 changed files with 49 additions and 1 deletions

View file

@ -8,6 +8,7 @@ knox = require "knox"
crypto = require "crypto" crypto = require "crypto"
async = require "async" async = require "async"
settings = require("settings-sharelatex") settings = require("settings-sharelatex")
_ = require("underscore")
SERVICES = require("./config/services") SERVICES = require("./config/services")
@ -101,7 +102,7 @@ module.exports = (grunt) ->
grunt.registerTask 'default', 'run' grunt.registerTask 'default', 'run'
grunt.registerTask "check:redis", "Check that redis is installed and running", () -> 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", () -> grunt.registerTask "check:latexmk", "Check that latexmk is installed", () ->
Helpers.checkLatexmk @async() Helpers.checkLatexmk @async()
grunt.registerTask "check:s3", "Check that Amazon S3 credentials are configured", () -> 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", () -> grunt.registerTask "check:make", "Check that make is installed", () ->
Helpers.checkMake @async() 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"] 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." grunt.log.write "OK."
return callback() 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

View file

@ -10,6 +10,7 @@
"load-grunt-config": "^0.19.2", "load-grunt-config": "^0.19.2",
"lodash": "^3.0.0", "lodash": "^3.0.0",
"mongojs": "^0.18.1", "mongojs": "^0.18.1",
"redis": "^2.6.2",
"rimraf": "~2.2.6", "rimraf": "~2.2.6",
"settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git", "settings-sharelatex": "git+https://github.com/sharelatex/settings-sharelatex.git",
"underscore": "^1.7.0" "underscore": "^1.7.0"