diff --git a/Dockerfile b/Dockerfile index 95ecb6f6..64ff4f9a 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.1 --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/README.md b/README.md index 621e38fc..9b3df62a 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ By default, the container will download the latest version of the "vanilla" [Min * [Enabling Autopause](#enabling-autopause) * [Running on RaspberryPi](#running-on-raspberrypi) - + @@ -1057,6 +1057,7 @@ If you must, the server port can be set like: | USE_NATIVE_TRANSPORT | use-native-transport | | ENFORCE_WHITELIST | enforce-whitelist | | ENABLE_WHITELIST | white-list and whitelist | +| SIMULATION_DISTANCE | simulation-distance | ## Miscellaneous Options 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 )) } diff --git a/start-deployForge b/start-deployForge index e78e2c4f..93d0bbb8 100755 --- a/start-deployForge +++ b/start-deployForge @@ -4,83 +4,37 @@ : ${FORGEVERSION:=RECOMMENDED} isDebugging && set -x -if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then - norm=$VANILLA_VERSION +get_installer() { + if [[ -z $FORGE_INSTALLER_URL ]]; then + log "Downloading $normForgeVersion" - case $VANILLA_VERSION in - *.*.*) - norm=$VANILLA_VERSION ;; - *.*) - norm=${VANILLA_VERSION}.0 ;; - esac + forgeFileNames=" + $normForgeVersion/forge-$normForgeVersion-installer.jar + $shortForgeVersion/forge-$shortForgeVersion-installer.jar + " - ################################################################################# - - log "Checking Forge version information." - case $FORGEVERSION in - RECOMMENDED) - curl -fsSL -o /tmp/forge.json http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json - FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-recommended\"]") - if [ $FORGE_VERSION = null ]; then - FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-latest\"]") - if [ $FORGE_VERSION = null ]; then - log "ERROR: Version $VANILLA_VERSION is not supported by Forge" - log " Refer to http://files.minecraftforge.net/ for supported versions" - exit 2 - fi - fi - ;; - - *) - FORGE_VERSION=$FORGEVERSION - ;; - esac - - normForgeVersion=$VANILLA_VERSION-$FORGE_VERSION-$norm - shortForgeVersion=$VANILLA_VERSION-$FORGE_VERSION - - FORGE_INSTALLER="/tmp/forge-$shortForgeVersion-installer.jar" -elif [[ -z $FORGE_INSTALLER ]]; then - FORGE_INSTALLER="/tmp/forge-installer.jar" -elif [[ ! -e $FORGE_INSTALLER ]]; then - log "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER" - exit 2 -else - shortForgeVersion=$VANILLA_VERSION-${FORGE_INSTALLER_CUSTOM_VERSION:-custom} -fi - -installMarker="/data/.forge-installed-$shortForgeVersion" - -if [ ! -e $installMarker ]; then - if [ ! -e $FORGE_INSTALLER ]; then - - if [[ -z $FORGE_INSTALLER_URL ]]; then - log "Downloading $normForgeVersion" - - forgeFileNames=" - $normForgeVersion/forge-$normForgeVersion-installer.jar - $shortForgeVersion/forge-$shortForgeVersion-installer.jar - END - " - for fn in $forgeFileNames; do - if [ $fn == END ]; then - log "Unable to compute URL for $normForgeVersion" - exit 2 - fi - downloadUrl=https://maven.minecraftforge.net/net/minecraftforge/forge/$fn - log "...trying $downloadUrl" - if curl -o $FORGE_INSTALLER -fsSL $downloadUrl; then - break - fi - done - else - log "Downloading $FORGE_INSTALLER_URL ..." - if ! curl -o $FORGE_INSTALLER -fsSL $FORGE_INSTALLER_URL; then - log "Failed to download from given location $FORGE_INSTALLER_URL" - exit 2 + for fn in $forgeFileNames; do + downloadUrl=https://maven.minecraftforge.net/net/minecraftforge/forge/$fn + log "...trying $downloadUrl" + if curl -o $FORGE_INSTALLER -fsSL $downloadUrl; then + return fi + done + log "Unable to locate usable URL for $normForgeVersion" + exit 2 + else + log "Downloading $FORGE_INSTALLER_URL ..." + if ! curl -o $FORGE_INSTALLER -fsSL $FORGE_INSTALLER_URL; then + log "Failed to download from given location $FORGE_INSTALLER_URL" + exit 2 fi fi +} + +install() { + if [ ! -e $FORGE_INSTALLER ]; then + get_installer $normForgeVersion $shortForgeVersion + fi log "Installing Forge $shortForgeVersion using $FORGE_INSTALLER" mkdir -p mods @@ -113,9 +67,69 @@ if [ ! -e $installMarker ]; then export SERVER=$latest log "Using server $SERVER" echo $SERVER > $installMarker +} +resolve_versions() { + if [[ -z $FORGE_INSTALLER && -z $FORGE_INSTALLER_URL ]]; then + norm=$VANILLA_VERSION + + case $VANILLA_VERSION in + *.*.*) + norm=$VANILLA_VERSION ;; + *.*) + norm=${VANILLA_VERSION}.0 ;; + esac + + ################################################################################# + + log "Checking Forge version information." + case $FORGEVERSION in + RECOMMENDED) + curl -fsSL -o /tmp/forge.json http://files.minecraftforge.net/maven/net/minecraftforge/forge/promotions_slim.json + FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-recommended\"]") + if [ $FORGE_VERSION = null ]; then + FORGE_VERSION=$(cat /tmp/forge.json | jq -r ".promos[\"$VANILLA_VERSION-latest\"]") + if [ $FORGE_VERSION = null ]; then + log "ERROR: Version $VANILLA_VERSION is not supported by Forge" + log " Refer to http://files.minecraftforge.net/ for supported versions" + exit 2 + fi + fi + ;; + + *) + FORGE_VERSION=$FORGEVERSION + ;; + esac + + normForgeVersion=$VANILLA_VERSION-$FORGE_VERSION-$norm + shortForgeVersion=$VANILLA_VERSION-$FORGE_VERSION + + FORGE_INSTALLER="/tmp/forge-$shortForgeVersion-installer.jar" + elif [[ -z $FORGE_INSTALLER ]]; then + FORGE_INSTALLER="/tmp/forge-installer.jar" + elif [[ ! -e $FORGE_INSTALLER ]]; then + log "ERROR: the given Forge installer doesn't exist : $FORGE_INSTALLER" + exit 2 + else + shortForgeVersion=$VANILLA_VERSION-${FORGE_INSTALLER_CUSTOM_VERSION:-custom} + fi +} + +### main + +resolve_versions + +installMarker="/data/.forge-installed-$shortForgeVersion" + +if [ ! -e $installMarker ]; then + install else export SERVER=$(cat $installMarker) + if [ ! -e "$SERVER" ] && versionLessThan 1.17; then + rm "$installMarker" + install + fi fi exec ${SCRIPTS:-/}start-setupWorld $@ diff --git a/start-setupServerProperties b/start-setupServerProperties index b1e4361b..50677d84 100755 --- a/start-setupServerProperties +++ b/start-setupServerProperties @@ -100,6 +100,7 @@ function customizeServerProps { setServerProp "prevent-proxy-connections" "$PREVENT_PROXY_CONNECTIONS" setServerProp "use-native-transport" "$USE_NATIVE_TRANSPORT" setServerProp "enforce-whitelist" "$ENFORCE_WHITELIST" + setServerProp "simulation-distance" "$SIMULATION_DISTANCE" if [ -n "$DIFFICULTY" ]; then case $DIFFICULTY in