feat: Allowed for server properties to be cleared vs skipped

#1117
This commit is contained in:
Geoff Bourne 2021-11-12 21:17:21 -06:00
parent e04e943e1c
commit 2375a6796c
4 changed files with 87 additions and 82 deletions

View file

@ -75,7 +75,6 @@ ENV UID=1000 GID=1000 \
MEMORY="1G" \
TYPE=VANILLA VERSION=LATEST \
ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \
SERVER_PORT=25565 ONLINE_MODE=TRUE SERVER_NAME="Dedicated Server" \
ENABLE_AUTOPAUSE=false AUTOPAUSE_TIMEOUT_EST=3600 AUTOPAUSE_TIMEOUT_KN=120 AUTOPAUSE_TIMEOUT_INIT=600 \
AUTOPAUSE_PERIOD=10 AUTOPAUSE_KNOCK_INTERFACE=eth0

View file

@ -808,6 +808,8 @@ This will reset any manual configuration of the `server.properties` file, so if
In the opposite case, you can skip the startup script's creation of `server.properties`, by setting `SKIP_SERVER_PROPERTIES` to "true".
> NOTE: to clear a server property, set the variable to an empty string, such as `-e RESOURCE_PACK=""`. A variables that maps to a server property that is unset, is ignored and the existing `server.property` is left unchanged.
### Message of the Day
The message of the day, shown below each server entry in the client UI, can be changed with the `MOTD` environment variable, such as

View file

