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

Graceful way to stop server.js through CLI/Docker? #557

Closed
igorsantos07 opened this issue Aug 21, 2016 · 15 comments · Fixed by #787
Closed

Graceful way to stop server.js through CLI/Docker? #557

igorsantos07 opened this issue Aug 21, 2016 · 15 comments · Fixed by #787
Labels

Comments

@igorsantos07
Copy link

I'm using webpack-dev-server under a Docker container, and it's default command is simply node server.js, which is sampled below. However, when I ask Docker to stop the container, it timeouts in 10s, meaning it's probably not being able to terminate the node process.

What would be the best way to implement some sort of npm stop command to gracefully shutdown webpack-dev-server?


server.js

'use strict'
require('core-js/fn/object/assign')
const webpack = require('webpack')
const WebpackDevServer = require('webpack-dev-server')
const config = require('./webpack.config')

new WebpackDevServer(webpack(config), config.devServer)
.listen(config.port, null, (err) => {
  if (err) {
    console.log(err)
  }
  console.log('Listening at localhost:' + config.port)
})
@SpaceK33z
Copy link
Member

Are you using webpack-dev-server 2.x or 1.x? It could be due to #357. If so, it will be fixed in the next 1.x version.

@igorsantos07
Copy link
Author

we're currently at 1.14.1. thanks for the lightning response :)

@igorsantos07
Copy link
Author

That doesn't seem to be the same issue, @SpaceK33z... I manually added the line from #357 and it didn't make a difference - docker still timeouts when stopping the container..

From looking into the docs, docker stop sends SIGTERM to the process and, after 10secs, SIGKILL.
Running the project directly in my machine, it seems to respond fine to SIGTERM (see complete output below). However, from inside the machine I'm not able to get a response from kill -15 1 nor kill -9 1; the output of ps aux stays the same.


$ npm start
> project@1.0.0 start /home/me/dev/project
> node server.js --env=dev

Listening at localhost:8000
Terminated

npm ERR! Linux 3.13.0-85-generic
npm ERR! argv "/home/me/.nvm/versions/node/v5.8.0/bin/node" "/home/me/.nvm/versions/node/v5.8.0/bin/npm" "start"
npm ERR! node v5.8.0
npm ERR! npm  v3.7.3
npm ERR! code ELIFECYCLE
npm ERR! project@1.0.0 start: `node server.js --env=dev`
npm ERR! Exit status 143
npm ERR! 
npm ERR! Failed at the project@1.0.0 start script 'node server.js --env=dev'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the project package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node server.js --env=dev
[...]

@SpaceK33z
Copy link
Member

SpaceK33z commented Aug 21, 2016

Okay, could you try if manually applying #352 works for you (and using the new flag of course)?

@igorsantos07
Copy link
Author

You got it now. --stdin works with that patch :)

@igorsantos07 igorsantos07 changed the title Good way to stop server.js through CLI? Graceful way to stop server.js through CLI/Docker? Aug 21, 2016
@SpaceK33z
Copy link
Member

Nice! There will be a 1.x release about not too long.

@igorsantos07
Copy link
Author

Actually, I have no idea of what's going on. Even by commenting out the option, both patches, removing and recreating the container... The stop procedure is taking < 4s...
Will keep this issue as a reminder if the issue happen again :/

@SpaceK33z
Copy link
Member

I'm closing this issue because of inactivity. Feel free to comment, and we can always re-open it again.

@40thieves
Copy link

I'm having the same issue on 2.1.0-beta.10. I am also unable to kill 1 or kill -9 1 from inside the machine. Looking at the source it seems that the patch in #352 has already been applied.

I'm sure if I'm understanding what the --stdin flag in the thread means? I'm running server as an executable (unsure of the wording here - I'm running node devserver.js which is new-ing up a webpack-dev-server instance). I've tried stdin: true as a config option and it doesn't seem to help.

Any advice?

@lucsky
Copy link
Contributor

lucsky commented Feb 7, 2017

Having the same problem still, but I don't think it's a webpack-dev-server issue, the problem is exactly the same if I do webpack --watch.

@lucsky
Copy link
Contributor

lucsky commented Feb 12, 2017

Just found this in the Docker documentation:

Note: A process running as PID 1 inside a container is treated specially by Linux: it ignores any signal with the default action. So, the process will not terminate on SIGINT or SIGTERM unless it is coded to do so.

(source: https://docs.docker.com/engine/reference/run/#/foreground)

I wonder if that could be the reason behind all this.

(poke @SpaceK33z)

@SpaceK33z
Copy link
Member

Could be, I have no experience with Docker at all so can't help you with that.

@joshwiens
Copy link
Member

@SpaceK33z - I'm a Docker *nix guy.

Has anyone actually gone in and done a ps -eaf inside a container in question and had a look at the process || checked the syslog for any logging related to why SIGTERM is failing?

@joshwiens
Copy link
Member

@lucsky - You got a Dockerfile I can have a look at?

@batjko
Copy link

batjko commented Apr 10, 2017

I'm using webpack-dev-server 2.4.1 and I'm almost sure I have the same issue:

We run all our apps and services via docker-compose. In development mode, we build the local project, create a container from it and run webpack-dev-server for live-reload.

So then we can just docker-compose up and our app with all its dependent containers just starts up and we can work on the project as if we didn't use docker.

When we then Ctrl+C the whole compose thing, every container shuts down but the process doesn't return (apparently due to webpack-dev-server still running).

I don't know if the merged PR above (#787) was supposed to solve this? If so, what version is this released with?
Actually, I just tried with 2.4.2 (latest release) and it still doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants