3 var env
= require('gitter-web-env');
4 var logger
= env
.logger
;
5 var shutdown
= require('shutdown');
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');
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');