BlueGit

timfa questward

Files

questward / deploy / install-service.sh

install-service.sh

install-service.sh 1.2 KiB Download Raw
1#!/usr/bin/env bash
2# Install and start the Questward systemd unit (run as root on the game host).
3set -euo pipefail
4
5SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
6REPO="${QUESTWARD_REPO:-${TILE_MMO_REPO:-$(cd "$SCRIPT_DIR/.." && pwd)}}"
7UNIT_SRC="$SCRIPT_DIR/questward.service"
8UNIT_DST="/etc/systemd/system/questward.service"
9SERVICE_USER="${QUESTWARD_USER:-${TILE_MMO_USER:-questward}}"
10
11if [[ "$(id -u)" -ne 0 ]]; then
12 echo "Run as root: sudo $0" >&2
13 exit 1
14fi
15
16if [[ ! -f "$UNIT_SRC" ]]; then
17 echo "Missing unit file: $UNIT_SRC" >&2
18 exit 1
19fi
20
21chmod +x "$SCRIPT_DIR/start-server.sh" "$SCRIPT_DIR/install-service.sh" "$SCRIPT_DIR/update-if-requested.mjs" 2>/dev/null || true
22
23# Rewrite WorkingDirectory / paths for this checkout.
24tmp="$(mktemp)"
25sed \
26 -e "s|/srv/questward/current|$REPO|g" \
27 -e "s|^User=.*|User=$SERVICE_USER|" \
28 -e "s|^Group=.*|Group=$SERVICE_USER|" \
29 "$UNIT_SRC" > "$tmp"
30install -m 0644 "$tmp" "$UNIT_DST"
31rm -f "$tmp"
32
33systemctl daemon-reload
34systemctl enable questward.service
35systemctl restart questward.service
36systemctl --no-pager --full status questward.service || true
37
38echo
39echo "Installed $UNIT_DST"
40echo "Repo: $REPO"
41echo "Logs: journalctl -u questward -f"