diff --git a/README.md b/README.md index 4b9ac404301..45fe6c42225 100644 --- a/README.md +++ b/README.md @@ -1699,6 +1699,8 @@ The following environment variables define the behaviour of auto-pausing: * `AUTOPAUSE_KNOCK_INTERFACE`, default `eth0`
Describes the interface passed to the `knockd` daemon. If the default interface does not work, run the `ifconfig` command inside the container and derive the interface receiving the incoming connection from its output. The passed interface must exist inside the container. Using the loopback interface (`lo`) does likely not yield the desired results. +> To troubleshoot, add `DEBUG_AUTOPAUSE=true` to see additional output + ## Autostop An option to stop the server after a specified time has been added for niche applications (e.g. billing saving on AWS Fargate). The function is incompatible with the Autopause functionality, as they basically cancel out each other. @@ -1721,6 +1723,8 @@ The following environment variables define the behaviour of auto-stopping: * `AUTOSTOP_PERIOD`, default `10` (seconds) describes period of the daemonized state machine, that handles the stopping of the server +> To troubleshoot, add `DEBUG_AUTOSTOP=true` to see additional output + ## Running on RaspberryPi To run this image on a RaspberryPi 3 B+, 4, or newer, use any of the image tags [list in the Java version section](#running-minecraft-server-on-different-java-version) that specify `armv7` for the architecture, which includes `itzg/minecraft-server:latest`. diff --git a/files/autopause/autopause-daemon.sh b/files/autopause/autopause-daemon.sh index e2f486087bf..e71006ea43d 100755 --- a/files/autopause/autopause-daemon.sh +++ b/files/autopause/autopause-daemon.sh @@ -2,8 +2,11 @@ . /autopause/autopause-fcns.sh -. ${SCRIPTS:-/}start-utils - +# shellcheck source=../../scripts/start-utils +. "${SCRIPTS:-/}start-utils" +if isTrue "${DEBUG_AUTOPAUSE}"; then + set -x +fi autopause_error_loop() { logAutopause "Available interfaces within the docker container:" @@ -39,7 +42,12 @@ if ! [[ -d "/sys/class/net/$AUTOPAUSE_KNOCK_INTERFACE" ]] ; then autopause_error_loop fi -sudo /usr/sbin/knockd -c /tmp/knockd-config.cfg -d -i "$AUTOPAUSE_KNOCK_INTERFACE" +knockdArgs=(-c /tmp/knockd-config.cfg -d -i "$AUTOPAUSE_KNOCK_INTERFACE") +if isTrue "${DEBUG_AUTOPAUSE}"; then + knockdArgs+=(-D) +fi + +sudo /usr/sbin/knockd "${knockdArgs[@]}" if [ $? -ne 0 ] ; then logAutopause "Failed to start knockd daemon." logAutopause "Probable cause: Unable to attach to interface \"$AUTOPAUSE_KNOCK_INTERFACE\"." @@ -50,12 +58,13 @@ STATE=INIT while : do + isTrue "${DEBUG_AUTOPAUSE}" && log "DEBUG: autopause state = $STATE" case X$STATE in XINIT) # Server startup if mc_server_listening ; then TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_INIT)) - logAutopause "MC Server listening for connections - stopping in $AUTOPAUSE_TIMEOUT_INIT seconds" + logAutopause "MC Server listening for connections - pausing in $AUTOPAUSE_TIMEOUT_INIT seconds" STATE=K fi ;; @@ -66,7 +75,7 @@ do STATE=E else if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then - logAutopause "No client connected since startup / knocked - stopping" + logAutopause "No client connected since startup / knocked - pausing" /autopause/pause.sh STATE=S fi @@ -76,7 +85,7 @@ do # Established if ! java_clients_connected ; then TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_EST)) - logAutopause "All clients disconnected - stopping in $AUTOPAUSE_TIMEOUT_EST seconds" + logAutopause "All clients disconnected - pausing in $AUTOPAUSE_TIMEOUT_EST seconds" STATE=I fi ;; @@ -87,7 +96,7 @@ do STATE=E else if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then - logAutopause "No client reconnected - stopping" + logAutopause "No client reconnected - pausing" /autopause/pause.sh STATE=S fi @@ -115,8 +124,8 @@ do esac if [[ "$STATE" == "S" ]] ; then # before rcon times out - sleep 2 + sleep 5 else - sleep $AUTOPAUSE_PERIOD + sleep "$AUTOPAUSE_PERIOD" fi done diff --git a/files/autopause/pause.sh b/files/autopause/pause.sh index bcd1a06c25c..19e6a43653f 100755 --- a/files/autopause/pause.sh +++ b/files/autopause/pause.sh @@ -1,6 +1,9 @@ #!/bin/bash . /start-utils +if isTrue "${DEBUG_AUTOPAUSE}"; then + set -x +fi if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; then # save world diff --git a/files/autopause/resume.sh b/files/autopause/resume.sh index 6ae5a8cfcfd..0d483faaa5a 100755 --- a/files/autopause/resume.sh +++ b/files/autopause/resume.sh @@ -1,6 +1,9 @@ #!/bin/bash . /start-utils +if isTrue "${DEBUG_AUTOPAUSE}"; then + set -x +fi if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then logAutopauseAction "Knocked, resuming Java process" diff --git a/files/autostop/autostop-daemon.sh b/files/autostop/autostop-daemon.sh index 0d6aa2ad83d..b6a86581e79 100755 --- a/files/autostop/autostop-daemon.sh +++ b/files/autostop/autostop-daemon.sh @@ -3,7 +3,11 @@ # needed for the clients connected function residing in autopause . /autopause/autopause-fcns.sh -. ${SCRIPTS:-/}start-utils +# shellcheck source=../../scripts/start-utils +. "${SCRIPTS:-/}start-utils" +if isTrue "${DEBUG_AUTOSTOP}"; then + set -x +fi # wait for java process to be started while : @@ -18,11 +22,12 @@ STATE=INIT while : do + isTrue "${DEBUG_AUTOSTOP}" && log "DEBUG: autostop state = $STATE" case X$STATE in XINIT) # Server startup if mc_server_listening ; then - TIME_THRESH=$(($(current_uptime)+$AUTOSTOP_TIMEOUT_INIT)) + TIME_THRESH=$(($(current_uptime)+AUTOSTOP_TIMEOUT_INIT)) logAutostop "MC Server listening for connections - stopping in $AUTOSTOP_TIMEOUT_INIT seconds" STATE=II fi diff --git a/files/autostop/stop.sh b/files/autostop/stop.sh index 1a9ed2f44dd..2629e2fa975 100755 --- a/files/autostop/stop.sh +++ b/files/autostop/stop.sh @@ -1,6 +1,9 @@ #!/bin/bash . /start-utils +if isTrue "${DEBUG_AUTOSTOP}"; then + set -x +fi logAutostopAction "Stopping Java process" kill -SIGTERM 1 diff --git a/scripts/start-autopause b/scripts/start-autopause index c2646726834..4afdf4fb7a1 100755 --- a/scripts/start-autopause +++ b/scripts/start-autopause @@ -10,6 +10,7 @@ : "${AUTOPAUSE_TIMEOUT_INIT:=600}" : "${AUTOPAUSE_PERIOD:=10}" : "${AUTOPAUSE_KNOCK_INTERFACE:=eth0}" +: "${DEBUG_AUTOPAUSE:=false}" export SERVER_PORT export ENABLE_AUTOPAUSE export AUTOPAUSE_TIMEOUT_EST @@ -17,6 +18,7 @@ export AUTOPAUSE_TIMEOUT_KN export AUTOPAUSE_TIMEOUT_INIT export AUTOPAUSE_PERIOD export AUTOPAUSE_KNOCK_INTERFACE +export DEBUG_AUTOPAUSE log "Autopause functionality enabled" diff --git a/scripts/start-autostop b/scripts/start-autostop index 1962526d050..38ce1edbf15 100755 --- a/scripts/start-autostop +++ b/scripts/start-autostop @@ -8,11 +8,13 @@ : "${AUTOSTOP_TIMEOUT_EST:=3600}" : "${AUTOSTOP_TIMEOUT_INIT:=1800}" : "${AUTOSTOP_PERIOD:=10}" +: "${DEBUG_AUTOSTOP:=false}" export SERVER_PORT export ENABLE_AUTOSTOP export AUTOSTOP_TIMEOUT_EST export AUTOSTOP_TIMEOUT_INIT export AUTOSTOP_PERIOD +export DEBUG_AUTOSTOP log "Autostop functionality enabled" diff --git a/scripts/start-utils b/scripts/start-utils index f5482c2e07c..a4102f9acba 100755 --- a/scripts/start-utils +++ b/scripts/start-utils @@ -99,7 +99,6 @@ function isDebugging() { function handleDebugMode() { if isDebugging; then set -x - extraCurlArgs=(-v) fi }