Skip to content

Commit

Permalink
Allow skipping autopause/autostop using a file (#2261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 authored Jun 30, 2023
1 parent ce65bcc commit 4a942db
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/misc/autopause-autostop/autopause.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/misc/autopause-autostop/autostop.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 14 additions & 1 deletion files/auto/autopause-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -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"
Expand All @@ -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"
Expand Down
15 changes: 14 additions & 1 deletion files/auto/autostop-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 4a942db

Please sign in to comment.