Skip to content

fix(grafana): forward SIGTERM from the entrypoint to Grafana - #9444

Open
KennethWKZ wants to merge 1 commit into
apache:mainfrom
KennethWKZ:fix/grafana-entrypoint-sigterm
Open

KennethWKZ wants to merge 1 commit into
apache:mainfrom
KennethWKZ:fix/grafana-entrypoint-sigterm

Conversation

@KennethWKZ

Copy link
Copy Markdown
Contributor

Summary

The dashboard image's grafana/scripts/entrypoint.sh starts 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, so docker stop (and docker compose up when 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):

  • Before: PID 1 has no SIGTERM handler (SigCgt: 0000000000010002 in /proc/1/status). docker stop takes 10.2 s, the exit code is 137, and the log has no shutdown lines.
  • After: SigCgt: 0000000000014002. docker stop takes 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 -n passes; the script still runs under BusyBox sh.

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.

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>
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.

1 participant

⌂ Proxy