From 05fe53a25e12c79b264f5b0dda8ca9e6f8d483d8 Mon Sep 17 00:00:00 2001 From: Luc Heinrich Date: Mon, 13 Feb 2017 00:51:55 +0100 Subject: [PATCH] Explicitely but gracefully handle SIGINT and SIGTERM signals. Fixes #557. --- bin/webpack-dev-server.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/webpack-dev-server.js b/bin/webpack-dev-server.js index d3352b0aa2..6095edeb7d 100755 --- a/bin/webpack-dev-server.js +++ b/bin/webpack-dev-server.js @@ -386,6 +386,14 @@ function startDevServer(wpOpt, options) { throw e; } + ["SIGINT", "SIGTERM"].forEach(function(sig) { + process.on(sig, function() { + console.log(`Gracefully shutting down server after ${sig}...`); + server.close(); + process.exit(); // eslint-disable-line no-process-exit + }); + }); + if(options.socket) { server.listeningApp.on("error", function(e) { if(e.code === "EADDRINUSE") {