Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: send proper quit signal on ctrl-c #1387

Merged
merged 1 commit into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,15 @@ Additional restart information:
* Which ignore rules are being applied
* Which file extensions are being watch
* The process ID of your application (the `child pid`)
* The process ID of nodemon to manually trigger restarts via kill signals

For example:

```text
14 Apr 15:24:58 - [nodemon] v1.0.17
14 Apr 15:24:58 - [nodemon] reading config /Users/remy/Sites/jsbin-private/nodemon.json
14 Apr 15:24:58 - [nodemon] to restart at any time, enter `rs`
14 Apr 15:24:58 - [nodemon] or send SIGHUP to 58118 to restart
14 Apr 15:24:58 - [nodemon] ignoring: /Users/remy/Sites/jsbin-private/.git/**/* node_modules/**/node_modules
14 Apr 15:24:58 - [nodemon] watching: /Users/remy/Sites/jsbin/views/**/* /Users/remy/Sites/jsbin/lib/**/* ../json/*.json config.dev.json
14 Apr 15:24:58 - [nodemon] watching extensions: json,js,html
Expand Down Expand Up @@ -263,13 +265,11 @@ Otherwise see [issue #1124](https://github.com/remy/nodemon/issues/1124) for fur

## No automatic restart when using Docker volumes [issue #419](https://github.com/remy/nodemon/issues/419#issuecomment-391244911)

Some Node.js Docker images do not seem to have the full suite of filtesystem process utilities that allow `nodemon` to restart automatically when the code in a mounted volume changes. To handle this, and enable automatic restarts without using legacy mode, you can install the [procps](http://procps.sourceforge.net) package.
Some Node.js Docker images do not seem to have the full suite of filtesystem process utilities that allow `nodemon` to restart automatically when the code in a mounted volume changes. To handle this, and enable automatic restarts without using legacy mode, you can install the [procps](http://procps.sourceforge.net) package.

Here's an example snippet of a Dockerfile:

```
FROM node:8.9.4-wheezy
RUN apt-get update && apt-get install -y procps
RUN apt-get update && apt-get install -y procps
```


15 changes: 9 additions & 6 deletions lib/monitor/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ run.kill = function (flag, callback) {
};
run.restart = noop;

bus.on('quit', function onQuit() {
bus.on('quit', function onQuit(code) {
if (code === undefined) {
code = 0;
}

// remove event listener
var exitTimer = null;
var exit = function () {
Expand All @@ -357,7 +361,7 @@ bus.on('quit', function onQuit() {
listener();
}
});
process.exit(0);
process.exit(code);
} else {
bus.emit('exit');
}
Expand Down Expand Up @@ -389,7 +393,7 @@ bus.on('restart', function () {
run.kill();
});

// remove the flag file on exit
// remove the child file on exit
process.on('exit', function () {
utils.log.detail('exiting');
if (child) { child.kill(); }
Expand All @@ -399,11 +403,10 @@ process.on('exit', function () {
if (!utils.isWindows) {
bus.once('boot', () => {
// usual suspect: ctrl+c exit
process.once('SIGINT', () => bus.emit('quit'));
process.once('SIGINT', () => bus.emit('quit', 130));
process.once('SIGTERM', () => {
bus.emit('quit');
bus.emit('quit', 143);
if (child) { child.kill('SIGTERM'); }
process.exit(0);
});
})
}
Expand Down
13 changes: 9 additions & 4 deletions lib/nodemon.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,22 @@ function nodemon(settings) {
if (chr === 13) {
process.stdout.write('\n');
}
// this prevents cursor keys from working.
// this intentionally prevents cursor keys from working.
process.stdout.write(String.fromCharCode(chr));
}

if (chr === 3) {
if (ctrlC) {
process.exit(0);
}

// if restartable, assume ctrl+c will break immediately
if (ctrlC || rs) {
process.exit(rs ? 1 : 0);
if (rs) {
bus.emit('quit', 130);
}
ctrlC = true;
return;
} else if (buffer === '.exit' || chr === 4) { // ctrl+d
} else if (!rs && (buffer === '.exit' || chr === 4)) { // ctrl+d
process.exit();
} else if (chr === 13 || chr === 10) { // enter / carriage return
const input = buffer.toString().trim().toLowerCase();
Expand All @@ -140,6 +144,7 @@ function nodemon(settings) {
}
ctrlC = false;
});
process.stdin.resume();
if (process.stdin.setRawMode) {
process.stdin.setRawMode(true);
}
Expand Down