|
| 1 | +#!/usr/bin/env bash |
| 2 | +# Create, register, and start a GitHub Actions runner. |
| 3 | +# |
| 4 | +# Sourced by misc/runners/runner.sh after config is loaded. |
| 5 | +# Config must define runner_install_dir() and may set TARBALL_CACHE_DIR. |
| 6 | +# |
| 7 | +# runner_install_dir <name> [override-dir] |
| 8 | +# Returns the directory where the runner should be installed. |
| 9 | +# If override-dir is given it is used directly; otherwise the site |
| 10 | +# computes the path (e.g. SHARED_DIR/<name> on Frontier, or an |
| 11 | +# auto-numbered actions-runner-N/ directory on Phoenix). |
| 12 | +# |
| 13 | +# TARBALL_CACHE_DIR |
| 14 | +# If non-empty, the runner tarball is cached here and reused across |
| 15 | +# installs (useful on Frontier where shared Lustre is visible from all |
| 16 | +# login nodes). If empty or unset, a fresh download is made for each |
| 17 | +# runner and the temporary file is removed after extraction. |
| 18 | +# |
| 19 | +# Usage: runner.sh <site> create-runner <name> <node> [install-dir] |
| 20 | +# name Runner name (e.g. frontier-23, phoenix-11) |
| 21 | +# node Login node to start the runner on |
| 22 | +# install-dir Optional: override the computed installation directory |
| 23 | +set -euo pipefail |
| 24 | + |
| 25 | +RUNNER_NAME="${1:?Usage: create-runner <name> <node> [install-dir]}" |
| 26 | +TARGET_NODE="${2:?Usage: create-runner <name> <node> [install-dir]}" |
| 27 | +INSTALL_DIR_OVERRIDE="${3:-}" |
| 28 | + |
| 29 | +RUNNER_DIR=$(runner_install_dir "$RUNNER_NAME" "$INSTALL_DIR_OVERRIDE") |
| 30 | +RUNNER_VERSION="${RUNNER_VERSION:-$(gh_latest_runner_version 2>/dev/null || echo "2.332.0")}" |
| 31 | +TARBALL="actions-runner-linux-x64-${RUNNER_VERSION}.tar.gz" |
| 32 | +TARBALL_URL="https://github.com/actions/runner/releases/download/v${RUNNER_VERSION}/${TARBALL}" |
| 33 | + |
| 34 | +echo "=== Creating runner ===" |
| 35 | +echo " Name: $RUNNER_NAME" |
| 36 | +echo " Node: $TARGET_NODE" |
| 37 | +echo " Directory: $RUNNER_DIR" |
| 38 | +echo " Org: $ORG" |
| 39 | +echo " Group: $RUNNER_GROUP" |
| 40 | +echo " Label: $RUNNER_LABEL" |
| 41 | +echo " Version: $RUNNER_VERSION" |
| 42 | +echo "" |
| 43 | + |
| 44 | +if [ -d "$RUNNER_DIR" ]; then |
| 45 | + echo "ERROR: Directory already exists: $RUNNER_DIR" >&2 |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +# --- Download tarball --- |
| 50 | +if [ -n "${TARBALL_CACHE_DIR:-}" ]; then |
| 51 | + if [ ! -f "$TARBALL_CACHE_DIR/$TARBALL" ]; then |
| 52 | + echo "==> Downloading runner v${RUNNER_VERSION} to cache..." |
| 53 | + tmp="$TARBALL_CACHE_DIR/$TARBALL.tmp.$$" |
| 54 | + curl -fsSL "$TARBALL_URL" -o "$tmp" |
| 55 | + mv "$tmp" "$TARBALL_CACHE_DIR/$TARBALL" |
| 56 | + fi |
| 57 | + tarball_path="$TARBALL_CACHE_DIR/$TARBALL" |
| 58 | +else |
| 59 | + echo "==> Downloading runner v${RUNNER_VERSION}..." |
| 60 | + mkdir -p "$RUNNER_DIR" |
| 61 | + tarball_path="$RUNNER_DIR/runner-download.tmp.$$" |
| 62 | + curl -fsSL "$TARBALL_URL" -o "$tarball_path" |
| 63 | +fi |
| 64 | + |
| 65 | +# --- Extract --- |
| 66 | +mkdir -p "$RUNNER_DIR" |
| 67 | +echo "==> Extracting into $RUNNER_DIR..." |
| 68 | +tar xzf "$tarball_path" -C "$RUNNER_DIR" |
| 69 | +[ -z "${TARBALL_CACHE_DIR:-}" ] && rm -f "$tarball_path" |
| 70 | + |
| 71 | +if [ ! -f "$RUNNER_DIR/run.sh" ]; then |
| 72 | + echo "ERROR: Extraction failed — run.sh not found in $RUNNER_DIR" >&2 |
| 73 | + exit 1 |
| 74 | +fi |
| 75 | + |
| 76 | +# --- Register --- |
| 77 | +echo "==> Fetching registration token..." |
| 78 | +token=$(gh_registration_token) |
| 79 | +if [ -z "$token" ]; then |
| 80 | + echo "ERROR: Failed to get registration token." >&2 |
| 81 | + echo " Run: gh auth refresh -h github.com -s admin:org" >&2 |
| 82 | + exit 1 |
| 83 | +fi |
| 84 | + |
| 85 | +echo "==> Configuring runner..." |
| 86 | +"$RUNNER_DIR/config.sh" \ |
| 87 | + --url "https://github.com/$ORG" \ |
| 88 | + --token "$token" \ |
| 89 | + --name "$RUNNER_NAME" \ |
| 90 | + --runnergroup "$RUNNER_GROUP" \ |
| 91 | + --labels "$RUNNER_LABEL" \ |
| 92 | + --work "_work" \ |
| 93 | + --unattended \ |
| 94 | + --replace |
| 95 | +echo "==> Configured." |
| 96 | + |
| 97 | +# --- Start --- |
| 98 | +echo "==> Starting on $TARGET_NODE..." |
| 99 | +if start_runner "$TARGET_NODE" "$RUNNER_DIR"; then |
| 100 | + echo "$TARGET_NODE" > "$RUNNER_DIR/runner.node" |
| 101 | + pids=$(find_pids "$TARGET_NODE" "$RUNNER_DIR") |
| 102 | + pid=${pids%% *} |
| 103 | + if has_slurm "$TARGET_NODE" "$pid"; then |
| 104 | + echo "==> OK: $RUNNER_NAME running on $TARGET_NODE (PID $pid, slurm in PATH)" |
| 105 | + else |
| 106 | + echo "==> WARNING: $RUNNER_NAME running on $TARGET_NODE (PID $pid) but slurm MISSING from PATH" |
| 107 | + fi |
| 108 | +else |
| 109 | + echo "ERROR: $RUNNER_NAME did not start on $TARGET_NODE" >&2 |
| 110 | + exit 1 |
| 111 | +fi |
| 112 | + |
| 113 | +echo "" |
| 114 | +echo "==> Log: $RUNNER_DIR/runner.log" |
0 commit comments