diff --git a/services/document-updater/app.coffee b/services/document-updater/app.coffee index 9623a36c2c..6c1d8d1136 100644 --- a/services/document-updater/app.coffee +++ b/services/document-updater/app.coffee @@ -16,6 +16,8 @@ RedisManager = require('./app/js/RedisManager') DispatchManager = require('./app/js/DispatchManager') Errors = require "./app/js/Errors" HttpController = require "./app/js/HttpController" +mongojs = require "./app/js/mongojs" +async = require "async" Path = require "path" @@ -92,6 +94,29 @@ app.get "/health_check/redis_cluster", (req, res, next) -> else res.send 200 +app.get "/health_check", (req, res, next) -> + async.series [ + (cb) -> + pubsubClient.healthCheck (error) -> + if error? + logger.err {err: error}, "failed redis health check" + cb(error) + (cb) -> + docUpdaterRedisClient.healthCheck (error) -> + if error? + logger.err {err: error}, "failed redis cluster health check" + cb(error) + (cb) -> + mongojs.healthCheck (error) -> + if error? + logger.err {err: error}, "failed mongo health check" + cb(error) + ] , (error) -> + if error? + res.send 500 + else + res.send 200 + app.use (error, req, res, next) -> if error instanceof Errors.NotFoundError res.send 404 diff --git a/services/document-updater/app/coffee/mongojs.coffee b/services/document-updater/app/coffee/mongojs.coffee index 8f8f1a9ab9..dfeebb788f 100644 --- a/services/document-updater/app/coffee/mongojs.coffee +++ b/services/document-updater/app/coffee/mongojs.coffee @@ -1,7 +1,12 @@ Settings = require "settings-sharelatex" mongojs = require "mongojs" db = mongojs(Settings.mongo.url, ["docSnapshots"]) + module.exports = db: db ObjectId: mongojs.ObjectId - + healthCheck: (callback) -> + db.runCommand {ping: 1}, (err, res) -> + return callback(err) if err? + return callback(new Error("failed mongo ping")) if !res.ok + callback()