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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,8 @@ The following environment variables define the behaviour of auto-pausing:
* `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.

> 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.
Expand All @@ -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`.
Expand Down
27 changes: 18 additions & 9 deletions files/autopause/autopause-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down Expand Up @@ -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\"."
Expand All @@ -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
;;
Expand All @@ -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
Expand All @@ -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
;;
Expand All @@ -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
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions files/autopause/pause.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions files/autopause/resume.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
9 changes: 7 additions & 2 deletions files/autostop/autostop-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions files/autostop/stop.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/bin/bash

. /start-utils
if isTrue "${DEBUG_AUTOSTOP}"; then
set -x
fi

logAutostopAction "Stopping Java process"
kill -SIGTERM 1
2 changes: 2 additions & 0 deletions scripts/start-autopause
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
: "${AUTOPAUSE_TIMEOUT_INIT:=600}"
: "${AUTOPAUSE_PERIOD:=10}"
: "${AUTOPAUSE_KNOCK_INTERFACE:=eth0}"
: "${DEBUG_AUTOPAUSE:=false}"
export SERVER_PORT
export ENABLE_AUTOPAUSE
export AUTOPAUSE_TIMEOUT_EST
export AUTOPAUSE_TIMEOUT_KN
export AUTOPAUSE_TIMEOUT_INIT
export AUTOPAUSE_PERIOD
export AUTOPAUSE_KNOCK_INTERFACE
export DEBUG_AUTOPAUSE

log "Autopause functionality enabled"

Expand Down
2 changes: 2 additions & 0 deletions scripts/start-autostop
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
1 change: 0 additions & 1 deletion scripts/start-utils
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ function isDebugging() {
function handleDebugMode() {
if isDebugging; then
set -x
extraCurlArgs=(-v)
fi
}

Expand Down