Added debug options for autopause/stop (#1638)

This commit is contained in:
Geoff Bourne authored and GitHub committed 2022-07-30 12:06:22 -05:00
1 parent 8dbfff1873
commit 2df678e96a
9 files changed
+42 -12

No files matched your search

+4
View File
@@ -1699,6 +1699,8 @@ The following environment variables define the behaviour of auto-pausing:
* `AUTOPAUSE_KNOCK_INTERFACE`, default `eth0` * `AUTOPAUSE_KNOCK_INTERFACE`, default `eth0`
<br>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. <br>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 ## 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. 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) * `AUTOSTOP_PERIOD`, default `10` (seconds)
describes period of the daemonized state machine, that handles the stopping of the server 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 ## 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`. 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`.
+18 -9
View File
@@ -2,8 +2,11 @@
. /autopause/autopause-fcns.sh . /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() { autopause_error_loop() {
logAutopause "Available interfaces within the docker container:" logAutopause "Available interfaces within the docker container:"
@@ -39,7 +42,12 @@ if ! [[ -d "/sys/class/net/$AUTOPAUSE_KNOCK_INTERFACE" ]] ; then
autopause_error_loop autopause_error_loop
fi 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 if [ $? -ne 0 ] ; then
logAutopause "Failed to start knockd daemon." logAutopause "Failed to start knockd daemon."
logAutopause "Probable cause: Unable to attach to interface \"$AUTOPAUSE_KNOCK_INTERFACE\"." logAutopause "Probable cause: Unable to attach to interface \"$AUTOPAUSE_KNOCK_INTERFACE\"."
@@ -50,12 +58,13 @@ STATE=INIT
while : while :
do do
isTrue "${DEBUG_AUTOPAUSE}" && log "DEBUG: autopause state = $STATE"
case X$STATE in case X$STATE in
XINIT) XINIT)
# Server startup # Server startup
if mc_server_listening ; then if mc_server_listening ; then
TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_INIT)) 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 STATE=K
fi fi
;; ;;
@@ -66,7 +75,7 @@ do
STATE=E STATE=E
else else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then 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 /autopause/pause.sh
STATE=S STATE=S
fi fi
@@ -76,7 +85,7 @@ do
# Established # Established
if ! java_clients_connected ; then if ! java_clients_connected ; then
TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_EST)) 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 STATE=I
fi fi
;; ;;
@@ -87,7 +96,7 @@ do
STATE=E STATE=E
else else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
logAutopause "No client reconnected - stopping" logAutopause "No client reconnected - pausing"
/autopause/pause.sh /autopause/pause.sh
STATE=S STATE=S
fi fi
@@ -115,8 +124,8 @@ do
esac esac
if [[ "$STATE" == "S" ]] ; then if [[ "$STATE" == "S" ]] ; then
# before rcon times out # before rcon times out
sleep 2 sleep 5
else else
sleep $AUTOPAUSE_PERIOD sleep "$AUTOPAUSE_PERIOD"
fi fi
done done
+3
View File
@@ -1,6 +1,9 @@
#!/bin/bash #!/bin/bash
. /start-utils . /start-utils
if isTrue "${DEBUG_AUTOPAUSE}"; then
set -x
fi
if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; then if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^S.*$ ]] ; then
# save world # save world
+3
View File
@@ -1,6 +1,9 @@
#!/bin/bash #!/bin/bash
. /start-utils . /start-utils
if isTrue "${DEBUG_AUTOPAUSE}"; then
set -x
fi
if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then if [[ $( ps -ax -o stat,comm | grep 'java' | awk '{ print $1 }') =~ ^T.*$ ]] ; then
logAutopauseAction "Knocked, resuming Java process" logAutopauseAction "Knocked, resuming Java process"
+7 -2
View File
@@ -3,7 +3,11 @@
# needed for the clients connected function residing in autopause # needed for the clients connected function residing in autopause
. /autopause/autopause-fcns.sh . /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 # wait for java process to be started
while : while :
@@ -18,11 +22,12 @@ STATE=INIT
while : while :
do do
isTrue "${DEBUG_AUTOSTOP}" && log "DEBUG: autostop state = $STATE"
case X$STATE in case X$STATE in
XINIT) XINIT)
# Server startup # Server startup
if mc_server_listening ; then 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" logAutostop "MC Server listening for connections - stopping in $AUTOSTOP_TIMEOUT_INIT seconds"
STATE=II STATE=II
fi fi
+3
View File
@@ -1,6 +1,9 @@
#!/bin/bash #!/bin/bash
. /start-utils . /start-utils
if isTrue "${DEBUG_AUTOSTOP}"; then
set -x
fi
logAutostopAction "Stopping Java process" logAutostopAction "Stopping Java process"
kill -SIGTERM 1 kill -SIGTERM 1
+2
View File
@@ -10,6 +10,7 @@
: "${AUTOPAUSE_TIMEOUT_INIT:=600}" : "${AUTOPAUSE_TIMEOUT_INIT:=600}"
: "${AUTOPAUSE_PERIOD:=10}" : "${AUTOPAUSE_PERIOD:=10}"
: "${AUTOPAUSE_KNOCK_INTERFACE:=eth0}" : "${AUTOPAUSE_KNOCK_INTERFACE:=eth0}"
: "${DEBUG_AUTOPAUSE:=false}"
export SERVER_PORT export SERVER_PORT
export ENABLE_AUTOPAUSE export ENABLE_AUTOPAUSE
export AUTOPAUSE_TIMEOUT_EST export AUTOPAUSE_TIMEOUT_EST
@@ -17,6 +18,7 @@ export AUTOPAUSE_TIMEOUT_KN
export AUTOPAUSE_TIMEOUT_INIT export AUTOPAUSE_TIMEOUT_INIT
export AUTOPAUSE_PERIOD export AUTOPAUSE_PERIOD
export AUTOPAUSE_KNOCK_INTERFACE export AUTOPAUSE_KNOCK_INTERFACE
export DEBUG_AUTOPAUSE
log "Autopause functionality enabled" log "Autopause functionality enabled"
+2
View File
@@ -8,11 +8,13 @@
: "${AUTOSTOP_TIMEOUT_EST:=3600}" : "${AUTOSTOP_TIMEOUT_EST:=3600}"
: "${AUTOSTOP_TIMEOUT_INIT:=1800}" : "${AUTOSTOP_TIMEOUT_INIT:=1800}"
: "${AUTOSTOP_PERIOD:=10}" : "${AUTOSTOP_PERIOD:=10}"
: "${DEBUG_AUTOSTOP:=false}"
export SERVER_PORT export SERVER_PORT
export ENABLE_AUTOSTOP export ENABLE_AUTOSTOP
export AUTOSTOP_TIMEOUT_EST export AUTOSTOP_TIMEOUT_EST
export AUTOSTOP_TIMEOUT_INIT export AUTOSTOP_TIMEOUT_INIT
export AUTOSTOP_PERIOD export AUTOSTOP_PERIOD
export DEBUG_AUTOSTOP
log "Autostop functionality enabled" log "Autostop functionality enabled"
-1
View File
@@ -99,7 +99,6 @@ function isDebugging() {
function handleDebugMode() { function handleDebugMode() {
if isDebugging; then if isDebugging; then
set -x set -x
extraCurlArgs=(-v)
fi fi
} }