Allow skipping autopause/autostop using a file (#2261)

This commit is contained in:
Darion Spaargaren 2023-06-30 16:50:30 +02:00 committed by GitHub
parent ce65bcc840
commit 4a942dbc02
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 2 deletions

View File

@ -14,6 +14,8 @@ The utility used to wake the server (`knock(d)`) works at network interface leve
A file called `.paused` is created in `/data` directory when the server is paused and removed when the server is resumed. Other services may check for this file's existence before waking the server.
A `.skip-pause` file can be created in the `/data` directory to make the server skip autopausing, for as long as the file is present. The autopause timer will also be reset.
A starting, example compose file has been provided in [examples/docker-compose-autopause.yml](https://github.com/itzg/docker-minecraft-server/blob/master/examples/docker-compose-autopause.yml).
Auto-pause is not compatible with `EXEC_DIRECTLY=true` and the two cannot be set together.

View File

@ -6,6 +6,8 @@ An option to stop the server after a specified time has been added for niche app
the docker container variables have to be set accordingly (restart policy set to "no") and that the container has to be manually restarted.
A `.skip-stop` file can be created in the `/data` directory to make the server skip autostopping, for as long as the file is present. The autostop timer will also be reset.
A starting, example compose file has been provided in [examples/docker-compose-autostop.yml](https://github.com/itzg/docker-minecraft-server/blob/master/examples/docker-compose-autostop.yml).
Enable the Autostop functionality by setting:

View File

@ -62,7 +62,13 @@ do
# Server startup
if mc_server_listening ; then
TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_INIT))
logAutopause "MC Server listening for connections - pausing in $AUTOPAUSE_TIMEOUT_INIT seconds"
if [ -e /data/.skip-pause ] ; then
logAutopause "'/data/.skip-pause' file is present - skipping pausing"
else
logAutopause "MC Server listening for connections - pausing in $AUTOPAUSE_TIMEOUT_INIT seconds"
fi
STATE=K
fi
;;
@ -71,6 +77,9 @@ do
if java_clients_connected ; then
logAutopause "Client connected - waiting for disconnect"
STATE=E
elif [ -e /data/.skip-pause ] ; then
logAutopause "'/data/.skip-pause' file is present - skipping pausing"
STATE=E
else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
logAutopause "No client connected since startup / knocked - pausing"
@ -92,6 +101,10 @@ do
if java_clients_connected ; then
logAutopause "Client reconnected - waiting for disconnect"
STATE=E
elif [ -e /data/.skip-pause ] ; then
TIME_THRESH=$(($(current_uptime)+$AUTOPAUSE_TIMEOUT_EST))
logAutopause "'/data/.skip-pause' file is present - skipping pausing"
STATE=E
else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
logAutopause "No client reconnected - pausing"

View File

@ -28,7 +28,13 @@ do
# Server startup
if mc_server_listening ; then
TIME_THRESH=$(($(current_uptime)+AUTOSTOP_TIMEOUT_INIT))
logAutostop "MC Server listening for connections - stopping in $AUTOSTOP_TIMEOUT_INIT seconds"
if [ -e /data/.skip-stop ] ; then
logAutostop "'/data/.skip-stop' file is present - skipping stopping"
else
logAutostop "MC Server listening for connections - stopping in $AUTOSTOP_TIMEOUT_INIT seconds"
fi
STATE=II
fi
;;
@ -37,6 +43,9 @@ do
if java_clients_connected ; then
logAutostop "Client connected - waiting for disconnect"
STATE=E
elif [ -e /data/.skip-stop ] ; then
logAutostop "'/data/.skip-stop' file is present - skipping stopping"
STATE=E
else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
logAutostop "No client connected since startup - stopping server"
@ -58,6 +67,10 @@ do
if java_clients_connected ; then
logAutostop "Client reconnected - waiting for disconnect"
STATE=E
elif [ -e /data/.skip-stop ] ; then
TIME_THRESH=$(($(current_uptime)+$AUTOSTOP_TIMEOUT_EST))
logAutostop "'/data/.skip-stop' file is present - skipping stopping"
STATE=E
else
if [[ $(current_uptime) -ge $TIME_THRESH ]] ; then
logAutostop "No client reconnected - stopping"