Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mc-send-to-console support #228

Merged
merged 2 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ RUN easy-add --var version=1.5.0 --var app=restify --file {{.app}} --from https:

RUN easy-add --var version=0.5.0 --var app=mc-monitor --file {{.app}} --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_linux_${ARCH}.tar.gz

COPY *.sh /opt/
COPY scripts/* /opt/
COPY bin/* /usr/local/bin/

COPY property-definitions.json /etc/bds-property-definitions.json

Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,17 @@ For more information [FoxyNoTail](https://www.youtube.com/watch?v=nWBM4UFm0rQ&t=

For more information about managing Bedrock Dedicated Servers in general, [check out this Reddit post](https://old.reddit.com/user/ProfessorValko/comments/9f438p/bedrock_dedicated_server_tutorial/).

## Executing server commands
## Sending commands to the server

To send individual commands to the server, exec `mc-send-to-console` inside the container passing the server command as its arguments. For example, the following would disable the `falldamage` gamerule:

```shell
docker exec $container mc-send-to-console gamerule falldamage false
```

> NOTE: to see the output/results of the command, use `docker logs -f $container`

## Interactive server console

Assuming you started container with stdin and tty enabled (such as using `-it`), you can attach to the container's console by its name or ID using:

Expand Down
15 changes: 15 additions & 0 deletions bin/mc-send-to-console
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

: "${CONSOLE_IN_NAMED_PIPE:=/var/run/bds-stdin}"

if [ $# = 0 ]; then
echo "ERROR: pass console commands as arguments"
exit 1
fi

if [ ! -p "${CONSOLE_IN_NAMED_PIPE}" ]; then
echo "ERROR: named pipe ${CONSOLE_IN_NAMED_PIPE} is missing"
exit 1
fi

/usr/local/bin/entrypoint-demoter --match /data bash -c "echo $* > '${CONSOLE_IN_NAMED_PIPE}'"
6 changes: 5 additions & 1 deletion bedrock-entry.sh → scripts/bedrock-entry.sh
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,8 @@ set-property --file server.properties --bulk /etc/bds-property-definitions.json
export LD_LIBRARY_PATH=.

echo "Starting Bedrock server..."
exec ./bedrock_server-${VERSION}

mkfifo /var/run/bds-stdin
# See https://serverfault.com/a/1088115/196770
sleep infinity > /var/run/bds-stdin &
exec ./bedrock_server-"${VERSION}" < /var/run/bds-stdin