SPB Git forge
15commits 1branches 0releases
29.7 MBsize
maindefault branch
10 days agolast push
TypeScript 36.3% Python 31.8% Go 18% JavaScript 9.8% Shell 1.9% SQL 1.4% CSS 0.5%
3.6 KB · 74 lines shellscript
Raw Blame History
1#!/usr/bin/env bash2# Build the Go probe agent and (re)install it on every node listed in data/seed/probes.yaml.3#4#   deploy/bin/probes.sh build                 cross-compile dist/ip-probe-{darwin-arm64,linux-amd64}5#   deploy/bin/probes.sh keys                  print probe ids + keys from the production API (BHS64b)6#   deploy/bin/probes.sh install [probe_id…]   push binary + installer to the node(s) and (re)start the service7#   deploy/bin/probes.sh status                /healthz of every probe8#9# Sudo passwords for the rented Macs live OUTSIDE the repo in ~/.internetpressure/sudo.txt ("<node> <password>" per10# line; nodes with passwordless sudo are simply absent). Keys are read from the production Postgres through11# `docker compose run --rm cli probe-key <id>` on BHS64b and never written to disk here.12source "$(dirname "${BASH_SOURCE[0]}")/lib.sh"1314AGENT="$REPO_ROOT/services/probe-agent"15SUDO_FILE="$HOME/.internetpressure/sudo.txt"16INGEST_URL="${IP_INGEST_URL:-https://$IP_DOMAIN/ingest/v1}"1718probes_nodes() {  # "probe_id node" pairs from the seed19  python3 - "$REPO_ROOT/data/seed/probes.yaml" <<'EOF'20import sys, yaml21for p in yaml.safe_load(open(sys.argv[1]))["probes"]:22    print(p["probe_id"], p["node"])23EOF24}2526probe_key() { compose "run --rm --no-deps -T cli probe-key $1" 2>/dev/null | tail -1 | tr -d '\r'; }2728sudo_pw() { [[ -f "$SUDO_FILE" ]] && awk -v n="$1" '$1==n {print $2}' "$SUDO_FILE" || true; }2930install_one() {31  local pid="$1" node="$2" key="$3"32  local os arch bin33  os=$(ssh -n -o BatchMode=yes -o ConnectTimeout=20 "$node" 'uname -s | tr A-Z a-z') || { warn "$node unreachable"; return 1; }34  arch=$(ssh -n -o BatchMode=yes "$node" 'uname -m')35  case "$arch" in arm64|aarch64) arch=arm64;; x86_64|amd64) arch=amd64;; esac36  bin="$AGENT/dist/ip-probe-$os-$arch"37  [[ -x "$bin" ]] || die "missing $bin (run: probes.sh build)"38  log "$pid$node ($os/$arch)"39  ssh -n -o BatchMode=yes "$node" 'mkdir -p ~/ip-probe/dist ~/ip-probe/deploy/launchd ~/ip-probe/deploy/systemd'40  scp -q "$bin" "$node:~/ip-probe/dist/"41  scp -q "$AGENT/deploy/install.sh" "$node:~/ip-probe/deploy/install.sh"42  scp -q "$AGENT/deploy/launchd/io.internetpressure.probe.plist" "$node:~/ip-probe/deploy/launchd/"43  scp -q "$AGENT/deploy/systemd/ip-probe.service" "$node:~/ip-probe/deploy/systemd/"44  local pw; pw=$(sudo_pw "$node")45  if [[ -n "$pw" ]]; then46    ssh -n -o BatchMode=yes "$node" "chmod +x ~/ip-probe/deploy/install.sh; printf '%s\n' '$pw' | sudo -S -p '' bash ~/ip-probe/deploy/install.sh '$pid' '$key' '$INGEST_URL' 2>&1 | tail -6"47  else48    ssh -n -o BatchMode=yes "$node" "chmod +x ~/ip-probe/deploy/install.sh; sudo -n bash ~/ip-probe/deploy/install.sh '$pid' '$key' '$INGEST_URL' 2>&1 | tail -6"49  fi50}5152cmd="${1:-status}"; shift || true53case "$cmd" in54  build) (cd "$AGENT" && make build) ;;55  keys)  while read -r pid node; do printf '%-12s %-8s %s\n' "$pid" "$node" "$(probe_key "$pid")"; done < <(probes_nodes) ;;56  install)57    want=("$@")58    while read -r pid node; do59      if [[ ${#want[@]} -gt 0 ]] && [[ ! " ${want[*]} " =~ " $pid " ]]; then continue; fi60      key=$(probe_key "$pid")61      [[ "$key" =~ ^[0-9a-f]{64}$ ]] || { warn "no key for $pid (seed the registry first)"; continue; }62      install_one "$pid" "$node" "$key" || true63    done < <(probes_nodes)64    ;;65  status)66    while read -r pid node; do67      printf '%-12s %-8s ' "$pid" "$node"68      ssh -n -o BatchMode=yes -o ConnectTimeout=15 "$node" 'curl -s -m 3 http://127.0.0.1:9381/healthz' 2>/dev/null | head -c 200 || printf 'unreachable'69      echo70    done < <(probes_nodes)71    ;;72  *) die "unknown command $cmd" ;;73esac74