-
-
Notifications
You must be signed in to change notification settings - Fork 296
Expand file tree
/
Copy pathdemoter-entry.sh
More file actions
executable file
·39 lines (33 loc) · 1.92 KB
/
Copy pathdemoter-entry.sh
File metadata and controls
executable file
·39 lines (33 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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