Auf Docker umgestellt

Ein Image (pfaedle + pmtiles + Python), zwei Container per compose:
web (Port 8080) und updater (stündlich Fahrplan, beim ersten Start
Kartenkacheln). install.sh installiert Docker und startet alles.
systemd-Dienste entfernt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X48pE4bzjHej8w9HyZXCjb
This commit is contained in:
Claude
2026-10-21 19:24:44 +02:00
parent 88fd24c22b
commit 30d3127b21
12 changed files with 132 additions and 123 deletions
+23 -68
View File
@@ -1,87 +1,42 @@
#!/usr/bin/env bash
# TrainPulse – Installation in einem Debian-LXC (Proxmox). Im Container als root:
# TrainPulse – Installation mit Docker (z. B. in einem Debian-LXC auf Proxmox). Als root:
# bash deploy/install.sh
# Erneut ausführen = Update des Programmcodes (Daten, Karte und Einstellungen bleiben).
# Erneut ausführen = Update (Image neu bauen, Daten und Einstellungen bleiben).
set -euo pipefail
APP=/opt/trainpulse
DATA=/var/lib/trainpulse
SRC=$(cd "$(dirname "$0")/.." && pwd)
BBOX=5.8,45.7,10.6,47.9 # Schweiz mit etwas Rand
cd "$(dirname "$0")/.."
[ "$(id -u)" = 0 ] || { echo "Bitte als root ausführen" >&2; exit 1; }
command -v apt-get >/dev/null || { echo "Nur für Debian/Ubuntu (apt) gedacht" >&2; exit 1; }
command -v systemctl >/dev/null || { echo "systemd fehlt – im Proxmox-LXC mit Debian-Template ist es dabei" >&2; exit 1; }
mem=$(awk '/MemTotal/ {print int($2/1024)}' /proc/meminfo)
[ "$mem" -ge 3500 ] || echo "WARNUNG: nur ${mem} MB RAM – für die Fahrplan-Aufbereitung werden ~4 GB empfohlen" >&2
echo "==> Pakete (Python, Compiler und Bibliotheken für pfaedle, Werkzeuge)"
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y -qq python3 python3-venv python3-pip git cmake g++ make \
libzip-dev zlib1g-dev libbz2-dev curl ca-certificates tar >/dev/null
echo "==> Programm nach $APP"
id trainpulse &>/dev/null || useradd --system --home-dir "$DATA" --shell /usr/sbin/nologin trainpulse
mkdir -p "$APP" "$DATA/tiles"
rm -rf "$APP/trainpulse" "$APP/web"
cp -r "$SRC/trainpulse" "$SRC/web" "$SRC/requirements.txt" "$APP/"
[ -d "$APP/.venv" ] || python3 -m venv "$APP/.venv"
"$APP/.venv/bin/pip" install -q --upgrade -r "$APP/requirements.txt"
if ! command -v pfaedle >/dev/null; then
echo "==> pfaedle bauen (Streckenverläufe aus OpenStreetMap, dauert ein paar Minuten)"
tmp=$(mktemp -d)
git clone -q --depth 1 --recurse-submodules --shallow-submodules https://github.com/ad-freiburg/pfaedle "$tmp/src"
cmake -S "$tmp/src" -B "$tmp/build" -DCMAKE_BUILD_TYPE=Release >/dev/null
make -C "$tmp/build" -j"$(nproc)" >/dev/null
make -C "$tmp/build" install >/dev/null
rm -rf "$tmp"
if ! command -v docker >/dev/null || ! docker compose version >/dev/null 2>&1; then
echo "==> Docker installieren (offizielles Skript von get.docker.com)"
apt-get update -qq
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq curl ca-certificates >/dev/null
curl -fsSL https://get.docker.com | sh
fi
if ! command -v pmtiles >/dev/null; then
echo "==> pmtiles-Werkzeug"
url=$(curl -fsSL https://api.github.com/repos/protomaps/go-pmtiles/releases/latest | python3 -c \
'import json,sys; print(next(a["browser_download_url"] for a in json.load(sys.stdin)["assets"] if a["name"].endswith("Linux_x86_64.tar.gz")))')
curl -fsSL "$url" | tar xz -C /usr/local/bin pmtiles
fi
if [ ! -s "$DATA/tiles/region.pmtiles" ]; then
echo "==> Kartenkacheln (OpenStreetMap via Protomaps) für $BBOX"
for i in 1 2 3 4 5 6 7; do
d=$(date -d "-$i day" +%Y%m%d)
if pmtiles extract "https://build.protomaps.com/$d.pmtiles" "$DATA/tiles/region.tmp.pmtiles" --bbox=$BBOX --maxzoom=15; then
mv "$DATA/tiles/region.tmp.pmtiles" "$DATA/tiles/region.pmtiles"
break
fi
done
[ -s "$DATA/tiles/region.pmtiles" ] || { echo "Kartenkacheln konnten nicht geladen werden" >&2; exit 1; }
fi
if [ ! -f /etc/trainpulse.env ]; then
cat > /etc/trainpulse.env <<EOF
TRAINPULSE_DATA=$DATA
# API-Key von https://api-manager.opentransportdata.swiss (Produkt "GTFS-RT")
TRAINPULSE_RT_KEY=
if ! docker run --rm hello-world >/dev/null 2>&1; then
cat >&2 <<'EOF'
Docker ist installiert, kann aber keine Container starten.
In einem Proxmox-LXC: Container herunterfahren, unter Optionen → Features
"Nesting" und "keyctl" aktivieren, Container starten, Skript nochmals ausführen.
EOF
chmod 640 /etc/trainpulse.env
chgrp trainpulse /etc/trainpulse.env
exit 1
fi
chown -R trainpulse:trainpulse "$DATA"
echo "==> Dienste"
cp "$SRC"/deploy/trainpulse.service "$SRC"/deploy/trainpulse-update.service "$SRC"/deploy/trainpulse-update.timer /etc/systemd/system/
systemctl daemon-reload
systemctl enable --now trainpulse-update.timer
systemctl enable trainpulse.service
systemctl restart trainpulse.service
systemctl start --no-block trainpulse-update.service
[ -f .env ] || cp .env.example .env
mkdir -p data
echo "==> Image bauen und starten (das erste Mal dauert der Bau von pfaedle ein paar Minuten)"
docker compose up -d --build
ip=$(hostname -I | awk '{print $1}')
cat <<EOF
Fertig. Die Karte läuft unter http://$ip:8080
Der erste Fahrplan wird jetzt im Hintergrund geladen und aufbereitet (ca. 10–15 min).
Fortschritt: journalctl -fu trainpulse-update
Echtzeit: API-Key in /etc/trainpulse.env eintragen, dann systemctl restart trainpulse
Der Updater lädt jetzt Kartenkacheln (~1,2 GB) und den Fahrplan und berechnet die
Streckenverläufe. Bis die ersten Züge erscheinen, dauert es ca. 15 Minuten.
Fortschritt: docker compose logs -f updater
Echtzeit: API-Key in $(pwd)/.env eintragen, dann docker compose up -d
EOF