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" \ MEMORY="1G" \
TYPE=VANILLA VERSION=LATEST \ TYPE=VANILLA VERSION=LATEST \
ENABLE_RCON=true RCON_PORT=25575 RCON_PASSWORD=minecraft \ 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 \ ENABLE_AUTOPAUSE=false AUTOPAUSE_TIMEOUT_EST=3600 AUTOPAUSE_TIMEOUT_KN=120 AUTOPAUSE_TIMEOUT_INIT=600 \
AUTOPAUSE_PERIOD=10 AUTOPAUSE_KNOCK_INTERFACE=eth0 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". 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 ### 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 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 #!/bin/bash
. ${SCRIPTS:-/}start-utils # shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
: ${SERVER_PROPERTIES:=/data/server.properties} : "${SERVER_PROPERTIES:=/data/server.properties}"
# FUNCTIONS # 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 { function setServerProp {
local prop=$1 local prop=$1
local var=$2 local varName=$2
if [ -n "$var" ]; then
# normalize booleans if [ -v $varName ]; then
case ${var^^} in setServerPropValue "$prop" "${!varName}"
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}"
fi fi
} }
function customizeServerProps { function customizeServerProps {
if [ -n "$WHITELIST" ] || isTrue ${ENABLE_WHITELIST:-false}; then if [ -n "$WHITELIST" ] || isTrue "${ENABLE_WHITELIST:-false}"; then
log "Creating whitelist" log "Creating whitelist"
setServerProp "whitelist" "true" setServerPropValue "whitelist" "true"
setServerProp "white-list" "true" setServerPropValue "white-list" "true"
else else
log "Disabling whitelist" log "Disabling whitelist"
setServerProp "whitelist" "false" setServerPropValue "whitelist" "false"
setServerProp "white-list" "false" setServerPropValue "white-list" "false"
fi fi
# If not provided, generate a reasonable default message-of-the-day, # 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" MOTD="A ${label} Minecraft Server powered by Docker"
fi fi
setServerProp "server-name" "$SERVER_NAME" setServerProp "server-name" SERVER_NAME
setServerProp "server-ip" "$SERVER_IP" setServerProp "server-ip" SERVER_IP
setServerProp "server-port" "$SERVER_PORT" setServerProp "server-port" SERVER_PORT
setServerProp "motd" "$(echo $MOTD | mc-image-helper asciify)" setServerProp "allow-nether" ALLOW_NETHER
setServerProp "allow-nether" "$ALLOW_NETHER" setServerProp "announce-player-achievements" ANNOUNCE_PLAYER_ACHIEVEMENTS
setServerProp "announce-player-achievements" "$ANNOUNCE_PLAYER_ACHIEVEMENTS" setServerProp "enable-command-block" ENABLE_COMMAND_BLOCK
setServerProp "enable-command-block" "$ENABLE_COMMAND_BLOCK" setServerProp "spawn-animals" SPAWN_ANIMALS
setServerProp "spawn-animals" "$SPAWN_ANIMALS" setServerProp "spawn-monsters" SPAWN_MONSTERS
setServerProp "spawn-monsters" "$SPAWN_MONSTERS" setServerProp "spawn-npcs" SPAWN_NPCS
setServerProp "spawn-npcs" "$SPAWN_NPCS" setServerProp "spawn-protection" SPAWN_PROTECTION
setServerProp "spawn-protection" "$SPAWN_PROTECTION" setServerProp "generate-structures" GENERATE_STRUCTURES
setServerProp "generate-structures" "$GENERATE_STRUCTURES" setServerProp "view-distance" VIEW_DISTANCE
setServerProp "view-distance" "$VIEW_DISTANCE" setServerProp "hardcore" HARDCORE
setServerProp "hardcore" "$HARDCORE" setServerProp "snooper-enabled" SNOOPER_ENABLED
setServerProp "snooper-enabled" "$SNOOPER_ENABLED" setServerProp "max-build-height" MAX_BUILD_HEIGHT
setServerProp "max-build-height" "$MAX_BUILD_HEIGHT" setServerProp "force-gamemode" FORCE_GAMEMODE
setServerProp "force-gamemode" "$FORCE_GAMEMODE" setServerProp "max-tick-time" MAX_TICK_TIME
setServerProp "max-tick-time" "$MAX_TICK_TIME" setServerProp "enable-query" ENABLE_QUERY
setServerProp "enable-query" "$ENABLE_QUERY" setServerProp "query.port" QUERY_PORT
setServerProp "query.port" "$QUERY_PORT" setServerProp "enable-rcon" ENABLE_RCON
setServerProp "enable-rcon" "$ENABLE_RCON" setServerProp "rcon.password" RCON_PASSWORD
setServerProp "rcon.password" "$RCON_PASSWORD" setServerProp "rcon.port" RCON_PORT
setServerProp "rcon.port" "$RCON_PORT" setServerProp "max-players" MAX_PLAYERS
setServerProp "max-players" "$MAX_PLAYERS" setServerProp "max-world-size" MAX_WORLD_SIZE
setServerProp "max-world-size" "$MAX_WORLD_SIZE" setServerProp "level-name" LEVEL
setServerProp "level-name" "$LEVEL" setServerProp "level-seed" SEED
setServerProp "level-seed" "$SEED" setServerProp "pvp" PVP
setServerProp "pvp" "${PVP}" setServerProp "generator-settings" GENERATOR_SETTINGS
setServerProp "generator-settings" "$GENERATOR_SETTINGS" setServerProp "online-mode" ONLINE_MODE
setServerProp "online-mode" "$ONLINE_MODE" setServerProp "allow-flight" ALLOW_FLIGHT
setServerProp "allow-flight" "$ALLOW_FLIGHT" setServerProp "resource-pack" RESOURCE_PACK
setServerProp "level-type" "${LEVEL_TYPE^^}" setServerProp "resource-pack-sha1" RESOURCE_PACK_SHA1
setServerProp "resource-pack" "$RESOURCE_PACK" setServerProp "player-idle-timeout" PLAYER_IDLE_TIMEOUT
setServerProp "resource-pack-sha1" "$RESOURCE_PACK_SHA1" setServerProp "broadcast-console-to-ops" BROADCAST_CONSOLE_TO_OPS
setServerProp "player-idle-timeout" "$PLAYER_IDLE_TIMEOUT" setServerProp "broadcast-rcon-to-ops" BROADCAST_RCON_TO_OPS
setServerProp "broadcast-console-to-ops" "$BROADCAST_CONSOLE_TO_OPS" setServerProp "enable-jmx-monitoring" ENABLE_JMX
setServerProp "broadcast-rcon-to-ops" "$BROADCAST_RCON_TO_OPS" setServerProp "sync-chunk-writes" SYNC_CHUNK_WRITES
setServerProp "enable-jmx-monitoring" "$ENABLE_JMX" setServerProp "enable-status" ENABLE_STATUS
setServerProp "sync-chunk-writes" "$SYNC_CHUNK_WRITES" setServerProp "entity-broadcast-range-percentage" ENTITY_BROADCAST_RANGE_PERCENTAGE
setServerProp "enable-status" "$ENABLE_STATUS" setServerProp "function-permission-level" FUNCTION_PERMISSION_LEVEL
setServerProp "entity-broadcast-range-percentage" "$ENTITY_BROADCAST_RANGE_PERCENTAGE" setServerProp "network-compression-threshold" NETWORK_COMPRESSION_THRESHOLD
setServerProp "function-permission-level" "$FUNCTION_PERMISSION_LEVEL" setServerProp "op-permission-level" OP_PERMISSION_LEVEL
setServerProp "network-compression-threshold" "$NETWORK_COMPRESSION_THRESHOLD" setServerProp "prevent-proxy-connections" PREVENT_PROXY_CONNECTIONS
setServerProp "op-permission-level" "$OP_PERMISSION_LEVEL" setServerProp "use-native-transport" USE_NATIVE_TRANSPORT
setServerProp "prevent-proxy-connections" "$PREVENT_PROXY_CONNECTIONS" setServerProp "enforce-whitelist" ENFORCE_WHITELIST
setServerProp "use-native-transport" "$USE_NATIVE_TRANSPORT" setServerProp "simulation-distance" SIMULATION_DISTANCE
setServerProp "enforce-whitelist" "$ENFORCE_WHITELIST" [[ $MOTD ]] && setServerPropValue "motd" "$(echo $MOTD | mc-image-helper asciify)"
setServerProp "simulation-distance" "$SIMULATION_DISTANCE" [[ $LEVEL_TYPE ]] && setServerPropValue "level-type" "${LEVEL_TYPE^^}"
if [ -n "$DIFFICULTY" ]; then if [ -n "$DIFFICULTY" ]; then
case $DIFFICULTY in case $DIFFICULTY in
@ -137,7 +143,7 @@ function customizeServerProps {
exit 1 exit 1
;; ;;
esac esac
setServerProp "difficulty" "$DIFFICULTY" setServerPropValue "difficulty" "$DIFFICULTY"
fi fi
if [ -n "$MODE" ]; then if [ -n "$MODE" ]; then
@ -177,7 +183,7 @@ function customizeServerProps {
exit 1 exit 1
;; ;;
esac esac
setServerProp "gamemode" "$MODE" setServerPropValue "gamemode" "$MODE"
fi fi
} }
@ -210,7 +216,7 @@ fi
if isTrue "${ENABLE_AUTOPAUSE}"; then if isTrue "${ENABLE_AUTOPAUSE}"; then
current_max_tick=$( grep 'max-tick-time' "$SERVER_PROPERTIES" | sed -r 's/( )+//g' | awk -F= '{print $2}' ) 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: 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): 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+)." 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 #!/bin/bash
. ${SCRIPTS:-/}start-utils # shellcheck source=start-utils
. "${SCRIPTS:-/}start-utils"
set -e set -e
isDebugging && set -x isDebugging && set -x
: ${LEVEL:=world}
export LEVEL
if [ $TYPE = "CURSEFORGE" ]; then if [ $TYPE = "CURSEFORGE" ]; then
worldDest=$FTB_DIR/$LEVEL worldDest=$FTB_DIR/${LEVEL:-world}
else else
worldDest=/data/$LEVEL worldDest=/data/${LEVEL:-world}
fi fi
if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); then if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] ); then
@ -71,4 +69,4 @@ if [[ "$WORLD" ]] && ( isTrue "${FORCE_WORLD_COPY}" || [ ! -d "$worldDest" ] );
fi fi
fi fi
exec ${SCRIPTS:-/}start-setupModpack $@ exec "${SCRIPTS:-/}start-setupModpack" "$@"