-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Gracefully shutdown services in Docker container #8486
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
Conversation
|
I've prepared a stage. Click to open. |
|
@kfei Thanks for this PR, it is awesome and I really like the graceful shutdown. Is it needed to make the other changes to the docker/Dockerfile? The shutdown works fine but if I boot according to the instructions in the docker/readme I get: |
|
If the changes are needed please ensure to update the docker/readme accordingly if needed. |
|
@dosire |
|
@kfei Thanks for your response. Please help me understand this. Does the |
|
@dosire |
|
It's generally a bad idea to use ENTRYPOINT instead of CMD. In that case it will make this command not working: |
|
@ayufan Thanks for your reminder. I didn't notice that it conflicts with README. I agree with you that ENTRYPOINT can sometimes confuse new Docker users. But it is required for dealing with signals. So I improved the wrapper to support the data volume container use case (kinda old-fashioned IMO) from README. Please have a look at that. |
95e1d3b to
0a066ba
Compare
|
It is not entirely true. There are two variants of CMD (one with brackets Kamil On Thursday, January 8, 2015, LIN, KE-FEI notifications@github.com wrote:
Kamil Trzciński |
0a066ba to
a78e02d
Compare
|
@ayufan You're right. I did not notice that CMD can also act as PID1. I've update my PR to use CMD instead. Thanks! |
|
Thanks everyone, please let me know when it's updated. |
|
@dosire It's updated. The commits on my branch are squashed. Please have a look at that. |
|
@kfei Can I run it based on the existing README documentation? |
|
@dosire Yes it's compatible with README now. |
|
@kfei Can you rebase? |
The problem is `docker stop` only sends SIGTERM to the PID 1 inside the container, and the PID 1 (`/bin/sh -c ...`) does not take care of signals. Hence the services (e.g., postgresql, redis, sidekiq, etc) never have chances to graceful shutdown. Docker just kills the container after its 10 seconds timeout by default. What this commit does: 1) Add a wrapper as the default executable of Docker container. Which starts services through `runit`, reconfigure Gitlab by `gitlab-ctl` and gracefully shutdown all services when a SIGTERM is received. 2) Create an `assets` directory for assets. 3) Add `.dockerignore` file. Now you'll see the following log messages after `docker stop`: ``` SIGTERM signal received, try to gracefully shutdown all services... ok: down: logrotate: 1s, normally up ok: down: nginx: 0s, normally up ok: down: postgresql: 1s, normally up ok: down: redis: 0s, normally up ok: down: sidekiq: 0s, normally up ok: down: unicorn: 0s, normally up ``` Signed-off-by: kfei <kfei@kfei.net>
a78e02d to
9338c63
Compare
|
@Razer6 Sure. Rebased! |
Gracefully shutdown services in Docker container
|
Thanks @kfei, I merged it, can you test once more to verify everything still works? |
The problem is
docker stoponly sends SIGTERM to the PID 1 inside the container, and the PID 1 (/bin/sh -c ...) does not take care of signals. Hence the services (e.g., postgresql, redis, sidekiq, etc) never have chances to graceful shutdown. Docker just kills the container after its 10 seconds timeout by default.What this commit does:
services through
runit, reconfigure Gitlab bygitlab-ctlandgracefully shutdown all services when a SIGTERM is received.
assetsdirectory for assets..dockerignorefile.Now you'll see the following log messages after
docker stop:Signed-off-by: kfei kfei@kfei.net