For autopause, added use of mc-monitor to detect players connected (#1059)

This commit is contained in:
Geoff Bourne 2021-09-30 16:51:51 -05:00 committed by GitHub
parent 9d03a1dc13
commit 3482944ac8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 18 deletions

View File

@ -12,7 +12,10 @@ services:
ENABLE_AUTOPAUSE: "TRUE" ENABLE_AUTOPAUSE: "TRUE"
OVERRIDE_SERVER_PROPERTIES: "TRUE" OVERRIDE_SERVER_PROPERTIES: "TRUE"
MAX_TICK_TIME: "-1" MAX_TICK_TIME: "-1"
restart: always # More aggressive settings for demo purposes
AUTOPAUSE_TIMEOUT_INIT: "30"
AUTOPAUSE_TIMEOUT_EST: "10"
restart: unless-stopped
volumes: volumes:
mc: {} mc: {}

View File

@ -17,26 +17,15 @@ rcon_client_exists() {
} }
mc_server_listening() { 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 --timeout 10s >& /dev/null
} }
java_clients_connected() { java_clients_connected() {
local connections local connections
connections=$(netstat -tn | grep ":$SERVER_PORT" | grep ESTABLISHED) if java_running ; then
if [[ -z "$connections" ]] ; then connections=$(mc-monitor status --host localhost --port $SERVER_PORT --show-player-count)
return 1 else
connections=0
fi fi
IFS=$'\n' (( $connections > 0 ))
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
} }