Gitter migration: Setup redirects (rollout pt. 3)
[gitter.git] / server / web / graceful-shutdown.js
blob12ab3c514a1ad026208bbf2443d07fc181011c9a
1 'use strict';
3 var env = require('gitter-web-env');
4 var logger = env.logger;
5 var shutdown = require('shutdown');
7 module.exports = {
8 install: function(server, app) {
9 var gracefullyClosing = false;
10 app.use(function(req, res, next) {
11 if (!gracefullyClosing) return next();
13 res.setHeader('Connection', 'close');
14 res.status(502).send('Server is in the process of restarting');
15 });
17 shutdown.addHandler('web', 20, function(callback) {
18 gracefullyClosing = true;
19 var start = Date.now();
20 server.close(function() {
21 var time = Date.now() - start;
22 logger.info('Web server shutdown successfully in ' + time + 'ms');
23 callback();
24 });
25 });