horizon-server: install scripts, a Docker image, and boot services

- packaging/server/install.sh (Linux, macOS) and install.ps1 (Windows) install the latest release (or
  --version) from GitHub, check the SHA-256 GitHub publishes for it, and keep releases side by side:
  <dir>/current points at the one in use, so an update or a rollback is one link, and the game files
  prepared from the owner's Minecraft stay in <dir>/game-files across updates.
- packaging/server/Dockerfile builds the server and the engine; the prepared game files are mounted
  read-only, and the first start writes server.toml from HORIZON_EULA, HORIZON_WORLD, HORIZON_SEED,
  HORIZON_PORT, HORIZON_WHITELIST, HORIZON_PLAYERS and HORIZON_OP (`init` reads them too).
- `horizon-server service install|uninstall|print` writes and loads a systemd unit (user, or --system),
  a launchd agent, or a Windows task at logon. It runs the installer's launcher, so updates apply on
  the next restart.
- Releases build horizon-server and ship it beside horizon-ctl and horizon-prepare; PLAY.txt says how
  to run a server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-16 20:19:57 +02:00
parent 3510764cc6
commit ed6af00ff8
9 changed files with 657 additions and 12 deletions
+40
View File
@@ -0,0 +1,40 @@
# horizon-server in a container (docs/server.md, section 3). Build context: the repository root:
# docker build -f packaging/server/Dockerfile -t horizon-server .
#
# The image holds none of Minecraft's files. Prepare them on the host from your own Minecraft 26.3
# (horizon-prepare --prepare, see packaging/PLAY.txt) and mount the folder it writes, read-only:
# docker run -d --name horizon -p 25565:25565 --stop-timeout 180 \
# -v horizon-data:/data \
# -v /path/to/.local/horizon-client/26.3:/opt/horizon/.local/horizon-client/26.3:ro \
# -e HORIZON_EULA=true -e HORIZON_WHITELIST=true -e HORIZON_PLAYERS=Alex,Steve -e HORIZON_OP=Alex \
# horizon-server
#
# HORIZON_EULA=true accepts the Minecraft EULA (https://aka.ms/MinecraftEULA) for this server. The first
# start writes /data/server.toml from HORIZON_* (EULA, WORLD, SEED, PORT, WHITELIST, PLAYERS, OP); later
# starts use the file. Manage it with `docker exec horizon horizon-server status|cmd|backup|logs ...`.
FROM rust:1-slim-bookworm AS build
RUN apt-get update \
&& apt-get install -y --no-install-recommends pkg-config libasound2-dev libudev-dev \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /src
COPY . .
RUN cargo build --release --locked -p horizon-client --bin horizon-client -p horizon-server --bin horizon-server \
&& mkdir /out && cp target/release/horizon-client target/release/horizon-server /out/
FROM debian:bookworm-slim
# The game links ALSA and udev even when it runs headless with no sound.
RUN apt-get update \
&& apt-get install -y --no-install-recommends libasound2 libudev1 \
&& rm -rf /var/lib/apt/lists/* \
&& useradd --system --home-dir /data --shell /usr/sbin/nologin horizon \
&& mkdir -p /data /opt/horizon/.local/horizon-client \
&& chown horizon:horizon /data
COPY --from=build /out/ /opt/horizon/
ENV PATH=/opt/horizon:$PATH \
HORIZON_NO_AUDIO=1
WORKDIR /data
VOLUME /data
EXPOSE 25565
USER horizon
# SIGTERM makes horizon-server stop the game cleanly (it saves first): give it --stop-timeout 180.
CMD ["sh", "-c", "test -f server.toml || horizon-server init --yes || exit 1; exec horizon-server run"]
+79
View File
@@ -0,0 +1,79 @@
# Installs horizon-server (docs/server.md) on Windows: the latest Horizon release, downloaded from GitHub
# Releases and checked against the SHA-256 GitHub publishes for it.
#
# irm https://raw.githubusercontent.com/ludovic111/horizon/main/packaging/server/install.ps1 | iex
# & ([scriptblock]::Create((irm .../install.ps1))) -Version v0.5.0 -Dir D:\Horizon
#
# Releases go to <Dir>\releases\<version>, <Dir>\current points at the one in use, and <Dir>\bin (added to
# your PATH) holds horizon-server.cmd and horizon-prepare.cmd. The game files you prepare from your own
# Minecraft stay in <Dir>\game-files across updates. Nothing of Mojang's is downloaded. No admin rights.
param(
[string]$Version = "latest",
[string]$Dir = (Join-Path $env:LOCALAPPDATA "Horizon")
)
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
$Repo = "ludovic111/horizon"
$Asset = "horizon-windows-x64.zip"
if ($env:PROCESSOR_ARCHITECTURE -ne "AMD64") {
throw "No Horizon release for Windows on $env:PROCESSOR_ARCHITECTURE yet: build it from source (docs/server.md)"
}
$Api = if ($Version -eq "latest") { "https://api.github.com/repos/$Repo/releases/latest" }
else { "https://api.github.com/repos/$Repo/releases/tags/$Version" }
$Release = Invoke-RestMethod -Uri $Api -Headers @{ Accept = "application/vnd.github+json" }
$Tag = $Release.tag_name
$Item = $Release.assets | Where-Object { $_.name -eq $Asset } | Select-Object -First 1
if (-not $Item) { throw "Release $Tag has no $Asset" }
if (-not $Item.digest -or -not $Item.digest.StartsWith("sha256:")) { throw "Release $Tag publishes no SHA-256 for $Asset" }
$Digest = $Item.digest.Substring(7)
$Tmp = Join-Path ([IO.Path]::GetTempPath()) ("horizon-install-" + [Guid]::NewGuid())
New-Item -ItemType Directory -Path $Tmp | Out-Null
try {
Write-Host "Downloading Horizon $Tag ($Asset)..."
$Zip = Join-Path $Tmp $Asset
Invoke-WebRequest -Uri $Item.browser_download_url -OutFile $Zip
$Got = (Get-FileHash -Algorithm SHA256 $Zip).Hash.ToLowerInvariant()
if ($Got -ne $Digest.ToLowerInvariant()) {
throw "$Asset doesn't match its SHA-256 (got $Got, expected $Digest): not installed"
}
$Unpacked = Join-Path $Tmp "x"
Expand-Archive -Path $Zip -DestinationPath $Unpacked
$Server = Get-ChildItem -Path $Unpacked -Recurse -Filter "horizon-server.exe" | Select-Object -First 1
if (-not $Server) { throw "$Asset holds no horizon-server.exe (a release from before it existed?)" }
$Releases = Join-Path $Dir "releases"
$GameFiles = Join-Path $Dir "game-files\horizon-client"
$Bin = Join-Path $Dir "bin"
New-Item -ItemType Directory -Force -Path $Releases, $GameFiles, $Bin | Out-Null
$Target = Join-Path $Releases $Tag
if (Test-Path $Target) { Remove-Item -Recurse -Force $Target }
Move-Item -Path $Server.Directory.FullName -Destination $Target
# Prepared game files live outside the release, so updates and rollbacks keep them. Junctions need no
# admin rights, unlike symbolic links.
$Local = Join-Path $Target ".local"
New-Item -ItemType Directory -Force -Path $Local | Out-Null
New-Item -ItemType Junction -Path (Join-Path $Local "horizon-client") -Target $GameFiles | Out-Null
$Current = Join-Path $Dir "current"
if (Test-Path $Current) { (Get-Item $Current).Delete() }
New-Item -ItemType Junction -Path $Current -Target $Target | Out-Null
foreach ($Tool in "horizon-server", "horizon-prepare") {
Set-Content -Path (Join-Path $Bin "$Tool.cmd") -Encoding ASCII -Value "@`"$Current\$Tool.exe`" %*"
}
$UserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not (($UserPath -split ";") -contains $Bin)) {
[Environment]::SetEnvironmentVariable("Path", ($UserPath.TrimEnd(";") + ";" + $Bin).TrimStart(";"), "User")
Write-Host "Added $Bin to your PATH: open a new terminal to use it."
}
Write-Host "Installed Horizon $Tag in $Target."
if (-not (Get-ChildItem -Path $GameFiles -ErrorAction SilentlyContinue)) {
Write-Host "Next, prepare the game files from your own Minecraft 26.3 (it needs Java 25 and the game installed"
Write-Host "once by the official launcher; see docs/server.md):"
Write-Host " horizon-prepare --prepare --server-jar C:\path\to\server.jar"
}
Write-Host "Then set up a server: mkdir my-server; cd my-server; horizon-server init"
} finally {
Remove-Item -Recurse -Force $Tmp -ErrorAction SilentlyContinue
}
+98
View File
@@ -0,0 +1,98 @@
#!/bin/sh
# Installs horizon-server (docs/server.md) on Linux or macOS: the latest Horizon release for this computer,
# downloaded from GitHub Releases and checked against the SHA-256 GitHub publishes for it.
#
# curl -fsSL https://raw.githubusercontent.com/ludovic111/horizon/main/packaging/server/install.sh | sh
# curl -fsSL .../install.sh | sh -s -- --version v0.5.0 --dir /opt/horizon --bin /usr/local/bin
#
# It needs curl, tar or unzip, and sha256sum or shasum; it never asks for sudo (pick folders you can write).
# Releases go to <dir>/releases/<version>, <dir>/current points at the one in use, and <bin>/horizon-server
# runs it. The game files you prepare from your own Minecraft stay in <dir>/game-files across updates.
# Nothing of Mojang's is downloaded.
set -eu
REPO=ludovic111/horizon
VERSION=latest
DIR="${XDG_DATA_HOME:-$HOME/.local/share}/horizon"
BIN="$HOME/.local/bin"
die() { echo "horizon install: $*" >&2; exit 1; }
while [ $# -gt 0 ]; do
case "$1" in
--version) [ $# -ge 2 ] || die "--version needs a tag"; VERSION=$2; shift 2 ;;
--dir) [ $# -ge 2 ] || die "--dir needs a folder"; DIR=$2; shift 2 ;;
--bin) [ $# -ge 2 ] || die "--bin needs a folder"; BIN=$2; shift 2 ;;
-h|--help) sed -n '2,12p' "$0" 2>/dev/null || true; exit 0 ;;
*) die "unknown option $1" ;;
esac
done
case "$(uname -s)-$(uname -m)" in
Linux-x86_64) ASSET=horizon-linux-x86_64.tar.gz ;;
Darwin-arm64) ASSET=horizon-macos-arm64.zip ;;
*) die "no Horizon release for $(uname -s) $(uname -m) yet: build it from source (docs/server.md)" ;;
esac
command -v curl >/dev/null || die "curl is needed"
if command -v sha256sum >/dev/null; then SHA="sha256sum"
elif command -v shasum >/dev/null; then SHA="shasum -a 256"
else die "sha256sum or shasum is needed"; fi
if [ "$VERSION" = latest ]; then API="https://api.github.com/repos/$REPO/releases/latest"
else API="https://api.github.com/repos/$REPO/releases/tags/$VERSION"; fi
JSON=$(curl -fsSL -H "Accept: application/vnd.github+json" "$API") || die "no release $VERSION on GitHub"
TAG=$(printf '%s\n' "$JSON" | sed -n 's/^ "tag_name": "\([^"]*\)".*/\1/p' | head -n 1)
[ -n "$TAG" ] || die "could not read the release's tag"
# The asset's download address and digest, from its block in the release's JSON.
FIELDS=$(printf '%s\n' "$JSON" | awk -v asset="$ASSET" '
/"name": / { line = $0; sub(/.*"name": "/, "", line); sub(/".*/, "", line); current = line }
current == asset && /"digest": / { line = $0; sub(/.*"digest": "sha256:/, "", line); sub(/".*/, "", line); digest = line }
current == asset && /"browser_download_url": / { line = $0; sub(/.*"browser_download_url": "/, "", line); sub(/".*/, "", line); url = line }
END { print url; print digest }')
URL=$(printf '%s\n' "$FIELDS" | sed -n 1p)
DIGEST=$(printf '%s\n' "$FIELDS" | sed -n 2p)
[ -n "$URL" ] || die "release $TAG has no $ASSET"
[ -n "$DIGEST" ] || die "release $TAG publishes no SHA-256 for $ASSET"
TMP=$(mktemp -d)
trap 'rm -rf "$TMP"' EXIT
echo "Downloading Horizon $TAG ($ASSET)..."
curl -fL --progress-bar -o "$TMP/$ASSET" "$URL"
GOT=$($SHA "$TMP/$ASSET" | cut -d' ' -f1)
[ "$GOT" = "$DIGEST" ] || die "$ASSET doesn't match its SHA-256 (got $GOT, expected $DIGEST): not installed"
mkdir -p "$TMP/x"
case "$ASSET" in
*.tar.gz) tar -xzf "$TMP/$ASSET" -C "$TMP/x" ;;
*.zip) command -v unzip >/dev/null || die "unzip is needed"; unzip -q "$TMP/$ASSET" -d "$TMP/x" ;;
esac
SOURCE=$(dirname "$(find "$TMP/x" -name horizon-server -type f | head -n 1)")
[ -x "$SOURCE/horizon-server" ] || die "$ASSET holds no horizon-server (a release from before it existed?)"
RELEASE="$DIR/releases/$TAG"
mkdir -p "$DIR/releases" "$DIR/game-files/horizon-client" "$BIN"
rm -rf "$RELEASE"
mv "$SOURCE" "$RELEASE"
# Prepared game files live outside the release, so updates and rollbacks keep them.
mkdir -p "$RELEASE/.local"
ln -sfn "$DIR/game-files/horizon-client" "$RELEASE/.local/horizon-client"
ln -sfn "$RELEASE" "$DIR/current"
# Small launchers rather than links: the programs find their release folder from where they run.
for tool in horizon-server horizon-prepare; do
printf '#!/bin/sh\nexec "%s/current/%s" "$@"\n' "$DIR" "$tool" > "$BIN/$tool"
chmod +x "$BIN/$tool"
done
echo "Installed Horizon $TAG in $RELEASE; horizon-server and horizon-prepare are in $BIN."
case ":$PATH:" in
*":$BIN:"*) ;;
*) echo "Add $BIN to your PATH, for example: echo 'export PATH=\"$BIN:\$PATH\"' >> ~/.profile" ;;
esac
if [ -z "$(ls -A "$DIR/game-files/horizon-client" 2>/dev/null)" ]; then
echo "Next, prepare the game files from your own Minecraft 26.3 (it needs Java 25 and the game installed once"
echo "by the official launcher; see docs/server.md):"
echo " horizon-prepare --prepare --server-jar /path/to/server.jar"
fi
echo "Then set up a server: mkdir my-server && cd my-server && horizon-server init"