Repository navigation
fix(grafana): forward SIGTERM from the entrypoint to Grafana - #9444
Open
KennethWKZ wants to merge 1 commit into
Open
KennethWKZ wants to merge 1 commit into
KennethWKZ wants to merge 1 commit into
Conversation
The entrypoint starts Grafana in the background and stays PID 1 while it sets up the datasource and waits. A PID 1 with no handler never receives SIGTERM, so docker stop could not reach Grafana: it was killed after the 10 s grace period (exit 137) instead of shutting down cleanly. Trap TERM and INT, forward the signal to Grafana and wait for it to exit. docker stop now takes about 1.5 s and exits 0. Signed-off-by: Kenneth Wong <17061293+KennethWKZ@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The dashboard image's
grafana/scripts/entrypoint.shstarts Grafana in the background (/run.sh "$@" &), sets up the datasource, then waits. The script stays PID 1 and has no signal handler. Linux does not deliver SIGTERM to a container's PID 1 unless PID 1 handles it, sodocker stop(anddocker compose upwhen it recreates the container) never reaches Grafana. Docker waits out the 10 second grace period and sends SIGKILL. Grafana never shuts down cleanly, and the container exits with 137.This PR traps TERM and INT in the entrypoint, forwards the signal to Grafana, waits for Grafana to exit, then exits 0.
Does this close any open issues?
No open issue. Found while recreating the dashboard container after config changes: every recreate took Grafana down for about 15 seconds and ended in a SIGKILL.
Screenshots
Not applicable (entrypoint script only).
Other Information
Tested with the dashboard image (Grafana 13.3.1, arm64):
SigCgt: 0000000000010002in/proc/1/status).docker stoptakes 10.2 s, the exit code is 137, and the log has no shutdown lines.SigCgt: 0000000000014002.docker stoptakes 0.7 to 1.5 s, the exit code is 0, and the log shows "Signal received; stopping Grafana" followed by Grafana's "All modules stopped".sh -npasses; the script still runs under BusyBoxsh.No tests or docs added: the entrypoint has no test harness, and the change only affects how the container stops.
Suggested label:
pr-type/bug-fix.