From 8132db644d81ab4662a8e87709c3d0fb440bc848 Mon Sep 17 00:00:00 2001 From: Tejas Dinkar Date: Tue, 4 Dec 2018 19:52:32 +0530 Subject: [PATCH 1/2] docs: Example of how to allow a graceful reload (#1481) [skip ci] --- README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1625b5ea..5660c6b6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # nodemon -nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected. +nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected. nodemon does **not** require *any* additional changes to your code or method of development. nodemon is a replacement wrapper for `node`, to use `nodemon` replace the word `node` on the command line when executing your script. @@ -251,6 +251,38 @@ nodemon --delay 2.5 } ``` +## Gracefully reloading down your script + +It is possible to have nodemon send any signal that you specify to your application. + +```bash +nodemon --signal SIGHUP server.js +``` + +Your application can handle the signal as follows. + +```js +process.once("SIGHUP", function () { + reloadSomeConfiguration(); +}) +``` + +Please note that nodemon will send this signal to every process in the process tree. + +If you are using `cluster`, then each workers (as well as the master) will receive the signal. If you wish to terminate all workers on receiving a `SIGHUP`, a common pattern is to catch the `SIGHUP` in the master, and forward `SIGTERM` to all workers, while ensuring that all workers ignore `SIGHUP`. + +```js +if (cluster.isMaster) { + process.on("SIGHUP", function () { + for (const worker of Object.values(cluster.workers)) { + worker.process.kill("SIGTERM"); + } + }); +} else { + process.on("SIGHUP", function() {}) +} +``` + ## Controlling shutdown of your script nodemon sends a kill signal to your application when it sees a file update. If you need to clean up on shutdown inside your script you can capture the kill signal and handle it yourself. From eb457be24e5a5253bb395176daa4ad8b70cb8b01 Mon Sep 17 00:00:00 2001 From: Remy Sharp Date: Mon, 10 Dec 2018 16:19:58 +0000 Subject: [PATCH 2/2] chore: update issue template [skip ci] --- .github/ISSUE_TEMPLATE.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index d975f3b3..cf8df0d5 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -8,6 +8,7 @@ - `nodemon -v`: - `node -v`: - Operating system/terminal environment: +- Using Docker? What image: - Command you ran: