Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion examples/docker-compose-autopause.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ services:
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: {}
23 changes: 6 additions & 17 deletions files/autopause/autopause-fcns.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,15 @@ 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 --timeout 10s >& /dev/null
}

java_clients_connected() {
local connections
connections=$(netstat -tn | grep ":$SERVER_PORT" | grep ESTABLISHED)
if [[ -z "$connections" ]] ; then
return 1
if java_running ; then
connections=$(mc-monitor status --host localhost --port $SERVER_PORT --show-player-count)
else
connections=0
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 > 0 ))
}