1 /*jshint trailing: false, unused: true, node: true */
4 var os = require('os');
5 var appVersion = require('gitter-app-version');
6 var mongoose = require('mongoose');
7 var env = require('gitter-web-env');
8 var logger = env.logger;
9 var config = env.config;
10 var redis = env.redis;
11 var errorReporter = env.errorReporter;
12 var StatusError = require('statuserror');
15 function(req, res, next) {
17 var db = mongoose.connection.db;
18 var adminDb = db.admin();
19 adminDb.ping(function(err, pingResult) {
20 if (err) return next(err);
22 if (!pingResult || !pingResult.ok) return next(new StatusError(500, 'Ping failed'));
24 adminDb.replSetGetStatus(function(err, info) {
25 if (err) return next(err);
26 if (!info || info.myState !== 1) return next(new StatusError(500, 'Replica set failure'));
28 var pingtestCollection = db.collection('pingtest');
29 pingtestCollection.insert({ ping: Date.now() }, function(err) {
30 if (err) return next(err);
32 pingtestCollection.remove({}, function(err) {
33 if (err) return next(err);
35 var redisClient = redis.getClient();
36 redisClient.incr('ping.test', function(err) {
37 if (err) return next(err);
45 appVersion.getVersion()
56 function(err, req, res /*, next*/) {
57 logger.error('Health check failed: ' + err, { exception: err });
58 errorReporter(err, { health_check_full: 'failed' }, { module: 'health-check' });
59 res.status(500).send('Failed: ' + err);