@ -1,40 +1,46 @@
#!/bin/bash
. ${SCRIPTS:-/}start-utils
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
: ${SERVER_PROPERTIES:=/data/server.properties}
: "${SERVER_PROPERTIES:=/data/server.properties}"
# FUNCTIONS
function setServerPropValue {
local prop=$1
local value=$2
# normalize booleans
case ${value^^} in
TRUE|FALSE)
value=${value,,} ;;
esac
if grep "${prop}" "$SERVER_PROPERTIES" > /dev/null; then
log "Setting ${prop} to '${value}' in ${SERVER_PROPERTIES}"
sed -i "/^${prop}\s*=/ c ${prop}=${value//\\/\\\\}" "$SERVER_PROPERTIES"
else
log "Adding ${prop} with '${value}' in ${SERVER_PROPERTIES}"
echo "${prop}=${value}" >> "$SERVER_PROPERTIES"
fi
}
function setServerProp {
local prop=$1
local var=$2
if [ -n "$var" ]; then
# normalize booleans
case ${var^^} in
TRUE|FALSE)
var=${var,,} ;;
esac
if grep "${prop}" "$SERVER_PROPERTIES" > /dev/null; then
log "Setting ${prop} to '${var}' in ${SERVER_PROPERTIES}"
sed -i "/^${prop}\s*=/ c ${prop}=${var//\\/\\\\}" "$SERVER_PROPERTIES"
else
log "Adding ${prop} with '${var}' in ${SERVER_PROPERTIES}"
echo "${prop}=${var}" >> "$SERVER_PROPERTIES"
fi
else
isDebugging && log "Skip setting ${prop}"
local varName=$2
if [ -v $varName ]; then
setServerPropValue "$prop" "${!varName}"
fi
}
function customizeServerProps {
if [ -n "$WHITELIST" ] || isTrue ${ENABLE_WHITELIST:-false}; then
if [ -n "$WHITELIST" ] || isTrue "${ENABLE_WHITELIST:-false}"; then
log "Creating whitelist"
setServerProp "whitelist" "true"
setServerProp "white-list" "true"
setServerPropValue "whitelist" "true"
setServerPropValue "white-list" "true"
else
log "Disabling whitelist"
setServerProp "whitelist" "false"
setServerProp "white-list" "false"
setServerPropValue "whitelist" "false"
setServerPropValue "white-list" "false"
fi
# If not provided, generate a reasonable default message-of-the-day,
@ -53,54 +59,54 @@ function customizeServerProps {
MOTD="A ${label} Minecraft Server powered by Docker"
fi
setServerProp "server-name" "$SERVER_NAME"
setServerProp "server-ip" "$SERVER_IP"
setServerProp "server-port" "$SERVER_PORT"
setServerProp "motd" "$(echo $MOTD | mc-image-helper asciify)"
setServerProp "allow-nether" "$ALLOW_NETHER"
setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS"
setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK"
setServerProp "spawn-animals" "$SPAWN_ANIMALS"
setServerProp "spawn-monsters" "$SPAWN_MONSTERS"
setServerProp "spawn-npcs" "$SPAWN_NPCS"
setServerProp "spawn-protection" "$SPAWN_PROTECTION"
setServerProp "generate-structures" "$GENERATE_STRUCTURES"
setServerProp "view-distance" "$VIEW_DISTANCE"
setServerProp "hardcore" "$HARDCORE"
setServerProp "snooper-enabled" "$SNOOPER_ENABLED"
setServerProp "max-build-height" "$MAX_BUILD_HEIGHT"
setServerProp "force-gamemode" "$FORCE_GAMEMODE"
setServerProp "max-tick-time" "$MAX_TICK_TIME"
setServerProp "enable-query" "$ENABLE_QUERY"
setServerProp "query.port" "$QUERY_PORT"
setServerProp "enable-rcon" "$ENABLE_RCON"
setServerProp "rcon.password" "$RCON_PASSWORD"
setServerProp "rcon.port" "$RCON_PORT"
setServerProp "max-players" "$MAX_PLAYERS"
setServerProp "max-world-size" "$MAX_WORLD_SIZE"
setServerProp "level-name" "$LEVEL"
setServerProp "level-seed" "$SEED"
setServerProp "pvp" "${PVP}"
setServerProp "generator-settings" "$GENERATOR_SETTINGS"
setServerProp "online-mode" "$ONLINE_MODE"
setServerProp "allow-flight" "$ALLOW_FLIGHT"
setServerProp "level-type" "${LEVEL_TYPE^^}"
setServerProp "resource-pack" "$RESOURCE_PACK"
setServerProp "resource-pack-sha1" "$RESOURCE_PACK_SHA1"
setServerProp "player-idle-timeout" "$PLAYER_IDLE_TIMEOUT"
setServerProp "broadcast-console-to-ops" "$BROADCAST_CONSOLE_TO_OPS"
setServerProp "broadcast-rcon-to-ops" "$BROADCAST_RCON_TO_OPS"
setServerProp "enable-jmx-monitoring" "$ENABLE_JMX"
setServerProp "sync-chunk-writes" "$SYNC_CHUNK_WRITES"
setServerProp "enable-status" "$ENABLE_STATUS"
setServerProp "entity-broadcast-range-percentage" "$ENTITY_BROADCAST_RANGE_PERCENTAGE"
setServerProp "function-permission-level" "$FUNCTION_PERMISSION_LEVEL"
setServerProp "network-compression-threshold" "$NETWORK_COMPRESSION_THRESHOLD"
setServerProp "op-permission-level" "$OP_PERMISSION_LEVEL"
setServerProp "prevent-proxy-connections" "$PREVENT_PROXY_CONNECTIONS"
setServerProp "use-native-transport" "$USE_NATIVE_TRANSPORT"
setServerProp "enforce-whitelist" "$ENFORCE_WHITELIST"
setServerProp "simulation-distance" "$SIMULATION_DISTANCE"
setServerProp "server-name" SERVER_NAME
setServerProp "server-ip" SERVER_IP
setServerProp "server-port" SERVER_PORT
setServerProp "allow-nether" ALLOW_NETHER
setServerProp "announce-player-achievements" ANNOUNCE_PLAYER_ACHIEVEMENTS
setServerProp "enable-command-block" ENABLE_COMMAND_BLOCK
setServerProp "spawn-animals" SPAWN_ANIMALS
setServerProp "spawn-monsters" SPAWN_MONSTERS
setServerProp "spawn-npcs" SPAWN_NPCS
setServerProp "spawn-protection" SPAWN_PROTECTION
setServerProp "generate-structures" GENERATE_STRUCTURES
setServerProp "view-distance" VIEW_DISTANCE
setServerProp "hardcore" HARDCORE
setServerProp "snooper-enabled" SNOOPER_ENABLED
setServerProp "max-build-height" MAX_BUILD_HEIGHT
setServerProp "force-gamemode" FORCE_GAMEMODE
setServerProp "max-tick-time" MAX_TICK_TIME
setServerProp "enable-query" ENABLE_QUERY
setServerProp "query.port" QUERY_PORT
setServerProp "enable-rcon" ENABLE_RCON
setServerProp "rcon.password" RCON_PASSWORD
setServerProp "rcon.port" RCON_PORT
setServerProp "max-players" MAX_PLAYERS
setServerProp "max-world-size" MAX_WORLD_SIZE
setServerProp "level-name" LEVEL
setServerProp "level-seed" SEED
setServerProp "pvp" PVP
setServerProp "generator-settings" GENERATOR_SETTINGS
setServerProp "online-mode" ONLINE_MODE
setServerProp "allow-flight" ALLOW_FLIGHT
setServerProp "resource-pack" RESOURCE_PACK
setServerProp "resource-pack-sha1" RESOURCE_PACK_SHA1
setServerProp "player-idle-timeout" PLAYER_IDLE_TIMEOUT
setServerProp "broadcast-console-to-ops" BROADCAST_CONSOLE_TO_OPS
setServerProp "broadcast-rcon-to-ops" BROADCAST_RCON_TO_OPS
setServerProp "enable-jmx-monitoring" ENABLE_JMX
setServerProp "sync-chunk-writes" SYNC_CHUNK_WRITES
setServerProp "enable-status" ENABLE_STATUS
setServerProp "entity-broadcast-range-percentage" ENTITY_BROADCAST_RANGE_PERCENTAGE
setServerProp "function-permission-level" FUNCTION_PERMISSION_LEVEL
setServerProp "network-compression-threshold" NETWORK_COMPRESSION_THRESHOLD
setServerProp "op-permission-level" OP_PERMISSION_LEVEL
setServerProp "prevent-proxy-connections" PREVENT_PROXY_CONNECTIONS
setServerProp "use-native-transport" USE_NATIVE_TRANSPORT
setServerProp "enforce-whitelist" ENFORCE_WHITELIST
setServerProp "simulation-distance" SIMULATION_DISTANCE
[[ $MOTD ]] && setServerPropValue "motd" "$(echo $MOTD | mc-image-helper asciify)"
[[ $LEVEL_TYPE ]] && setServerPropValue "level-type" "${LEVEL_TYPE^^}"
if [ -n "$DIFFICULTY" ]; then
case $DIFFICULTY in
@ -137,7 +143,7 @@ function customizeServerProps {
exit 1
;;
esac
setServerProp "difficulty" "$DIFFICULTY"
setServerPropValue "difficulty" "$DIFFICULTY"
fi
if [ -n "$MODE" ]; then
@ -177,7 +183,7 @@ function customizeServerProps {
exit 1
;;
esac
setServerProp "gamemode" "$MODE"
setServerPropValue "gamemode" "$MODE"
fi
}
@ -210,7 +216,7 @@ fi
if isTrue "${ENABLE_AUTOPAUSE}"; then
current_max_tick=$( grep 'max-tick-time' "$SERVER_PROPERTIES" | sed -r 's/( )+//g' | awk -F= '{print $2}' )
if (( $current_max_tick > 0 && $current_max_tick < 86400000 )); then
if (( current_max_tick > 0 && current_max_tick < 86400000 )); then
log "Warning: The server.properties for the server doesn't have the Server Watchdog (effectively) disabled."
log "Warning (cont): Autopause functionality resuming the process might trigger the Watchdog and restart the server completely."
log "Warning (cont): Set the max-tick-time property to a high value (or disable the Watchdog with value -1 for versions 1.8.1+)."

View file

@ -1,16 +1,14 @@
#!/bin/bash
. ${SCRIPTS:-/}start-utils
# shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
set -e
isDebugging && set -x
: ${LEVEL:=world}
export LEVEL
if [ $TYPE = "CURSEFORGE" ]; then
worldDest=$FTB_DIR/$LEVEL
worldDest=$FTB_DIR/${LEVEL:-world}
else
worldDest=/data/$LEVEL
worldDest=/data/${LEVEL:-world}
fi
if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); then
@ -71,4 +69,4 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] );
fi
fi
exec ${SCRIPTS:-/}start-setupModpack $@
exec "${SCRIPTS:-/}start-setupModpack" "$@"