Added mc-send-to-console as rcon/attach alternative

#1071
This commit is contained in:
Geoff Bourne 2021-10-09 11:34:37 -05:00
parent 1d41593a84
commit c3cf892e40
6 changed files with 49 additions and 27 deletions

View file

@ -53,7 +53,7 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \
--from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz
RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \
--var version=1.7.0 --var app=mc-server-runner --file {{.app}} \
--var version=1.8.0 --var app=mc-server-runner --file {{.app}} \
--from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz
RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \
@ -65,8 +65,6 @@ RUN curl -fsSL https://github.com/itzg/mc-image-helper/releases/download/v${MC_H
| tar -C /usr/share -zxf - \
&& ln -s /usr/share/mc-image-helper-${MC_HELPER_VERSION}/bin/mc-image-helper /usr/bin
COPY mcstatus /usr/local/bin
VOLUME ["/data"]
COPY server.properties /tmp/server.properties
COPY log4j2.xml /tmp/log4j2.xml
@ -83,13 +81,13 @@ ENV UID=1000 GID=1000 \
AUTOPAUSE_PERIOD=10 AUTOPAUSE_KNOCK_INTERFACE=eth0
COPY start* /
COPY health.sh /
COPY bin/ /usr/local/bin/
COPY bin/mc-health /health.sh
ADD files/autopause /autopause
RUN dos2unix /start* && chmod +x /start*
RUN dos2unix /health.sh && chmod +x /health.sh
RUN dos2unix /autopause/* && chmod +x /autopause/*.sh
RUN dos2unix /start* && chmod +x /start* \
&& dos2unix /autopause/* && chmod +x /autopause/*.sh
ENTRYPOINT [ "/start" ]
HEALTHCHECK --start-period=1m CMD /health.sh
HEALTHCHECK --start-period=1m CMD mc-health

View file

@ -151,8 +151,7 @@ docker exec -i mc rcon-cli
Note: The `-i` is required for interactive use of rcon-cli.
To run a simple, one-shot command, such as stopping a Minecraft server, pass the command as
arguments to `rcon-cli`, such as:
To run a simple, one-shot command, such as stopping a Minecraft server, pass the command as arguments to `rcon-cli`, such as:
```
docker exec mc rcon-cli stop
@ -160,6 +159,14 @@ docker exec mc rcon-cli stop
_The `-i` is not needed in this case._
If rcon is disabled you can send commands by passing them as arguments to the packaged `mc-send-to-console` script. For example, a player can be op'ed in the container `mc` with:
```shell
docker exec mc mc-send-to-console op player
| |
+- container name +- Minecraft commands start here
```
In order to attach and interact with the Minecraft server, add `-it` when starting the container, such as
docker run -d -it -p 25565:25565 --name mc itzg/minecraft-server

View file

@ -1,5 +1,6 @@
#!/bin/bash
# shellcheck source=../start-utils
. ${SCRIPTS:-/}start-utils
if isTrue "${DISABLE_HEALTHCHECK}"; then

15
bin/mc-send-to-console Executable file
View file

@ -0,0 +1,15 @@
#!/bin/bash
: "${CONSOLE_IN_NAMED_PIPE:=/tmp/minecraft-console-in}"
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
echo "$@" > "${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}"

View file

@ -172,29 +172,32 @@ function copyFilesForCurseForge() {
cp -f /data/eula.txt "${FTB_DIR}/"
}
mcServerRunnerArgs="--stop-duration ${STOP_DURATION:-60}s"
mcServerRunnerArgs=(
--stop-duration "${STOP_DURATION:-60}s"
--named-pipe "${CONSOLE_IN_NAMED_PIPE:-/tmp/minecraft-console-in}"
)
if [[ ${STOP_SERVER_ANNOUNCE_DELAY} ]]; then
mcServerRunnerArgs="${mcServerRunnerArgs} --stop-server-announce-delay ${STOP_SERVER_ANNOUNCE_DELAY}s"
mcServerRunnerArgs+=(--stop-server-announce-delay "${STOP_SERVER_ANNOUNCE_DELAY}s")
fi
if [[ ${TYPE} == "CURSE_INSTANCE" ]]; then
if isTrue ${DEBUG_EXEC}; then
set -x
fi
exec mc-server-runner ${mcServerRunnerArgs} \
exec mc-server-runner "${mcServerRunnerArgs[@]}" \
--cf-instance-file "${CURSE_INSTANCE_JSON}" \
java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar _SERVERJAR_ "$@" $EXTRA_ARGS
elif [[ ${TYPE} == "CURSEFORGE" && "${SERVER}" ]]; then
copyFilesForCurseForge
cd "${FTB_DIR}"
cd "${FTB_DIR}" || (log "ERROR: can't go into ${FTB_DIR}"; exit 1)
log "Starting CurseForge server in ${FTB_DIR}..."
if isTrue ${DEBUG_EXEC}; then
set -x
fi
exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $(basename "${SERVER}") "$@" $EXTRA_ARGS
exec mc-server-runner ${bootstrapArgs} "${mcServerRunnerArgs[@]}" java $JVM_XX_OPTS $JVM_OPTS $expandedDOpts -jar $(basename "${SERVER}") "$@" $EXTRA_ARGS
elif [[ ${TYPE} == "CURSEFORGE" ]]; then
mcServerRunnerArgs="${mcServerRunnerArgs} --shell bash"
mcServerRunnerArgs+=(--shell bash)
copyFilesForCurseForge
@ -209,15 +212,13 @@ EOF
sed -i "s/MAX_RAM=[^;]*/MAX_RAM=${MAX_MEMORY}/" "${FTB_DIR}/settings.cfg"
fi
cd "${FTB_DIR}"
cd "${FTB_DIR}" || (log "ERROR: can't go into ${FTB_DIR}"; exit 1)
log "Running FTB ${FTB_SERVER_START} in ${FTB_DIR} ..."
finalArgs=(
"${FTB_SERVER_START}"
)
finalArgs="${FTB_SERVER_START}"
if isTrue ${SETUP_ONLY:=false}; then
echo "SETUP_ONLY: ${finalArgs[@]}"
echo "SETUP_ONLY: ${finalArgs}"
exit
fi
@ -227,12 +228,12 @@ EOF
if isTrue ${EXEC_DIRECTLY:-false}; then
"${finalArgs[@]}"
else
exec mc-server-runner ${mcServerRunnerArgs} "${finalArgs[@]}"
exec mc-server-runner "${mcServerRunnerArgs[@]}" "${finalArgs[@]}"
fi
elif [[ -x run.sh ]]; then
log "Using Forge supplied run.sh script..."
echo $JVM_XX_OPTS $JVM_OPTS $expandedDOpts > user_jvm_args.txt
exec mc-server-runner ${mcServerRunnerArgs} --shell bash run.sh
exec mc-server-runner "${mcServerRunnerArgs[@]}" --shell bash run.sh
else
# If we have a bootstrap.txt file... feed that in to the server stdin
if [ -f /data/bootstrap.txt ]; then
@ -245,12 +246,12 @@ else
$JVM_XX_OPTS
$JVM_OPTS
$expandedDOpts
-jar $SERVER
-jar "$SERVER"
"$@" $EXTRA_ARGS
)
if isTrue ${SETUP_ONLY:=false}; then
echo "SETUP_ONLY: java ${finalArgs[@]}"
echo "SETUP_ONLY: java ${finalArgs[*]}"
exit
fi
@ -261,7 +262,7 @@ else
if isTrue ${EXEC_DIRECTLY:-false}; then
exec java "${finalArgs[@]}"
else
exec mc-server-runner ${bootstrapArgs} ${mcServerRunnerArgs} java "${finalArgs[@]}"
exec mc-server-runner ${bootstrapArgs} "${mcServerRunnerArgs[@]}" java "${finalArgs[@]}"
fi
fi