|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -eo pipefail |
| 4 | + |
| 5 | +# Entrypoint wrapper that launches entrypoint-demoter (as PID 1) for the Bedrock |
| 6 | +# server, optionally enabling a graceful "announce, wait, then stop" on SIGTERM. |
| 7 | +# |
| 8 | +# Why a wrapper: entrypoint-demoter is PID 1 and handles SIGTERM by writing the |
| 9 | +# --stdin-on-term message ("stop") to the server's stdin (the save-clean path). |
| 10 | +# To also warn players first, its v0.5.0 --stdin-on-term-announce / -delay flags |
| 11 | +# must be present on the command line *before* the process starts, so we build the |
| 12 | +# argument list here from the environment and exec into it. |
| 13 | +# |
| 14 | +# Default behaviour is UNCHANGED: with no env set, SIGTERM still sends "stop" |
| 15 | +# immediately (same args as the previous static ENTRYPOINT). |
| 16 | +# |
| 17 | +# Opt-in graceful shutdown: |
| 18 | +# STOP_SERVER_ANNOUNCE_DELAY Whole seconds to wait between the announce and the |
| 19 | +# stop. Unset or 0 => disabled (immediate stop). |
| 20 | +# Keep it shorter than the container's stop grace |
| 21 | +# period (docker `stop -t` / ECS stopTimeout / a Spot |
| 22 | +# interruption's 2-minute window) so the world save |
| 23 | +# isn't cut short by SIGKILL. |
| 24 | +# STOP_SERVER_ANNOUNCE Console line written as the heads-up. The %delay% |
| 25 | +# token is replaced by entrypoint-demoter with the |
| 26 | +# whole-second value of the delay. |
| 27 | +# Default: "say Server shutting down in %delay% seconds" |
| 28 | + |
| 29 | +demoterArgs=(--match /data --debug) |
| 30 | + |
| 31 | +delay="${STOP_SERVER_ANNOUNCE_DELAY:-0}" |
| 32 | +if [[ "${delay}" =~ ^[0-9]+$ ]] && (( delay > 0 )); then |
| 33 | + announce="${STOP_SERVER_ANNOUNCE:-say Server shutting down in %delay% seconds}" |
| 34 | + demoterArgs+=(--stdin-on-term-announce "${announce}" --stdin-on-term-delay "${delay}s") |
| 35 | +fi |
| 36 | + |
| 37 | +demoterArgs+=(--stdin-on-term stop) |
| 38 | + |
| 39 | +exec /usr/local/bin/entrypoint-demoter "${demoterArgs[@]}" /opt/bedrock-entry.sh |
0 commit comments