Upstream/deploy/upstream.service
jvanvik 249818a7aa Stage 3-5 server (military, expansion, social), web client for stages 1-2, ops/deploy
Built: units/research/training, movements (scan, raid, attack, takeover, reinforce, settle, transport), deterministic
combat resolved in the event queue, reports, power/offline units, founding + conquest + incumbent sites; alliances,
roles, diplomacy (24h pact cancel via events), messages, rankings; vanilla-JS phone-first client (auth, POP, map,
alerts, settings, en/nb); systemd units, backup timer, DEPLOY.md, tools/admin.js.
Tested: npm test 96/96 (fake clock, in-memory db, a few real-HTTP tests); client checked with headless Chromium
screenshots only. NOT done: marketplace/transport trade, client screens for military/social, WebSocket push,
bots/balance, e2e suite. All unit stats and costs are unbalanced first guesses.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q2MJaQ5LXAHzGnTDgceT14
2026-10-11 18:32:36 +02:00

94 lines
4.6 KiB
Desktop File

# Upstream systemd unit (Debian 13 LXC; see docs/DEPLOY.md).
#
# install -m 0644 deploy/upstream.service /etc/systemd/system/upstream.service
# systemctl daemon-reload && systemctl enable --now upstream
# journalctl -u upstream -f
#
# Expects the app in /opt/upstream (server/, public/, node_modules/) and a Node >= 22.13 on the PATH (the Debian 13
# package is Node 20 and is too old for node:sqlite: see docs/DEPLOY.md section 1). The database lives in
# /var/lib/upstream (systemd creates it, owned by the service user, from StateDirectory=).
[Unit]
Description=Upstream - persistent network-operator strategy game (Node server, SQLite)
Documentation=file:///opt/upstream/docs/DEPLOY.md
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=upstream
Group=upstream
WorkingDirectory=/opt/upstream
# /usr/bin/env finds node on systemd's default PATH: /usr/local/bin (official tarball) before /usr/bin (NodeSource).
ExecStart=/usr/bin/env node /opt/upstream/server/index.js
# ---- state --------------------------------------------------------------------------------------------------
# Creates /var/lib/upstream owned by the service user (mode 0700) before start. This is the ONLY place the game
# writes. Do not put the database in /opt/upstream.
StateDirectory=upstream
StateDirectoryMode=0700
# Optional file for settings and secrets (SIGNUP_CODE). Values in it override the Environment= lines below.
# Keep it root:upstream 0640. The leading "-" means: fine if it does not exist.
EnvironmentFile=-/etc/upstream/upstream.env
# ---- configuration (see docs/DEPLOY.md, "Configuration") ----------------------------------------------------
Environment=NODE_ENV=production
Environment=PORT=8080
# "::" = one dual-stack socket for IPv4 + IPv6 (falls back to 0.0.0.0 if the kernel has no IPv6).
Environment=HOST=::
Environment=DB_PATH=/var/lib/upstream/game.db
# auto: believe X-Forwarded-For / X-Forwarded-Host only from loopback / private-range peers (your proxy).
Environment=TRUST_PROXY=auto
# Only when the proxy reaches this server from a NON-private address (global IPv6, Tailscale / CGNAT 100.64.0.0/10):
#Environment=TRUSTED_PROXIES=100.64.0.0/10,2001:db8::6
# Only when the proxy rewrites the Host header or you serve several public names (include the port if not 80/443):
#Environment=ALLOWED_ORIGINS=https://upstream.example.com
#Environment=MAX_CONN_PER_IP=40
# World settings: only read when the database has NO world yet (first boot). Change them later with
# `upstream-admin create-world` / `reset-world`, not here.
#Environment=WORLD_SPEED=1
#Environment=WORLD_RADIUS=50
#Environment=WORLD_NAME=World 1
# Invite code for signup. Empty/unset = open signup. Put the real value in /etc/upstream/upstream.env, not here.
#Environment=SIGNUP_CODE=
# ---- lifecycle ----------------------------------------------------------------------------------------------
Restart=on-failure
RestartSec=2
# SIGTERM closes the listener and the database and exits 0 within about a second; SIGKILL after 15 s as a backstop.
# (A SIGKILL is still safe for SQLite: the WAL is replayed on the next start and overdue events are caught up.)
TimeoutStopSec=15
# ---- hardening that works in any container (no mount namespaces needed) ------------------------------------
NoNewPrivileges=yes
CapabilityBoundingSet=
AmbientCapabilities=
# AF_NETLINK: Node's os.networkInterfaces() (start-up banner) and glibc's resolver use it.
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX AF_NETLINK
RestrictRealtime=yes
RestrictSUIDSGID=yes
LockPersonality=yes
SystemCallArchitectures=native
# New files (the database, its -wal/-shm, snapshots) are readable by the service user only: they hold password hashes.
UMask=0077
# Do NOT add MemoryDenyWriteExecute=yes: V8's JIT needs writable+executable memory and Node would crash.
# ---- optional extra hardening: needs mount namespaces ------------------------------------------------------
# In an unprivileged Proxmox LXC these fail with "status=226/NAMESPACE" unless the container has the
# "Nesting" feature enabled (Proxmox: container > Options > Features > Nesting; then restart the CT).
# Unlike Netwall this app writes to disk, so ProtectSystem=strict needs the ReadWritePaths line next to it.
# (StateDirectory= already makes /var/lib/upstream writable under strict; ReadWritePaths is the explicit belt.)
#ProtectSystem=strict
#ReadWritePaths=/var/lib/upstream
#ProtectHome=yes
#PrivateTmp=yes
#PrivateDevices=yes
#ProtectKernelTunables=yes
#ProtectKernelModules=yes
#ProtectKernelLogs=yes
#ProtectControlGroups=yes
#ProtectClock=yes
#ProtectHostname=yes
[Install]
WantedBy=multi-user.target