#!/usr/bin/env bash # remote-run.sh: run heavy cargo commands on the lane servers instead of this machine. # # Usage: # scripts/remote-run.sh [--host auto|a|b|c] [--with-edith] [--clean] -- # scripts/remote-run.sh --clean # # --host auto|a|b|c auto (default) probes a, b and c each round (one ssh each: busy slots and # MemAvailable) and tries the least loaded first: fewest busy slots, then most # MemAvailable. Unreachable hosts are skipped. It retries for up to 10 minutes # (20 s between rounds), then builds locally. # --with-edith also sync the edith tree ($EDITH_TREE, default # $HOME/Documents/Code/Rust/edith) to ~/lanes//edith and run # the command inside it. Its path deps ../../../edith_codecs resolve to # ~/lanes//edith_codecs. # --clean remove ~/lanes/, ~/.cache/tgt- and ~/tmp/ on every host, # and ~/.cache/tgt-, ~/.cache/tmp- locally. # # The source tree is the git toplevel of the current directory (worktrees work). It is rsynced # to ~/lanes//edith_codecs on the host, without target/, fixtures/ and .git. The host gets # fixtures -> ~/fixtures as a symlink. The command runs under the host's slot lock (~/.remote-slot), # so one heavy job at a time per server. # # Three job slots per host (~/.remote-slot.0, .1 and .2), each with CARGO_BUILD_JOBS=2. # Remote env: CARGO_TARGET_DIR=~/.cache/tgt-, TMPDIR=~/tmp/, CARGO_BUILD_JOBS=2, # EC_MEMGUARD_MAX=3500M (the memory cap read by scripts/memguard-runner.sh). Every EC_* variable # from the local environment is forwarded and wins over the defaults. # # Exit codes: the remote command's code. 75 means the slot stayed busy (with --host a or b, after # 10 minutes). A command that itself exits 75 looks the same and is retried on the next host. # 255 means the chosen host was unreachable. stderr shows "remote-run: host=a|b|c|local" when a run starts. set -uo pipefail [ -f "$HOME/.config/edith_codecs/remote-hosts" ] && . "$HOME/.config/edith_codecs/remote-hosts" HOST_A=${EC_HOST_A:-} HOST_B=${EC_HOST_B:-} HOST_C=${EC_HOST_C:-} EDITH_TREE=${EDITH_TREE:-$HOME/Documents/Code/Rust/edith} EDITH_ASSETS=${EDITH_ASSETS:-$HOME/Documents/Code/Rust/edith/assets} SSH=(ssh -o BatchMode=yes -o ConnectTimeout=20) RSYNC_RSH="ssh -o BatchMode=yes -o ConnectTimeout=20" BUSY=75 UNREACH=254 RETRY_SECS=20 RETRY_TOTAL=600 die() { echo "remote-run: $*" >&2; exit 2; } [ $# -ge 1 ] || { sed -n '2,25p' "$0" >&2; exit 2; } case $1 in -h|--help) sed -n '2,25p' "$0" >&2; exit 0 ;; esac lane=$1 shift host=auto with_edith=0 clean=0 cmd=() while [ $# -gt 0 ]; do case $1 in --host) [ $# -ge 2 ] || die "--host needs a value"; host=$2; shift 2 ;; --host=*) host=${1#--host=}; shift ;; --with-edith) with_edith=1; shift ;; --clean) clean=1; shift ;; --) shift; cmd=("$@"); break ;; *) die "unknown argument: $1 (put the command after --)" ;; esac done [[ $lane =~ ^[A-Za-z0-9][A-Za-z0-9._-]*$ ]] || die "bad lane name: $lane" case $host in auto|a|b|c) ;; *) die "--host must be auto, a, b or c" ;; esac host_addr() { case $1 in a) echo "$HOST_A" ;; b) echo "$HOST_B" ;; c) echo "$HOST_C" ;; esac; } # rsh