Quellcode durchsuchen

add checkMongoConnect and checkRedisConnect funcs to grunt

Henry Oswald vor 10 Jahren
Ursprung
Commit
192b77c573
2 geänderte Dateien mit 49 neuen und 1 gelöschten Zeilen
  1. 48 1
      Gruntfile.coffee
  2. 1 0
      package.json

+ 48 - 1
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

+ 1 - 0
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"