Wire optional graceful announce-before-stop into the entrypoint (#651)

This commit is contained in:
Robert Morris authored and GitHub committed 2026-06-23 16:58:41 -05:00
1 parent c4d868eba7
commit 612fb2479e
3 files changed
+45 -1

No files matched your search

+4 -1
View File
@@ -18,7 +18,10 @@ VOLUME ["/data"]
WORKDIR /data
ENTRYPOINT ["/usr/local/bin/entrypoint-demoter", "--match", "/data", "--debug", "--stdin-on-term", "stop", "/opt/bedrock-entry.sh"]
# demoter-entry.sh execs into entrypoint-demoter (PID 1). By default it builds the
# same args as before (--match /data --debug --stdin-on-term stop /opt/bedrock-entry.sh);
# set STOP_SERVER_ANNOUNCE_DELAY to opt into a graceful announce-then-wait before stop.
ENTRYPOINT ["/opt/demoter-entry.sh"]
ARG APPS_REV=1
ARG GITHUB_BASEURL=https://github.com
+2
View File
@@ -74,6 +74,8 @@ For Minecraft Java Edition you'll need to use this image instead:
- `MC_PACK` (no default): Path inside the container to a single archive file (e.g. `.mcpack`, `.mcworld`, `.mctemplate`, `.mcaddon`, or any zip) or to a directory with the same layout. At startup the archive is unpacked (or the directory is read): top-level `behavior_packs/` is merged into `behavior_packs/`, top-level `resource_packs/` into `resource_packs/`, and all other content (when `level.dat` is present) into `worlds/{LEVEL_NAME}`. For `.mcaddon` archives, which use root-level `data/` (behavior) and `resources/` (resource) folders instead of `behavior_packs/` and `resource_packs/`, these are detected and installed automatically using the pack UUID from each manifest as the folder name.
- `FORCE_WORLD_COPY` (default `false`): When `MC_PACK` contains a world (`level.dat`), set to `true` to remove and replace the existing `worlds/{LEVEL_NAME}` on every startup; otherwise the world is copied only when it does not exist.
- `FORCE_PACK_COPY` (default `false`): When `MC_PACK` contains `behavior_packs/` or `resource_packs/`, set to `true` to remove and replace existing pack folders with the same name on every startup; otherwise each pack is copied only when it does not already exist.
- `STOP_SERVER_ANNOUNCE_DELAY` (no default — disabled): opt into a graceful shutdown announcement. When set to a positive whole number of seconds, a heads-up line is written to the server console on container stop (`SIGTERM`); after that many seconds the server is sent `stop` (the usual clean-save shutdown). Unset or `0` keeps the previous behavior of stopping immediately. A second `SIGTERM` skips the remaining wait. Keep the value shorter than the container's stop grace period (e.g. `docker stop -t`, ECS `stopTimeout`, or an EC2 Spot interruption's ~2‑minute window) so the world save isn't cut short by `SIGKILL`.
- `STOP_SERVER_ANNOUNCE` (default `say Server shutting down in %delay% seconds`): the console line written as the announcement when `STOP_SERVER_ANNOUNCE_DELAY` is active. The `%delay%` token is replaced with the delay's whole-second value. Any server command works (e.g. a `say` or `tellraw`).
### Server Properties
+39
View File
@@ -0,0 +1,39 @@
#!/bin/bash
set -eo pipefail
# Entrypoint wrapper that launches entrypoint-demoter (as PID 1) for the Bedrock
# server, optionally enabling a graceful "announce, wait, then stop" on SIGTERM.
#
# Why a wrapper: entrypoint-demoter is PID 1 and handles SIGTERM by writing the
# --stdin-on-term message ("stop") to the server's stdin (the save-clean path).
# To also warn players first, its v0.5.0 --stdin-on-term-announce / -delay flags
# must be present on the command line *before* the process starts, so we build the
# argument list here from the environment and exec into it.
#
# Default behaviour is UNCHANGED: with no env set, SIGTERM still sends "stop"
# immediately (same args as the previous static ENTRYPOINT).
#
# Opt-in graceful shutdown:
# STOP_SERVER_ANNOUNCE_DELAY Whole seconds to wait between the announce and the
# stop. Unset or 0 => disabled (immediate stop).
# Keep it shorter than the container's stop grace
# period (docker `stop -t` / ECS stopTimeout / a Spot
# interruption's 2-minute window) so the world save
# isn't cut short by SIGKILL.
# STOP_SERVER_ANNOUNCE Console line written as the heads-up. The %delay%
# token is replaced by entrypoint-demoter with the
# whole-second value of the delay.
# Default: "say Server shutting down in %delay% seconds"
demoterArgs=(--match /data --debug)
delay="${STOP_SERVER_ANNOUNCE_DELAY:-0}"
if [[ "${delay}" =~ ^[0-9]+$ ]] && (( delay > 0 )); then
announce="${STOP_SERVER_ANNOUNCE:-say Server shutting down in %delay% seconds}"
demoterArgs+=(--stdin-on-term-announce "${announce}" --stdin-on-term-delay "${delay}s")
fi
demoterArgs+=(--stdin-on-term stop)
exec /usr/local/bin/entrypoint-demoter "${demoterArgs[@]}" /opt/bedrock-entry.sh