diff --git a/bin/browserid b/bin/browserid index 80dd6e2a20e6aa1c8de2b1b1247b4f8c562eaf5f..25a922658b8f14f54a101a3555e94b0fb1590f32 100755 --- a/bin/browserid +++ b/bin/browserid @@ -79,13 +79,7 @@ if (!config.get('dbwriter_url')) { // #1 - Setup health check / heartbeat middleware. // This is in front of logging on purpose. see issue #537 -heartbeat.setup(app, function(cb) { - // let's check stuff! first the heartbeat of our keysigner - heartbeat.check(config.get('keysigner_url'), function(rv) { - if (!rv) return cb(rv); - heartbeat.check(config.get('dbwriter_url'), cb); - }); -}); +heartbeat.setup(app); // #2 - logging! all requests other than __heartbeat__ are logged app.use(express.logger({ diff --git a/bin/dbwriter b/bin/dbwriter index 9bd767bac802b35c83ea4141dd2fdc8b1daa677e..f4be279423ce3ac8dec95db075710e5bc8758d0a 100755 --- a/bin/dbwriter +++ b/bin/dbwriter @@ -63,7 +63,10 @@ logger.info("dbwriter starting up"); // Setup health check / heartbeat middleware. // This is in front of logging on purpose. see issue #537 -heartbeat.setup(app); +heartbeat.setup(app, function(cb) { + // ping the database to verify we're really healthy. + db.ping(cb); +}); // logging! all requests other than __heartbeat__ are logged app.use(express.logger({ diff --git a/lib/db.js b/lib/db.js index 2b5cbbadcdd263929542333238c5b9c681800966..e717029611c4233375b006a3874a79738430ee6d 100644 --- a/lib/db.js +++ b/lib/db.js @@ -111,7 +111,8 @@ exports.onReady = function(f) { 'verificationSecretForEmail', 'checkAuth', 'listEmails', - 'lastStaged' + 'lastStaged', + 'ping' ].forEach(function(fn) { exports[fn] = function() { checkReady(); diff --git a/lib/db/json.js b/lib/db/json.js index f78045b009d3c14d41447d03be4fc152b2bffd69..dcbb213ec27e684a11e205bb0b875900bbcc102f 100644 --- a/lib/db/json.js +++ b/lib/db/json.js @@ -358,3 +358,7 @@ exports.addTestUser = function(email, hash, cb) { cb(); }); }; + +exports.ping = function(cb) { + setTimeout(function() { cb(); }, 0); +}; diff --git a/lib/db/mysql.js b/lib/db/mysql.js index 574c5a72e13206bb34c2ce4741e1747e9c911623..c1d4179165504bb49a84ae227901e08a7e52d4ec 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -453,3 +453,9 @@ exports.addTestUser = function(email, hash, cb) { }); }); }; + +exports.ping = function() { + client.ping(function(err) { + cb(err); + }); +};