diff options
| author | aslan2142 <jan.trencansky@protonmail.com> | 2026-11-25 02:37:19 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-11-25 02:37:19 +0100 |
| commit | 18a22c1aefa227fd2eda047bab3385147d569f9d (patch) | |
| tree | 74ad707a670f980da61b5b9e0bc9241dfd6ef181 /scripts/linux-boot | |
| parent | 5a5df8e0b6bff458814c934e18f4216e69c40d36 (diff) | |
| parent | 71a783e56fb6eb591849b5c9fb6618ed3af3f595 (diff) | |
Merge pull request #984 from Moriz82/integration/proton-story-load
[integration] Linux/Proton and native Windows: boot through the story load (RT-PROTON-STORY-LOAD)
Diffstat (limited to 'scripts/linux-boot')
| -rwxr-xr-x | scripts/linux-boot/boot-digest.sh | 75 | ||||
| -rwxr-xr-x | scripts/linux-boot/boot-inner.sh | 45 | ||||
| -rwxr-xr-x | scripts/linux-boot/boot.sh | 42 | ||||
| -rwxr-xr-x | scripts/linux-boot/configure-worktree.sh | 9 | ||||
| -rwxr-xr-x | scripts/linux-boot/run-boot.sh | 56 |
5 files changed, 227 insertions, 0 deletions
diff --git a/scripts/linux-boot/boot-digest.sh b/scripts/linux-boot/boot-digest.sh new file mode 100755 index 000000000..dd2289e30 --- /dev/null +++ b/scripts/linux-boot/boot-digest.sh | |||
| @@ -0,0 +1,75 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # ExecStopPost of a leonida-boot-* unit: runs after the boot ends however it ended (exit, crash, oomd kill, timeout). | ||
| 3 | # Writes /opt/leonida/work/<agent>/boot-<n>.digest.txt and appends a line to /opt/leonida/work/boots.tsv. | ||
| 4 | # Local only: digests quote trace lines, so they never go into commits or PRs. | ||
| 5 | set -u | ||
| 6 | AGENT=$1; N=$2; WORK=/opt/leonida/work/$AGENT; LOG=$WORK/boot-$N.log; RES=$WORK/boot-$N.resources.tsv | ||
| 7 | META=$WORK/boot-$N.meta; OUT=$WORK/boot-$N.digest.txt; LEDGER=/opt/leonida/work/boots.tsv | ||
| 8 | START=$(sed -n 's/^start_epoch=//p' "$META" 2>/dev/null); BOOT=$(sed -n 's/^boot_epoch=//p' "$META" 2>/dev/null) | ||
| 9 | START=${START:-$(date +%s)}; BOOT=${BOOT:-$START}; END=$(date +%s) | ||
| 10 | RESULT=${SERVICE_RESULT:-?}; ECODE=${EXIT_CODE:-?}; ESTAT=${EXIT_STATUS:-?} | ||
| 11 | D3D=$(grep -o 'd3d12=[^ ]*' "$LOG" 2>/dev/null | tail -1 | cut -d= -f2) | ||
| 12 | STDOUT=${D3D/d3d12-run-/stdout-run-} | ||
| 13 | CAP=/opt/leonida/capture/$AGENT-$N | ||
| 14 | |||
| 15 | verdict=OK | ||
| 16 | # systemd-oomd can kill the unit's processes without the unit ending in "oom-kill" (boot.sh then exits on its own). | ||
| 17 | if journalctl --user -u "leonida-boot-$AGENT-$N" --since "@$START" -q --no-pager 2>/dev/null | grep -q 'systemd-oomd killed'; then RESULT=oom-kill; fi | ||
| 18 | case "$RESULT" in | ||
| 19 | oom-kill) verdict="KILLED BY OOM (systemd-oomd or kernel): memory, not a crash" ;; | ||
| 20 | timeout) verdict="TIMEOUT" ;; | ||
| 21 | exit-code) verdict="EXITED WITH ERROR (code $ECODE status $ESTAT)" ;; | ||
| 22 | signal|core-dump) verdict="KILLED BY SIGNAL ($ESTAT)" ;; | ||
| 23 | success) verdict="OK (ran to its time limit or exited cleanly)" ;; | ||
| 24 | esac | ||
| 25 | grep -q 'time limit reached' "$LOG" 2>/dev/null && [ "$RESULT" = success ] && verdict="OK (ran its full time limit)" | ||
| 26 | |||
| 27 | cnt() { local c=0; [ -f "$D3D" ] && c=$(grep -a -c -E "$@" "$D3D"); echo "${c:-0}"; } | ||
| 28 | { | ||
| 29 | echo "== leonida boot $AGENT-$N: $verdict" | ||
| 30 | echo "unit result=$RESULT exit_code=$ECODE exit_status=$ESTAT" | ||
| 31 | echo "queued $((BOOT-START)) s, ran $((END-BOOT)) s; trace $D3D" | ||
| 32 | sed -n '/^LEONIDA_\|^WINEDEBUG\|^unit=/p' "$META" 2>/dev/null | tr '\n' ' '; echo | ||
| 33 | echo | ||
| 34 | echo "-- counts" | ||
| 35 | echo "PresentX ok $(cnt 'XboxPresentation::PresentX ok') refused $(cnt 'XboxPresentation::PresentX failed')" | ||
| 36 | echo "CreatePipelineState failed $(cnt 'CreatePipelineState failed') FSPX compute misses $(cnt 'no translated compute shader for FSPX') slot-67 failed $(cnt 'slot 67 call .* failed')" | ||
| 37 | echo "E_NOTIMPL $(cnt 'E_NOTIMPL') wine err: lines $(cnt '^[0-9a-f]{4}:err:|:err:') exceptions $(cnt -i 'exception|unhandled|page fault|access violation')" | ||
| 38 | grep -a -m1 -E 'translated shaders \(' "$D3D" 2>/dev/null | ||
| 39 | grep -a 'present-probe: source frame .* via' "$D3D" 2>/dev/null | tail -1 | sed 's/.*via/source via/' | cut -c1-120 | ||
| 40 | echo | ||
| 41 | echo "-- frames (swapchain; then the title's own backbuffer when LEONIDA_CAPTURE_SOURCE=1)" | ||
| 42 | [ -f "$CAP/index.txt" ] && { echo "$(wc -l < "$CAP/index.txt") captured; last: $(tail -1 "$CAP/index.txt" | cut -c1-110)"; awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print n+0 " of " NR " frames non-black"}' "$CAP/index.txt"; } || echo "no capture index" | ||
| 43 | grep -a 'present-probe: source frame .* mean' "$D3D" 2>/dev/null | tail -2 | sed 's/.*source frame/source frame/' | cut -c1-140 | ||
| 44 | echo | ||
| 45 | echo "-- resources (2 s samples)" | ||
| 46 | [ -s "$RES" ] && awk -F'\t' 'NR>1{ if(min==""||$2<min)min=$2; if($3>sw)sw=$3; if($4>um)um=$4; if($5>us)us=$5; if($6+0>gm)gm=$6 } END{printf "min RAM available %s MB, max swap used %s MB, game peak %s MB RAM + %s MB swap, VRAM peak %s MB\n",min,sw,um,us,gm}' "$RES" || echo "no samples" | ||
| 47 | journalctl --user -u "leonida-boot-$AGENT-$N" --since "@$START" -q --no-pager 2>/dev/null | grep -E 'Consumed|oom|Failed' | sed 's/^.*\]: //' | sort -u | cut -c1-200 | ||
| 48 | # Compare with other boots instead of guessing: on the console (Series S) path the title itself grows to ~20 GB of | ||
| 49 | # RAM+swap by ~130 s (fsdraw-6: 9.9 GB + 11.2 GB), mostly zero pages that zram compresses well. | ||
| 50 | [ -s "$RES" ] && awk -F'\t' 'NR>1{t=$4+$5; if(t>m)m=t} END{printf "game peak RAM+swap %.1f GB (console-path baseline ~20 GB at 130 s; oomd kills when zram swap passes 98%%)\n", m/1024}' "$RES" | ||
| 51 | echo | ||
| 52 | echo "-- system events during the boot (OOM, GPU Xid, segfaults)" | ||
| 53 | { journalctl --since "@$BOOT" -q --no-pager 2>/dev/null | grep -i -E 'systemd-oomd.*(Marked|killed)|oom-kill|out of memory|NVRM: Xid|segfault|gta6rt|wineserver.*crash' ; } | cut -c1-200 | tail -15 | ||
| 54 | echo | ||
| 55 | echo "-- distinct error lines (normalised, with counts; top 60)" | ||
| 56 | for f in "$D3D" "$STDOUT"; do [ -f "$f" ] && cat "$f"; done 2>/dev/null \ | ||
| 57 | | grep -a -i -E 'error|fail|E_NOTIMPL|E_INVALIDARG|E_FAIL|0x8[0-9a-f]{7}|exception|assert|abort|unhandled|page fault|refused|not implemented|no translated|no emulation|crash|:err:|fatal|cannot|could not|unsupported|invalid' \ | ||
| 58 | | grep -a -v -E ' ok$| called$' \ | ||
| 59 | | sed -E 's/#[0-9]+/#N/g; s/0x[0-9a-fA-F]{6,}/0xADDR/g; s/\b[0-9a-f]{64}\b/SHA/g; s/[0-9]{4,}/NUM/g; s/^[0-9a-f]{4}:/TID:/' \ | ||
| 60 | | cut -c1-220 | sort | uniq -c | sort -rn | head -60 | ||
| 61 | echo | ||
| 62 | echo "-- where the trace ended" | ||
| 63 | [ -f "$D3D" ] && tail -n 8 "$D3D" | cut -c1-200 | ||
| 64 | } > "$OUT" 2>&1 | ||
| 65 | |||
| 66 | frames=$( [ -f "$CAP/index.txt" ] && awk '{m=$(NF-2)+$(NF-1)+$NF; if (m>0) n++} END{print (n+0) "/" NR}' "$CAP/index.txt" || echo "-") | ||
| 67 | peak=$( [ -s "$RES" ] && awk -F'\t' 'NR>1{if($4>u)u=$4} END{print u+0}' "$RES" || echo "-") | ||
| 68 | exec 7>>"$LEDGER"; flock 7 | ||
| 69 | # Both the unit's ExecStopPost and the outer wrapper call this; the first one to finish records the boot. | ||
| 70 | grep -q -P "^[^\t]*\t$AGENT\t$N\t" "$LEDGER" 2>/dev/null && exit 0 | ||
| 71 | [ -s "$LEDGER" ] || printf 'end\tagent\tn\tresult\tran_s\tpresentx_ok\tpso_failed\tfspx_miss\tnonblack_frames\tpeak_mb\tgta6rt\n' >&7 | ||
| 72 | printf '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' "$(date '+%F %T')" "$AGENT" "$N" "$RESULT" "$((END-BOOT))" \ | ||
| 73 | "$(cnt 'XboxPresentation::PresentX ok')" "$(cnt 'CreatePipelineState failed')" "$(cnt 'no translated compute shader for FSPX')" \ | ||
| 74 | "$frames" "$peak" "$(sed -n 's/^unit=.*gta6rt=\([^ ]*\).*/\1/p' "$META")" >&7 | ||
| 75 | exit 0 | ||
diff --git a/scripts/linux-boot/boot-inner.sh b/scripts/linux-boot/boot-inner.sh new file mode 100755 index 000000000..e52d3daef --- /dev/null +++ b/scripts/linux-boot/boot-inner.sh | |||
| @@ -0,0 +1,45 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Runs inside the leonida-boot-* unit (see run-boot.sh). Waits for memory, takes the locks, samples resources, boots. | ||
| 3 | set -u | ||
| 4 | WORK=/opt/leonida/work/$BOOT_AGENT; N=$BOOT_N; LOG=$WORK/boot-$N.log; RES=$WORK/boot-$N.resources.tsv | ||
| 5 | META=$WORK/boot-$N.meta | ||
| 6 | : > "$LOG" | ||
| 7 | echo "start_epoch=$(date +%s)" > "$META" | ||
| 8 | echo "unit=leonida-boot-$BOOT_AGENT-$N gta6rt=$GTA6RT secs=$BOOT_SECS" >> "$META" | ||
| 9 | env | grep -E '^(LEONIDA_|WINEDEBUG=)' | sort >> "$META" | ||
| 10 | |||
| 11 | mem_free_mb() { # RAM available plus a third of free zram swap (zram pages cost RAM, roughly 3:1) | ||
| 12 | awk '/^MemAvailable:/{a=$2} /^SwapFree:/{s=$2} END{printf "%d", (a + s/3)/1024}' /proc/meminfo | ||
| 13 | } | ||
| 14 | NEED=${LEONIDA_BOOT_MIN_FREE_MB:-6500} | ||
| 15 | swap_pct() { awk '/^SwapTotal:/{t=$2} /^SwapFree:/{f=$2} END{printf "%d", t ? (t-f)*100/t : 0}' /proc/meminfo; } | ||
| 16 | |||
| 17 | exec 8>/opt/leonida/.gpu.lock; flock 8 # one boot at a time | ||
| 18 | echo "[run-boot] $(date +%T) got the GPU lock" >> "$LOG" | ||
| 19 | for i in $(seq 1 40); do # up to 10 min for memory headroom | ||
| 20 | f=$(mem_free_mb); sp=$(swap_pct); [ "$f" -ge "$NEED" ] && [ "$sp" -lt 70 ] && break | ||
| 21 | echo "[run-boot] $(date +%T) waiting for memory: ${f} MB free (need ${NEED}), swap ${sp}% (need < 70%)" >> "$LOG"; sleep 15 | ||
| 22 | done | ||
| 23 | echo "[run-boot] $(date +%T) memory before boot: $(mem_free_mb) MB free, swap $(swap_pct)%" >> "$LOG" | ||
| 24 | exec 9>/opt/leonida/.build.lock; flock 9 # no compiles while the game runs | ||
| 25 | echo "[run-boot] $(date +%T) got the build lock; booting" >> "$LOG" | ||
| 26 | echo "boot_epoch=$(date +%s)" >> "$META" | ||
| 27 | |||
| 28 | CG=/sys/fs/cgroup$(cut -d: -f3 /proc/self/cgroup) | ||
| 29 | ( printf 'time\tmem_avail_mb\tswap_used_mb\tunit_mem_mb\tunit_swap_mb\tgpu_mem_mb\tgpu_util\n' | ||
| 30 | while :; do | ||
| 31 | read -r ma su < <(awk '/^MemAvailable:/{a=$2} /^SwapTotal:/{t=$2} /^SwapFree:/{f=$2} END{print int(a/1024), int((t-f)/1024)}' /proc/meminfo) | ||
| 32 | um=$(( $(cat "$CG/memory.current" 2>/dev/null || echo 0) / 1048576 )); us=$(( $(cat "$CG/memory.swap.current" 2>/dev/null || echo 0) / 1048576 )) | ||
| 33 | g=$(nvidia-smi --query-gpu=memory.used,utilization.gpu --format=csv,noheader,nounits 2>/dev/null | tr -d ' ' | tr ',' '\t') | ||
| 34 | printf '%s\t%s\t%s\t%s\t%s\t%s\n' "$(date +%T)" "$ma" "$su" "$um" "$us" "${g:-? ?}" | ||
| 35 | sleep 2 | ||
| 36 | done ) > "$RES" 2>/dev/null & | ||
| 37 | SAMPLER=$! | ||
| 38 | |||
| 39 | /opt/leonida/boot.sh run "$BOOT_SECS" >> "$LOG" 2>&1 | ||
| 40 | rc=$? | ||
| 41 | kill $SAMPLER 2>/dev/null | ||
| 42 | echo "[run-boot] $(date +%T) boot.sh exit $rc" >> "$LOG" | ||
| 43 | # boot.sh stops the title with timeout(1) at the time limit: 124 means it ran the whole time, which is success here. | ||
| 44 | [ "$rc" = 124 ] && { echo "[run-boot] time limit reached" >> "$LOG"; rc=0; } | ||
| 45 | exit $rc | ||
diff --git a/scripts/linux-boot/boot.sh b/scripts/linux-boot/boot.sh new file mode 100755 index 000000000..55f84f019 --- /dev/null +++ b/scripts/linux-boot/boot.sh | |||
| @@ -0,0 +1,42 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Boot the packaged port under Wine with the network off (unshare -rn: user + network namespace, no root). | ||
| 3 | # usage: boot.sh dry-run|init|run [seconds] (run defaults to 150 s, then the title is stopped) | ||
| 4 | # Traces stay local in /opt/leonida/traces: they can quote game data, never post them. | ||
| 5 | set -u | ||
| 6 | MODE=${1:?dry-run|init|run}; SECS=${2:-150} | ||
| 7 | OUT=/opt/leonida | ||
| 8 | REPO=${LEONIDA_REPO:-$(cd "$(dirname "$(readlink -f "$0")")/../.." && pwd)} # the checkout this script is in | ||
| 9 | STAMP=$(date +%H%M%S) | ||
| 10 | T=$OUT/traces; mkdir -p "$T" "$OUT/overlay" "$OUT/cache/nv" | ||
| 11 | |||
| 12 | WINE=${WINE:-wine} # e.g. WINE=".../Proton - Experimental/files/bin/wine" WINEPREFIX=~/.local/share/leonida-proton/pfx | ||
| 13 | export WINEPREFIX=${WINEPREFIX:-$HOME/.local/share/leonida-wine} WINEDEBUG=${WINEDEBUG:--all} WINEDLLOVERRIDES="mscoree,mshtml=" | ||
| 14 | export LEONIDA_D3D12=vulkan | ||
| 15 | export LEONIDA_SHADERS=$OUT/work/shaders/spirv | ||
| 16 | export LEONIDA_ARENA_MB=${LEONIDA_ARENA_MB:-2048} | ||
| 17 | export LEONIDA_PIPELINE_CACHE_BYTES=${LEONIDA_PIPELINE_CACHE_BYTES:-4294967296} | ||
| 18 | export LEONIDA_STARTUP_CACHE_CHECKPOINTS=1 | ||
| 19 | export __GL_SHADER_DISK_CACHE=1 __GL_SHADER_DISK_CACHE_PATH=$OUT/cache/nv __GL_SHADER_DISK_CACHE_SIZE=21474836480 | ||
| 20 | export __GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1 | ||
| 21 | [ -n "${SKIP_INT3:-}" ] && export LEONIDA_SKIP_INT3=1 | ||
| 22 | |||
| 23 | GAME_WIN='Z:\opt\gta6\GTA6.Xbox.v1.0.2.1' | ||
| 24 | EXE=/opt/gta6/GTA6.Xbox.v1.0.2.1/game_scarlett_master.exe | ||
| 25 | TRACE_WIN="Z:\\opt\\leonida\\traces\\boot-$MODE-$STAMP.jsonl" | ||
| 26 | D3D=$T/d3d12-$MODE-$STAMP.log | ||
| 27 | GTA6RT=${GTA6RT:-$OUT/gta6rt.exe}; [ -f "$GTA6RT" ] || GTA6RT=$REPO/runtime/build/boot/gta6rt.exe # GTA6RT=<your build>/gta6rt.exe boots a private build without installing it | ||
| 28 | |||
| 29 | args=(--"$MODE" "$EXE" --game-dir "$GAME_WIN" --overlay 'Z:\opt\leonida\overlay' --trace "$TRACE_WIN") | ||
| 30 | [ "$MODE" = run ] && args+=(--trace-d3d12) | ||
| 31 | echo "[boot] $MODE gta6rt=$GTA6RT trace=$T/boot-$MODE-$STAMP.jsonl d3d12=$D3D" | ||
| 32 | # unshare: new user + network namespace, so the title has no network at all | ||
| 33 | if [ "$MODE" = run ]; then | ||
| 34 | timeout --signal=INT --kill-after=20 "$SECS" unshare -rn "$WINE" "$GTA6RT" "${args[@]}" > "$T/stdout-$MODE-$STAMP.log" 2> "$D3D" | ||
| 35 | else | ||
| 36 | unshare -rn "$WINE" "$GTA6RT" "${args[@]}" > "$T/stdout-$MODE-$STAMP.log" 2> "$D3D" | ||
| 37 | fi | ||
| 38 | rc=$?; echo "[boot] exit=$rc" | ||
| 39 | sleep 0 | ||
| 40 | python3 -I "$REPO/tools/boot_trace.py" "$T/boot-$MODE-$STAMP.jsonl" --d3d12 "$D3D" > "$T/summary-$MODE-$STAMP.txt" 2>&1 | ||
| 41 | echo "[boot] summary: $T/summary-$MODE-$STAMP.txt" | ||
| 42 | exit $rc | ||
diff --git a/scripts/linux-boot/configure-worktree.sh b/scripts/linux-boot/configure-worktree.sh new file mode 100755 index 000000000..c983b3357 --- /dev/null +++ b/scripts/linux-boot/configure-worktree.sh | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # usage: configure-worktree.sh <worktree> | ||
| 3 | # Configures a Windows build of the runtime on Linux with clang-cl and an xwin SDK (XWIN_DIR, default | ||
| 4 | # ~/.local/share/xwin-sdk). SDL3_SRC=<an SDL3 source tree> makes the configure work offline. | ||
| 5 | set -eu; W=$(realpath "$1") | ||
| 6 | cmake -S "$W/runtime" -B "$W/runtime/build/boot" -G Ninja -DCMAKE_BUILD_TYPE=Release \ | ||
| 7 | -DCMAKE_TOOLCHAIN_FILE="$W/runtime/cmake/clang-cl-xwin.cmake" -DXWIN_DIR="${XWIN_DIR:-$HOME/.local/share/xwin-sdk}" \ | ||
| 8 | -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DLEONIDA_SDL3=ON \ | ||
| 9 | ${SDL3_SRC:+-DFETCHCONTENT_SOURCE_DIR_SDL3="$SDL3_SRC"} | ||
diff --git a/scripts/linux-boot/run-boot.sh b/scripts/linux-boot/run-boot.sh new file mode 100755 index 000000000..523d17795 --- /dev/null +++ b/scripts/linux-boot/run-boot.sh | |||
| @@ -0,0 +1,56 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | # Boot gta6rt as its own systemd --user unit, protected from the swarm and logged in full. | ||
| 3 | # | ||
| 4 | # usage: run-boot.sh <agent> <n> <gta6rt.exe> [seconds=150] [KEY=VALUE ...] | ||
| 5 | # e.g. run-boot.sh fsdraw 3 /path/wt-fsdraw/runtime/build/boot/gta6rt.exe 150 LEONIDA_FOO=1 | ||
| 6 | # | ||
| 7 | # What it does for you: | ||
| 8 | # - runs the boot outside your agent's process tree (survives agent/session restarts); | ||
| 9 | # - waits for memory headroom before starting, then holds the GPU lock AND the build lock for the whole boot, | ||
| 10 | # so no compile competes with the game for RAM; | ||
| 11 | # - Series S profile, late-frame capture, source capture and Wine's error channel on by default (override with KEY=VALUE); | ||
| 12 | # - samples RAM / swap / the game's memory / VRAM every 2 s; | ||
| 13 | # - after the boot, even when systemd-oomd or a crash kills it, writes a digest with the unit result, OOM and GPU | ||
| 14 | # kernel events and every distinct error line, and appends one line to the shared ledger /opt/leonida/work/boots.tsv. | ||
| 15 | # | ||
| 16 | # Outputs (in /opt/leonida/work/<agent>/): boot-<n>.log boot-<n>.resources.tsv boot-<n>.digest.txt | ||
| 17 | set -u | ||
| 18 | AGENT=${1:?agent}; N=${2:?n}; EXE=${3:?gta6rt.exe}; SECS=${4:-150}; shift $(( $# >= 4 ? 4 : $# )) | ||
| 19 | [ -f "$EXE" ] || { echo "run-boot: no such gta6rt: $EXE" >&2; exit 2; } | ||
| 20 | # gta6rt loads gta6rt_tls_host.dll from its own folder; without it the title gets no module TLS index and exits at once. | ||
| 21 | [ -f "$(dirname "$EXE")/gta6rt_tls_host.dll" ] || { echo "run-boot: $(dirname "$EXE")/gta6rt_tls_host.dll is missing: copy it next to the exe (build it with the gta6rt target) or boot the exe from its build folder" >&2; exit 2; } | ||
| 22 | WORK=/opt/leonida/work/$AGENT; mkdir -p "$WORK" | ||
| 23 | UNIT=leonida-boot-$AGENT-$N | ||
| 24 | if systemctl --user is-active --quiet "$UNIT"; then echo "run-boot: $UNIT is already running" >&2; exit 2; fi | ||
| 25 | |||
| 26 | declare -A ENV=( | ||
| 27 | [WINE]="$HOME/.local/share/Steam/steamapps/common/Proton - Experimental/files/bin/wine" | ||
| 28 | [WINEPREFIX]="$HOME/.local/share/leonida-proton/pfx" | ||
| 29 | [WINEDEBUG]="-all,err+all" | ||
| 30 | [GTA6RT]="$EXE" | ||
| 31 | [LEONIDA_CAPTURE]="Z:\\opt\\leonida\\capture\\$AGENT-$N" | ||
| 32 | [LEONIDA_CAPTURE_EVERY]=4800 [LEONIDA_CAPTURE_LIMIT]=24 [LEONIDA_CAPTURE_SOURCE]=1 | ||
| 33 | [LEONIDA_DEVICE_TYPE]=6 | ||
| 34 | [LEONIDA_PIPELINE_CACHE_DIR]="Z:\\opt\\leonida\\cache\\pipelines" | ||
| 35 | ) | ||
| 36 | for kv in "$@"; do ENV[${kv%%=*}]="${kv#*=}"; done | ||
| 37 | args=() | ||
| 38 | for k in "${!ENV[@]}"; do args+=(--setenv="$k=${ENV[$k]}"); done | ||
| 39 | |||
| 40 | echo "run-boot: $UNIT starting (queues for memory headroom, the GPU lock and the build lock)" | ||
| 41 | rm -f "$WORK/boot-$N.digest.txt" | ||
| 42 | systemd-run --user --collect --quiet --unit="$UNIT" -p WorkingDirectory=/opt/leonida \ | ||
| 43 | --setenv=BOOT_AGENT="$AGENT" --setenv=BOOT_N="$N" --setenv=BOOT_SECS="$SECS" "${args[@]}" \ | ||
| 44 | /opt/leonida/boot-inner.sh || { echo "run-boot: could not start $UNIT" >&2; exit 2; } | ||
| 45 | # The digest is written by a separate, tiny watcher unit: it survives systemd-oomd killing the boot's cgroup and the | ||
| 46 | # caller's shell going away. It waits for the boot unit to end, reads its result from the journal and writes the digest. | ||
| 47 | systemd-run --user --collect --quiet --unit="leonida-digest-$AGENT-$N" -p MemoryMax=256M \ | ||
| 48 | /bin/bash -c 'while systemctl --user is-active --quiet "$0" || systemctl --user is-activating --quiet "$0"; do sleep 3; done | ||
| 49 | START=$(sed -n "s/^start_epoch=//p" "/opt/leonida/work/$1/boot-$2.meta" 2>/dev/null) | ||
| 50 | RES=$(journalctl --user -u "$0" ${START:+--since "@$START"} -q --no-pager 2>/dev/null | grep -o "Failed with result .[a-z-]*." | tail -1 | tr -d "\x27" | sed "s/Failed with result //") | ||
| 51 | SERVICE_RESULT=${RES:-success} exec /opt/leonida/boot-digest.sh "$1" "$2"' "$UNIT" "$AGENT" "$N" | ||
| 52 | # Block until the digest exists (so a caller that waits on this script gets the result), then print it. | ||
| 53 | while [ ! -s "$WORK/boot-$N.digest.txt" ] || systemctl --user is-active --quiet "leonida-digest-$AGENT-$N"; do sleep 5; done | ||
| 54 | echo "run-boot: $UNIT finished. Digest:" | ||
| 55 | cat "$WORK/boot-$N.digest.txt" | ||
| 56 | head -1 "$WORK/boot-$N.digest.txt" | grep -q ': OK' && exit 0 || exit 1 | ||