diff --git a/Dockerfile b/Dockerfile index c0c33883..d245b960 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/README.md b/README.md index 9b3df62a..cfb04ba8 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ By default, the container will download the latest version of the "vanilla" [Min * [Enabling Autopause](#enabling-autopause) * [Running on RaspberryPi](#running-on-raspberrypi) - + @@ -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 diff --git a/health.sh b/bin/mc-health similarity index 91% rename from health.sh rename to bin/mc-health index a3f14aa6..09aa9198 100755 --- a/health.sh +++ b/bin/mc-health @@ -1,5 +1,6 @@ #!/bin/bash +# shellcheck source=../start-utils . ${SCRIPTS:-/}start-utils if isTrue "${DISABLE_HEALTHCHECK}"; then diff --git a/bin/mc-send-to-console b/bin/mc-send-to-console new file mode 100755 index 00000000..a83f0e81 --- /dev/null +++ b/bin/mc-send-to-console @@ -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}" \ No newline at end of file diff --git a/mcstatus b/bin/mcstatus similarity index 100% rename from mcstatus rename to bin/mcstatus diff --git a/start-finalExec b/start-finalExec index 5359fe7f..3bb80e77 100755 --- a/start-finalExec +++ b/start-finalExec @@ -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