diff --git a/examples/docker-compose-autopause.yml b/examples/docker-compose-autopause.yml index f7d1bf92..9fab0dad 100644 --- a/examples/docker-compose-autopause.yml +++ b/examples/docker-compose-autopause.yml @@ -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: {} diff --git a/files/autopause/autopause-fcns.sh b/files/autopause/autopause-fcns.sh index 69eb9d08..3b2e56bf 100755 --- a/files/autopause/autopause-fcns.sh +++ b/files/autopause/autopause-fcns.sh @@ -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 )) }