Skip to content

Commit

Permalink
Prevent container start, if not TTY is attached
Browse files Browse the repository at this point in the history
  • Loading branch information
flobernd committed Mar 27, 2024
1 parent 6419ef7 commit ef03fa0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A Docker image for running [FTB](https://www.feed-the-beast.com/) Minecraft serv
### Example

```bash
docker run -it --rm --name minecraft-ftb \
docker run -itd --rm --name minecraft-ftb \
-v "/docker_data/minecraft:/var/lib/minecraft" \
-e "FTB_MODPACK_ID=119" \
-e "FTB_MODPACK_VERSION_ID=11614" \
Expand All @@ -15,12 +15,15 @@ docker run -it --rm --name minecraft-ftb \
ghcr.io/flobernd/minecraft-ftb
```

> [!NOTE]
> The modpack ID and the version ID are displayed on the right-hand side of the modpack info page. For example, the [Direwolf20 1.20 modpack](https://www.feed-the-beast.com/modpacks/119-ftb-presents-direwolf20-120) has the ID `119` and the latest version, as of today, is `11614`.
> [!WARNING]
> The server process does not shut down gracefully, if no TTY is present. Please pass the `--tty`/`-t` switch (Docker) or use `tty: true` (Docker Compose).
> [!IMPORTANT]
> [!WARNING]
> It is strongly recommended to set the `stop-timeout` / `stop_grace_period` to at least `60` seconds to avoid data loss when stopping the container.
> [!NOTE]
> It is recommended to pass the `--interactive`/`-i` switch (Docker) or use `stdin_open: true` (Docker Compose) to be able to use the server console after attaching to the container.
### Docker Compose Example

```yaml
Expand All @@ -29,6 +32,8 @@ services:
image: ghcr.io/flobernd/minecraft-ftb:latest
container_name: minecraft-ftb
restart: unless-stopped
tty: true
stdin_open: true
stop_grace_period: 1m
environment:
- "FTB_MODPACK_ID=119"
Expand All @@ -46,6 +51,9 @@ services:

The FTB modpack ID (*required*).

> [!NOTE]
> The modpack ID and the version ID are displayed on the right-hand side of the modpack info page. For example, the [Direwolf20 1.20 modpack](https://www.feed-the-beast.com/modpacks/119-ftb-presents-direwolf20-120) has the ID `119` and the latest version, as of today, is `11614`.

#### `FTB_MODPACK_VERSION_ID`

The FTB modpack version ID (*required*).
Expand Down
10 changes: 10 additions & 0 deletions minecraft-ftb/data/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ function check_environment() {
fi
}

function check_tty() {
# For some reason, the server process does not shut down gracefully, if no TTY is present ...

if [ ! -t 0 ] ; then
echo "Error: The server process requires a TTY. Please pass the '--tty' switch (Docker) or use 'tty: true' (Docker Compose)."
exit 1
fi
}

function patch_start_script() {
# We have to make sure the `start.sh` script uses `exec` to launch the server. SIGINT and
# other signals would not be forwarded to the Java process otherwise.
Expand Down Expand Up @@ -82,6 +91,7 @@ function confirm() {
}

if [ "$1" = "/var/lib/minecraft/start.sh" ]; then
check_tty
check_environment

local_pack_id=0
Expand Down
2 changes: 2 additions & 0 deletions minecraft-ftb/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ services:
image: flobernd/minecraft-ftb:latest
container_name: minecraft-ftb
restart: unless-stopped
tty: true
stdin_open: true
stop_grace_period: 1m
environment:
- "FTB_MODPACK_ID=119"
Expand Down

0 comments on commit ef03fa0

Please sign in to comment.