From 46487b65fbc3b4da6ffc4a396550ff37eeef866f Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sat, 25 Sep 2021 13:53:45 -0500 Subject: [PATCH 1/4] For autopause, added use of mc-monitor to detect players connected --- Dockerfile | 2 +- examples/docker-compose-autopause.yml | 7 ++++++- files/autopause/autopause-fcns.sh | 21 +++------------------ 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/Dockerfile b/Dockerfile index 46f7d49dcff..4dac529d814 100644 --- a/Dockerfile +++ b/Dockerfile @@ -49,7 +49,7 @@ RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ - --var version=0.7.1 --var app=mc-monitor --file {{.app}} \ + --var version=0.10.0 --var app=mc-monitor --file {{.app}} \ --from https://github.com/itzg/{{.app}}/releases/download/{{.version}}/{{.app}}_{{.version}}_{{.os}}_{{.arch}}.tar.gz RUN easy-add --var os=${TARGETOS} --var arch=${TARGETARCH}${TARGETVARIANT} \ diff --git a/examples/docker-compose-autopause.yml b/examples/docker-compose-autopause.yml index f7d1bf9249d..1cf3a13e89f 100644 --- a/examples/docker-compose-autopause.yml +++ b/examples/docker-compose-autopause.yml @@ -9,10 +9,15 @@ services: - "mc:/data" environment: EULA: "TRUE" + # PAPER starts up faster + TYPE: PAPER ENABLE_AUTOPAUSE: "TRUE" OVERRIDE_SERVER_PROPERTIES: "TRUE" MAX_TICK_TIME: "-1" - restart: always + # More aggressive settings for demo purposes + AUTOPAUSE_TIMEOUT_INIT: "30" + AUTOPAUSE_TIMEOUT_EST: "10" + restart: unless-stopped volumes: mc: {} diff --git a/files/autopause/autopause-fcns.sh b/files/autopause/autopause-fcns.sh index 69eb9d08470..ef01e3e808d 100755 --- a/files/autopause/autopause-fcns.sh +++ b/files/autopause/autopause-fcns.sh @@ -17,26 +17,11 @@ rcon_client_exists() { } mc_server_listening() { - [[ -n $(netstat -tln | grep -e "0.0.0.0:$SERVER_PORT" -e ":::$SERVER_PORT" | grep LISTEN) ]] + mc-monitor status --host localhost --port $SERVER_PORT >& /dev/null } java_clients_connected() { local connections - connections=$(netstat -tn | grep ":$SERVER_PORT" | grep ESTABLISHED) - if [[ -z "$connections" ]] ; then - return 1 - fi - IFS=$'\n' - connections=($connections) - unset IFS - # check that at least one external address is not localhost - # remember, that the host network mode does not work with autopause because of the knockd utility - for (( i=0; i<${#connections[@]}; i++ )) - do - if [[ ! $(echo "${connections[$i]}" | awk '{print $5}') =~ ^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$ ]] ; then - # not localhost - return 0 - fi - done - return 1 + connections=$(mc-monitor status --host localhost --port $SERVER_PORT --show-player-count) + (( $connections > 0 )) } From eed1de943db40720554f2508070b2f01578e21cd Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 26 Sep 2021 11:18:46 -0500 Subject: [PATCH 2/4] Used vanilla for autopause example --- examples/docker-compose-autopause.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/docker-compose-autopause.yml b/examples/docker-compose-autopause.yml index 1cf3a13e89f..9fab0dad52e 100644 --- a/examples/docker-compose-autopause.yml +++ b/examples/docker-compose-autopause.yml @@ -9,8 +9,6 @@ services: - "mc:/data" environment: EULA: "TRUE" - # PAPER starts up faster - TYPE: PAPER ENABLE_AUTOPAUSE: "TRUE" OVERRIDE_SERVER_PROPERTIES: "TRUE" MAX_TICK_TIME: "-1" From d87db54260486e3383eb47a47ec9c1378e927481 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Sun, 26 Sep 2021 11:22:41 -0500 Subject: [PATCH 3/4] Check for process running before getting player count Co-authored-by: Michael Kirsch --- files/autopause/autopause-fcns.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/files/autopause/autopause-fcns.sh b/files/autopause/autopause-fcns.sh index ef01e3e808d..d2166bf605e 100755 --- a/files/autopause/autopause-fcns.sh +++ b/files/autopause/autopause-fcns.sh @@ -22,6 +22,10 @@ mc_server_listening() { java_clients_connected() { local connections - connections=$(mc-monitor status --host localhost --port $SERVER_PORT --show-player-count) + if java_running ; then + connections=$(mc-monitor status --host localhost --port $SERVER_PORT --show-player-count) + else + connections=0 + fi (( $connections > 0 )) } From 6facf66b95583fe491482e316764fb9f996fe956 Mon Sep 17 00:00:00 2001 From: Geoff Bourne Date: Wed, 29 Sep 2021 21:38:08 -0500 Subject: [PATCH 4/4] Used shorter timeout for mc_server_listening --- files/autopause/autopause-fcns.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/autopause/autopause-fcns.sh b/files/autopause/autopause-fcns.sh index d2166bf605e..3b2e56bfa58 100755 --- a/files/autopause/autopause-fcns.sh +++ b/files/autopause/autopause-fcns.sh @@ -17,7 +17,7 @@ rcon_client_exists() { } mc_server_listening() { - mc-monitor status --host localhost --port $SERVER_PORT >& /dev/null + mc-monitor status --host localhost --port $SERVER_PORT --timeout 10s >& /dev/null } java_clients_connected() {