mirror of
https://github.com/itzg/docker-minecraft-server.git
synced 2024-06-07 19:40:43 +00:00
For autopause, added use of mc-monitor to detect players connected (#1059)
This commit is contained in:
parent
9d03a1dc13
commit
3482944ac8
@ -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: {}
|
||||||
|
@ -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
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user