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

Propagate SIGTERM for graceful shutdown #110

Merged
merged 1 commit into from
Oct 23, 2019
Merged

Conversation

jieyu
Copy link
Contributor

@jieyu jieyu commented Oct 22, 2019

If the process receiving the signal is PID 1, it gets special treatment
by the kernel; if it hasn't registered a handler for the signal, the
kernel won't fall back to default behavior, and nothing happens. Prior
to this patch, the entrypoint script is PID 1 in the container, and by
default, shell does not register SIGTERM handler. As a result, docker stop will not work properly when trying to gracefully shutdown the
container.

This patch adds tini to be the PID 1 in the container to do PID 1
things, and correctly propagate the SIGTERM signal.

If the process receiving the signal is PID 1, it gets special treatment
by the kernel; if it hasn't registered a handler for the signal, the
kernel won't fall back to default behavior, and nothing happens. Prior
to this patch, the entrypoint script is PID 1 in the container, and by
default, shell does not register SIGTERM handler. As a result, `docker
stop` will not work properly when trying to gracefully shutdown the
container.

This patch adds `tini` to be the PID 1 in the container to do PID 1
things, and correctly propagate the SIGTERM signal.
@jimmidyson
Copy link

Why not just update https://github.com/mintel/dex-k8s-authenticator/blob/master/entrypoint.sh#L9 to use:

exec /app/bin/dex-k8s-authenticator $@

@jieyu
Copy link
Contributor Author

jieyu commented Oct 22, 2019

@jimmidyson using exec is still not ideal. the go program might just assume using the default SIGTERM handler, which would kill itself if it's not PID1. But that behavior is not the case if it's running as PID 1. Plus, normally, a program won't do PID 1 things like reaping processes that reparented to it.

@nabadger
Copy link
Contributor

Thanks both - bit of an oversight on my part to not use this originally. 👍

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

Successfully merging this pull request may close these issues.

3 participants