Updated server configuration; add UPnP and JVM memory options, and enhance startup behaviour with dynamic memory allocation and ZUncommitDelay settings.
This commit is contained in:
1 parent
151e1d459f
commit
05eed7e205
4 files changed
+132
-62
No files matched your search
+56
-4
@@ -14,6 +14,10 @@
|
||||
# PORT Game port (-port). Default: 16261
|
||||
# UDP_PORT Direct connection port (-udpport). Default: 16262
|
||||
# STEAM 1 = Steam mode (required for official Steam clients), 0 = no Steam. Default: 1
|
||||
# UPNP true/false: UPnP port mapping on the router (.ini UPnP). false is
|
||||
# recommended: in a container the server sees only its container address,
|
||||
# publishing the ports is the container runtime's job, and the router
|
||||
# discovery delays every start by about 12 s.
|
||||
#
|
||||
# Admin account
|
||||
# ADMIN_USERNAME Admin account name (-adminusername), passed on every start.
|
||||
@@ -33,8 +37,14 @@
|
||||
# RCON_PASSWORD Written into the .ini before every start. RCON is disabled when empty.
|
||||
#
|
||||
# JVM
|
||||
# JVM_MIN_HEAP Value for -Xms. Default: JVM default
|
||||
# JVM_MAX_HEAP Value for -Xmx. Default: 8g (the vanilla ProjectZomboid64.json value)
|
||||
# JVM_MIN_HEAP Value for -Xms. Default: JVM default. ZGC returns unused heap memory
|
||||
# only down to this size.
|
||||
# JVM_MAX_HEAP Value for -Xmx. Default: 75 % of the container memory limit
|
||||
# (cgroup v2 memory.max); 8g, the vanilla ProjectZomboid64.json value,
|
||||
# when the container has no limit
|
||||
# JVM_UNCOMMIT_DELAY
|
||||
# Seconds of disuse after which ZGC returns heap memory to the system
|
||||
# (-XX:ZUncommitDelay). Default: 60 (JVM default: 300)
|
||||
#
|
||||
# Maintenance
|
||||
# SOFT_RESET true: start in Project Zomboid's soft reset mode (-Dsoftreset).
|
||||
@@ -58,6 +68,7 @@ readonly PUBLIC_NAME="${PUBLIC_NAME:-}"
|
||||
readonly PORT="${PORT:-}"
|
||||
readonly UDP_PORT="${UDP_PORT:-}"
|
||||
readonly STEAM="${STEAM:-1}"
|
||||
readonly UPNP="${UPNP:-}"
|
||||
readonly ADMIN_USERNAME="${ADMIN_USERNAME:-}"
|
||||
readonly ADMIN_PASSWORD="${ADMIN_PASSWORD:-}"
|
||||
readonly SERVER_PRESET="${SERVER_PRESET:-}"
|
||||
@@ -65,7 +76,8 @@ readonly MODS="${MODS:-}"
|
||||
readonly WORKSHOP_ITEMS="${WORKSHOP_ITEMS:-}"
|
||||
readonly RCON_PASSWORD="${RCON_PASSWORD:-}"
|
||||
readonly JVM_MIN_HEAP="${JVM_MIN_HEAP:-}"
|
||||
readonly JVM_MAX_HEAP="${JVM_MAX_HEAP:-8g}"
|
||||
readonly JVM_MAX_HEAP="${JVM_MAX_HEAP:-}"
|
||||
readonly JVM_UNCOMMIT_DELAY="${JVM_UNCOMMIT_DELAY:-60}"
|
||||
readonly SOFT_RESET="${SOFT_RESET:-}"
|
||||
|
||||
readonly SERVER_INI="${DATA_DIR}/Server/${SERVER_NAME}.ini"
|
||||
@@ -73,6 +85,8 @@ readonly SERVER_SANDBOX_VARS="${DATA_DIR}/Server/${SERVER_NAME}_SandboxVars.lua"
|
||||
readonly SERVER_DB="${DATA_DIR}/db/${SERVER_NAME}.db"
|
||||
# Target of the /opt/pz/steamapps symlink; Steam stores Workshop downloads there.
|
||||
readonly STEAMAPPS_DIR="${DATA_DIR}/steamapps"
|
||||
readonly CGROUP_MEMORY_MAX="/sys/fs/cgroup/memory.max"
|
||||
readonly UNLIMITED_MAX_HEAP="8g"
|
||||
|
||||
log() {
|
||||
echo "[entrypoint] $*" >&2
|
||||
@@ -166,6 +180,16 @@ apply_ini_settings() {
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${UPNP}" ]]; then
|
||||
if is_true "${UPNP}"; then
|
||||
set_ini_value "UPnP" "true"
|
||||
elif is_false "${UPNP}"; then
|
||||
set_ini_value "UPnP" "false"
|
||||
else
|
||||
fail "UPNP must be true or false, got '${UPNP}'."
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ -n "${RCON_PASSWORD}" ]]; then
|
||||
set_ini_value "RCONPassword" "${RCON_PASSWORD}"
|
||||
else
|
||||
@@ -231,16 +255,44 @@ check_admin_account() {
|
||||
fi
|
||||
}
|
||||
|
||||
# 75 % of the cgroup v2 memory limit in MiB; UNLIMITED_MAX_HEAP without a limit.
|
||||
# The rest of the limit is left for native memory (JVM, native libraries, thread stacks).
|
||||
default_max_heap() {
|
||||
local limit
|
||||
|
||||
if [[ ! -r "${CGROUP_MEMORY_MAX}" ]]; then
|
||||
echo "${UNLIMITED_MAX_HEAP}"
|
||||
return
|
||||
fi
|
||||
limit="$(< "${CGROUP_MEMORY_MAX}")"
|
||||
if [[ "${limit}" == "max" ]]; then
|
||||
echo "${UNLIMITED_MAX_HEAP}"
|
||||
return
|
||||
fi
|
||||
echo "$(( limit * 3 / 4 / 1024 / 1024 ))m"
|
||||
}
|
||||
|
||||
# Same JVM setup as the vanilla ProjectZomboid64.json and start-server.sh.
|
||||
# Java runs directly instead of through the native ProjectZomboid64 launcher.
|
||||
build_jvm_args() {
|
||||
local max_heap="${JVM_MAX_HEAP}"
|
||||
|
||||
if [[ -z "${max_heap}" ]]; then
|
||||
max_heap="$(default_max_heap)"
|
||||
log "JVM_MAX_HEAP is not set: using -Xmx${max_heap}."
|
||||
fi
|
||||
if [[ ! "${JVM_UNCOMMIT_DELAY}" =~ ^[0-9]+$ ]]; then
|
||||
fail "JVM_UNCOMMIT_DELAY must be a number of seconds, got '${JVM_UNCOMMIT_DELAY}'."
|
||||
fi
|
||||
|
||||
jvm_args=(
|
||||
"-javaagent:${AGENT_JAR}"
|
||||
"-Dzomboidforge.dir=${FORGE_DIR}"
|
||||
"-Djava.awt.headless=true"
|
||||
"--enable-native-access=ALL-UNNAMED"
|
||||
"-Xmx${JVM_MAX_HEAP}"
|
||||
"-Xmx${max_heap}"
|
||||
"-XX:+UseZGC"
|
||||
"-XX:ZUncommitDelay=${JVM_UNCOMMIT_DELAY}"
|
||||
"-XX:-OmitStackTraceInFastThrow"
|
||||
"-Dzomboid.steam=${STEAM}"
|
||||
"-Dzomboid.znetlog=1"
|
||||
|
||||
Reference in new issue
Block a user