Skip to content
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
9 changes: 3 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 9 additions & 5 deletions files/autopause/autopause-daemon.sh → files/auto/autopause-daemon.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

. /autopause/autopause-fcns.sh
. /auto/autopause-fcns.sh

# shellcheck source=../../scripts/start-utils
. "${SCRIPTS:-/}start-utils"
Expand Down Expand Up @@ -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
Expand All @@ -97,23 +97,27 @@ do
else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
logAutopause "No client reconnected - pausing"
/autopause/pause.sh
/auto/pause.sh
STATE=S
fi
fi
;;
XS)
# Stopped
if rcon_client_exists ; then
/autopause/resume.sh
/auto/resume.sh
fi
if java_running ; then
if java_clients_connected ; then
logAutopause "Client connected - waiting for disconnect"
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
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions files/autostop/autostop-daemon.sh → files/auto/autostop-daemon.sh
100755 → 100644
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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%
File renamed without changes.
3 changes: 2 additions & 1 deletion files/autopause/resume.sh → files/auto/resume.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/start-autopause
Original file line number Diff line number Diff line change
Expand Up @@ -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*$"
Expand Down Expand Up @@ -84,4 +84,4 @@ elif [[ -z "$MAX_TICK_TIME" ]] ; then
export MAX_TICK_TIME
fi

/autopause/autopause-daemon.sh &
/auto/autopause-daemon.sh &
2 changes: 1 addition & 1 deletion scripts/start-autostop
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
6 changes: 3 additions & 3 deletions scripts/start-finalExec
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion scripts/start-rconcmds
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
21 changes: 10 additions & 11 deletions scripts/start-setupServerProperties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down