From 9aeba7dfe498f73e8ab2e4f954f3369752600919 Mon Sep 17 00:00:00 2001 From: Scott Ewart Date: Mon, 25 Jan 2016 16:12:36 -0800 Subject: [PATCH] Gracefully close server connections on SIGTERM. --- bin/web.js | 9 +++++++++ package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/web.js b/bin/web.js index 258a16d4..2b921792 100644 --- a/bin/web.js +++ b/bin/web.js @@ -112,3 +112,12 @@ app.use(function(err, req, res, next) { var server = app.listen(PORT, HOST, function () { console.log('Listening at http://%s:%s%s', HOST, PORT, BASE_URL); }); + +process.on('SIGTERM', function() { + // runit sends a SIGTERM, then waits 10 seconds and, if necessary, + // sends a SIGKILL. This lets us shut down gracefully. + server.close(function() { + console.log('Closed all server connections.'); + process.exit(0); + }); +}); diff --git a/package.json b/package.json index cdc71a1a..ff0de717 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nuts-serve", - "version": "2.7.3", + "version": "2.7.4", "description": "Server to make GitHub releases (private) available to download with Squirrel support", "main": "./lib/index.js", "homepage": "https://github.com/GitbookIO/nuts",