Add Docker build system for ZomboidForge with containerized server setup, Gradle build logic, and project configuration.

This commit is contained in:
Overlord committed 2026-09-28 23:12:57 +02:00
1 parent d4c5a9d45f
commit bf9228d2be
18 files changed
+747 -55

No files matched your search

+120
View File
@@ -0,0 +1,120 @@
#!/usr/bin/env bash
#
# Container entrypoint: starts the patched Project Zomboid dedicated server
# with the ZomboidForge agent. Arguments are passed through to
# zombie.network.GameServer.
#
# Environment variables:
# SERVER_NAME Server config name (/data/Server/<name>.ini). Default: zomboidforge
# ADMIN_PASSWORD Admin account password. Required on the first start only.
# RCON_PASSWORD Written into the server .ini before every start. RCON is disabled when empty.
# JVM_MAX_HEAP Value for -Xmx. Default: 8g (the vanilla ProjectZomboid64.json value)
# STEAM 1 = Steam mode (required for official Steam clients), 0 = no Steam. Default: 1
set -o errexit
set -o nounset
set -o pipefail
readonly INSTALL_DIR="/opt/pz"
readonly DATA_DIR="/data"
readonly AGENT_JAR="${INSTALL_DIR}/zomboidforge-agent.jar"
readonly JAVA="${INSTALL_DIR}/jre64/bin/java"
readonly SERVER_NAME="${SERVER_NAME:-zomboidforge}"
readonly ADMIN_PASSWORD="${ADMIN_PASSWORD:-}"
readonly RCON_PASSWORD="${RCON_PASSWORD:-}"
readonly JVM_MAX_HEAP="${JVM_MAX_HEAP:-8g}"
readonly STEAM="${STEAM:-1}"
readonly SERVER_INI="${DATA_DIR}/Server/${SERVER_NAME}.ini"
readonly SERVER_DB="${DATA_DIR}/db/${SERVER_NAME}.db"
log() {
echo "[entrypoint] $*" >&2
}
# Sets <key>=<value> in the server .ini. Creates the file or the key if missing.
# Project Zomboid reads a partial .ini and writes the missing defaults on start.
set_ini_value() {
local key="$1"
local value="$2"
local temp_file="${SERVER_INI}.tmp"
local key_found=false
local line
mkdir --parents "$(dirname "${SERVER_INI}")"
: > "${temp_file}"
if [[ -f "${SERVER_INI}" ]]; then
while IFS= read -r line || [[ -n "${line}" ]]; do
if [[ "${line}" == "${key}="* ]]; then
printf '%s=%s\n' "${key}" "${value}" >> "${temp_file}"
key_found=true
else
printf '%s\n' "${line}" >> "${temp_file}"
fi
done < "${SERVER_INI}"
fi
if [[ "${key_found}" == false ]]; then
printf '%s=%s\n' "${key}" "${value}" >> "${temp_file}"
fi
mv "${temp_file}" "${SERVER_INI}"
}
apply_rcon_password() {
if [[ -z "${RCON_PASSWORD}" ]]; then
log "RCON_PASSWORD is not set; RCON stays disabled unless the .ini sets RCONPassword."
return
fi
set_ini_value "RCONPassword" "${RCON_PASSWORD}"
}
# Without -adminpassword, Project Zomboid blocks on an interactive prompt to
# create the admin account on the first start.
check_admin_password() {
if [[ -z "${ADMIN_PASSWORD}" && ! -f "${SERVER_DB}" ]]; then
log "First start of '${SERVER_NAME}': ADMIN_PASSWORD is required to create the admin account."
exit 1
fi
}
main() {
apply_rcon_password
check_admin_password
# Same JVM setup as the vanilla ProjectZomboid64.json and start-server.sh.
# Java runs directly instead of through the native ProjectZomboid64 launcher.
local jvm_args=(
"-javaagent:${AGENT_JAR}"
"-Djava.awt.headless=true"
"--enable-native-access=ALL-UNNAMED"
"-Xmx${JVM_MAX_HEAP}"
"-XX:+UseZGC"
"-XX:-OmitStackTraceInFastThrow"
"-Dzomboid.steam=${STEAM}"
"-Dzomboid.znetlog=1"
"-Djava.library.path=linux64/"
"-Djava.security.egd=file:/dev/urandom"
"-cp" "java/:java/projectzomboid.jar"
)
local server_args=(
"-cachedir=${DATA_DIR}"
"-servername" "${SERVER_NAME}"
)
if [[ -n "${ADMIN_PASSWORD}" ]]; then
server_args+=("-adminpassword" "${ADMIN_PASSWORD}")
fi
# Native libraries: game (linux64/), Steam (install root), JVM (jre64/lib).
# libjsig.so chains signal handlers between the JVM and native libraries.
export LD_LIBRARY_PATH="${INSTALL_DIR}/linux64:${INSTALL_DIR}:${INSTALL_DIR}/jre64/lib${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}"
export LD_PRELOAD="libjsig.so${LD_PRELOAD:+:${LD_PRELOAD}}"
cd "${INSTALL_DIR}"
exec "${JAVA}" "${jvm_args[@]}" zombie.network.GameServer "${server_args[@]}" "$@"
}
main "$@"