diff --git a/Dockerfile b/Dockerfile index 6c41bd878ca..0d97ac1149f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -64,13 +64,10 @@ ENV TYPE=VANILLA VERSION=LATEST EULA="" UID=1000 GID=1000 RCON_PASSWORD=minecraf COPY --chmod=755 scripts/start* / COPY --chmod=755 bin/ /usr/local/bin/ COPY --chmod=755 bin/mc-health /health.sh -COPY --chmod=644 files/server.properties /tmp/server.properties -COPY --chmod=644 files/log4j2.xml /tmp/log4j2.xml -COPY --chmod=755 files/autopause /autopause -COPY --chmod=755 files/autostop /autostop -COPY --chmod=755 files/rconcmds /rconcmds +COPY --chmod=644 files/log4j2.xml /image/log4j2.xml +COPY --chmod=755 files/auto /auto -RUN dos2unix /start* /autopause/* /autostop/* /rconcmds/* +RUN dos2unix /start* /auto/* ENTRYPOINT [ "/start" ] HEALTHCHECK --start-period=1m --interval=5s --retries=24 CMD mc-health diff --git a/files/rconcmds/rcon-cmds-daemon.sh b/bin/rcon-cmds-daemon.sh similarity index 97% rename from files/rconcmds/rcon-cmds-daemon.sh rename to bin/rcon-cmds-daemon.sh index 9774c5569fd..4b1c9a2529a 100644 --- a/files/rconcmds/rcon-cmds-daemon.sh +++ b/bin/rcon-cmds-daemon.sh @@ -8,8 +8,8 @@ : "${RCON_CMDS_PERIOD:=10}" # needed for the clients connected function residing in autopause -# shellcheck source=/autopause/autopause-fcns.sh -. /autopause/autopause-fcns.sh +# shellcheck source=../auto/autopause-fcns.sh +. /auto/autopause-fcns.sh # shellcheck source=start-utils . ${SCRIPTS:-/}start-utils diff --git a/files/autopause/autopause-daemon.sh b/files/auto/autopause-daemon.sh old mode 100755 new mode 100644 similarity index 91% rename from files/autopause/autopause-daemon.sh rename to files/auto/autopause-daemon.sh index e71006ea43d..8fe4a06a15d --- a/files/autopause/autopause-daemon.sh +++ b/files/auto/autopause-daemon.sh @@ -1,6 +1,6 @@ #!/bin/bash -. /autopause/autopause-fcns.sh +. /auto/autopause-fcns.sh # shellcheck source=../../scripts/start-utils . "${SCRIPTS:-/}start-utils" @@ -76,7 +76,7 @@ do else if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then logAutopause "No client connected since startup / knocked - pausing" - /autopause/pause.sh + /auto/pause.sh STATE=S fi fi @@ -97,7 +97,7 @@ do else if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then logAutopause "No client reconnected - pausing" - /autopause/pause.sh + /auto/pause.sh STATE=S fi fi @@ -105,7 +105,7 @@ do XS) # Stopped if rcon_client_exists ; then - /autopause/resume.sh + /auto/resume.sh fi if java_running ; then if java_clients_connected ; then @@ -113,7 +113,11 @@ do STATE=E else TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_KN)) - logAutopause "Server was knocked - waiting for clients or timeout" + from=unknown + if [ -e /var/log/knocked-source ]; then + from=$(cat /var/log/knocked-source) + fi + logAutopause "Server was knocked from $from - waiting for clients or timeout" STATE=K fi fi diff --git a/files/autopause/autopause-fcns.sh b/files/auto/autopause-fcns.sh old mode 100755 new mode 100644 similarity index 100% rename from files/autopause/autopause-fcns.sh rename to files/auto/autopause-fcns.sh diff --git a/files/autostop/autostop-daemon.sh b/files/auto/autostop-daemon.sh old mode 100755 new mode 100644 similarity index 95% rename from files/autostop/autostop-daemon.sh rename to files/auto/autostop-daemon.sh index b6a86581e79..5b9aa0c44f3 --- a/files/autostop/autostop-daemon.sh +++ b/files/auto/autostop-daemon.sh @@ -1,7 +1,7 @@ #!/bin/bash # needed for the clients connected function residing in autopause -. /autopause/autopause-fcns.sh +. /auto/autopause-fcns.sh # shellcheck source=../../scripts/start-utils . "${SCRIPTS:-/}start-utils" @@ -40,7 +40,7 @@ do else if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then logAutostop "No client connected since startup - stopping server" - /autostop/stop.sh + /auto/stop.sh exit 0 fi fi @@ -61,7 +61,7 @@ do else if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then logAutostop "No client reconnected - stopping" - /autostop/stop.sh + /auto/stop.sh exit 0 fi fi diff --git a/files/autopause/knockd-config.cfg b/files/auto/knockd-config.cfg similarity index 70% rename from files/autopause/knockd-config.cfg rename to files/auto/knockd-config.cfg index 768e6c868f8..0334ad05132 100644 --- a/files/autopause/knockd-config.cfg +++ b/files/auto/knockd-config.cfg @@ -3,13 +3,13 @@ [unpauseMCServer-server] sequence = 25565 seq_timeout = 1 - command = /autopause/resume.sh + command = /auto/resume.sh %IP% tcpflags = syn [unpauseMCServer-rcon] sequence = 25575 seq_timeout = 1 - command = /autopause/resume.sh + command = /auto/resume.sh %IP% tcpflags = syn [unpauseMCServer-bedrock] sequence = 19132:udp - command = /autopause/resume.sh + command = /auto/resume.sh %IP% diff --git a/files/autopause/pause.sh b/files/auto/pause.sh old mode 100755 new mode 100644 similarity index 100% rename from files/autopause/pause.sh rename to files/auto/pause.sh diff --git a/files/autopause/resume.sh b/files/auto/resume.sh old mode 100755 new mode 100644 similarity index 64% rename from files/autopause/resume.sh rename to files/auto/resume.sh index 0d483faaa5a..af55da95897 --- a/files/autopause/resume.sh +++ b/files/auto/resume.sh @@ -6,6 +6,7 @@ if isTrue "${DEBUG_AUTOPAUSE}"; then fi if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then - logAutopauseAction "Knocked, resuming Java process" + logAutopauseAction "Knocked from $1, resuming Java process" + echo "$1" > /var/log/knocked-source pkill -CONT java fi diff --git a/files/autostop/stop.sh b/files/auto/stop.sh old mode 100755 new mode 100644 similarity index 100% rename from files/autostop/stop.sh rename to files/auto/stop.sh diff --git a/scripts/start-autopause b/scripts/start-autopause index 4afdf4fb7a1..66fbbe60202 100755 --- a/scripts/start-autopause +++ b/scripts/start-autopause @@ -24,7 +24,7 @@ log "Autopause functionality enabled" isDebugging && set -x -cp /autopause/knockd-config.cfg /tmp/knockd-config.cfg +cp /auto/knockd-config.cfg /tmp/knockd-config.cfg # update server port to listen to regseq="^\s*sequence\s*=\s*$SERVER_PORT\s*$" @@ -84,4 +84,4 @@ elif [[ -z "$MAX_TICK_TIME" ]] ; then export MAX_TICK_TIME fi -/autopause/autopause-daemon.sh & +/auto/autopause-daemon.sh & diff --git a/scripts/start-autostop b/scripts/start-autostop index 38ce1edbf15..e21de3d7b3e 100755 --- a/scripts/start-autostop +++ b/scripts/start-autostop @@ -41,4 +41,4 @@ if ! [[ $AUTOSTOP_TIMEOUT_INIT =~ ^[0-9]+$ ]] ; then log "Warning: AUTOSTOP_TIMEOUT_INIT is not numeric, set to 1800 (seconds)" fi -/autostop/autostop-daemon.sh & +/auto/autostop-daemon.sh & diff --git a/scripts/start-finalExec b/scripts/start-finalExec index 1f5c7e3bf00..d45a8cdd948 100755 --- a/scripts/start-finalExec +++ b/scripts/start-finalExec @@ -83,7 +83,7 @@ if isTrue ${ENABLE_ROLLING_LOGS:-false}; then LOGFILE="/data/log4j2.xml" if [ ! -e "$LOGFILE" ]; then log "Creating log4j2.xml in ${LOGFILE}" - cp /tmp/log4j2.xml "$LOGFILE" + cp /image/log4j2.xml "$LOGFILE" else log "log4j2.xml already created, skipping" fi @@ -214,7 +214,7 @@ function copyFilesForCurseForge() { [ -f /data/ops.txt ] && cp -f /data/ops.txt "${FTB_DIR}/" [ -f /data/white-list.txt ] && cp -f /data/white-list.txt "${FTB_DIR}/" - if [ ! -e "${FTB_DIR}/server-icon.png" -a -e /data/server-icon.png ]; then + if [ ! -e "${FTB_DIR}/server-icon.png" ] && [ -e /data/server-icon.png ]; then cp -f /data/server-icon.png "${FTB_DIR}/" fi @@ -237,7 +237,7 @@ if [[ ${TYPE} == "CURSEFORGE" && "${SERVER}" ]]; then 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+=(--shell bash) diff --git a/scripts/start-rconcmds b/scripts/start-rconcmds index 67d4be87f54..69406cb306a 100644 --- a/scripts/start-rconcmds +++ b/scripts/start-rconcmds @@ -33,4 +33,4 @@ if [ "$RCON_CMDS_PERIOD" -eq "0" ] ; then log "Warning: RCON_CMDS_PERIOD must not be 0, set to 10 (seconds)" fi -/rconcmds/rcon-cmds-daemon.sh & +/usr/local/bin/rcon-cmds-daemon.sh & diff --git a/scripts/start-setupServerProperties b/scripts/start-setupServerProperties index 2e216ad0edb..bdd6ac6e39e 100755 --- a/scripts/start-setupServerProperties +++ b/scripts/start-setupServerProperties @@ -20,7 +20,7 @@ function setServerPropValue { else showValue="$value" fi - if grep "${prop}" "$SERVER_PROPERTIES" > /dev/null; then + if [ -f "$SERVER_PROPERTIES" ] && grep "${prop}" "$SERVER_PROPERTIES" > /dev/null; then debug "Setting ${prop} to '${showValue}' in ${SERVER_PROPERTIES}" sed -i "/^${prop}\s*=/ c ${prop}=${value//\\/\\\\}" "$SERVER_PROPERTIES" else @@ -43,13 +43,11 @@ function customizeServerProps { if [ -n "$WHITELIST" ] || [ -n "$WHITELIST_FILE" ] || isTrue "${ENABLE_WHITELIST:-false}"; then log "Enabling whitelist functionality" setServerPropValue "white-list" "true" + setServerPropValue "enforce-whitelist" "true" else log "Disabling whitelist functionality" setServerPropValue "white-list" "false" - fi - setServerProp "enforce-whitelist" ENFORCE_WHITELIST - if [[ $(grep "enforce-whitelist" $SERVER_PROPERTIES) != *true ]]; then - log "WARNING: whitelist enabled but not enforced. Set ENFORCE_WHITELIST=TRUE or update 'enforce-whitelist' in server.properties to enforce the whitelist." + setServerProp "enforce-whitelist" ENFORCE_WHITELIST fi # If not provided, generate a reasonable default message-of-the-day, @@ -213,7 +211,6 @@ fi if ! isTrue "${SKIP_SERVER_PROPERTIES:-false}"; then if [ ! -e "$SERVER_PROPERTIES" ]; then log "Creating server properties in ${SERVER_PROPERTIES}" - cp /tmp/server.properties "$SERVER_PROPERTIES" customizeServerProps elif [ -n "${OVERRIDE_SERVER_PROPERTIES}" ]; then case ${OVERRIDE_SERVER_PROPERTIES^^} in @@ -233,11 +230,13 @@ else fi if isTrue "${ENABLE_AUTOPAUSE}"; then - current_max_tick=$( grep 'max-tick-time' "$SERVER_PROPERTIES" | sed -r 's/( )+//g' | awk -F= '{print $2}' ) - if (( current_max_tick > 0 && current_max_tick < 86400000 )); then - log "Warning: The server.properties for the server doesn't have the Server Watchdog (effectively) disabled." - log "Warning (cont): Autopause functionality resuming the process might trigger the Watchdog and restart the server completely." - log "Warning (cont): Set the max-tick-time property to a high value (or disable the Watchdog with value -1 for versions 1.8.1+)." + if [ -f "$SERVER_PROPERTIES" ]; then + current_max_tick=$( grep 'max-tick-time' "$SERVER_PROPERTIES" | sed -r 's/( )+//g' | awk -F= '{print $2}' ) + if (( current_max_tick > 0 && current_max_tick < 86400000 )); then + log "Warning: The server.properties for the server doesn't have the Server Watchdog (effectively) disabled." + log " Autopause functionality resuming the process might trigger the Watchdog and restart the server completely." + log " Set the MAX_TICK_TIME env variable (or max-tick-time property) to a high value (or disable the Watchdog with value -1 for versions 1.8.1+)." + fi fi fi