#!/bin/sh set -eu umask 077 mkdir -p /tmp/live/output cleanup() { if [ -n "${eval_pid:-}" ]; then kill -TERM "$eval_pid" 2>/dev/null || true; wait "$eval_pid" 2>/dev/null || true; fi if [ -n "${guard:-}" ]; then kill -TERM "$guard" 2>/dev/null || true; wait "$guard" 2>/dev/null || true; fi if [ -d /tmp/live/index ]; then node /tmp/live/index-snapshot.mjs || echo "index snapshot failed" >&2; fi du -sb /tmp/live/events /tmp/live/pg /tmp/live >> /tmp/live/output/disk.txt 2>/dev/null || true dmesg | tail -60 > /tmp/live/output/kernel-tail.txt 2>/dev/null || true tar -czf /tmp/live-results.tar.gz -C /tmp/live output } trap cleanup EXIT trap 'exit 130' INT trap 'exit 143' TERM export DEBIAN_FRONTEND=noninteractive printf '#!/bin/sh\nexit 101\n' > /usr/sbin/policy-rc.d chmod 0755 /usr/sbin/policy-rc.d apt-get update -qq > /tmp/live/output/install.log 2>&1 if [ "${2:-fixed}" = references ]; then apt-get install -y -qq --no-install-recommends ca-certificates procps >> /tmp/live/output/install.log 2>&1 gzip -dc /tmp/live/relay-eval.gz > /tmp/live/relay-eval chmod 0755 /tmp/live/relay-eval relays=bsky.network,relay.waow.tech if [ "${5:-none}" != none ]; then relays="$relays,$5"; fi cat /proc/stat > /tmp/live/output/machine-cpu-before.txt timeout -k 5 "$(( ${1:-45} + 30 ))" /tmp/live/relay-eval eval --relays "$relays" --window "${1:-45}" --classify-limit 0 --db /tmp/live/output/eval.db --observations /tmp/live/output/eval-observations.json > /tmp/live/output/eval.log 2>&1 cat /proc/stat > /tmp/live/output/machine-cpu-after.txt exit 0 fi gzip -dc /tmp/live/zlay.gz > /tmp/live/zlay chmod 0755 /tmp/live/zlay apt-get install -y -qq --no-install-recommends postgresql curl ca-certificates procps >> /tmp/live/output/install.log 2>&1 npm --prefix /tmp/live install --no-audit --no-fund --ignore-scripts @atproto/lex-cbor@0.1.7 >> /tmp/live/output/install.log 2>&1 PG_BIN=$(pg_config --bindir) install -d -o postgres -g postgres /tmp/live/pg runuser -u postgres -- "$PG_BIN/initdb" -D /tmp/live/pg --auth-local=trust --auth-host=trust > /tmp/live/output/pg-init.log 2>&1 runuser -u postgres -- "$PG_BIN/pg_ctl" -D /tmp/live/pg -l /tmp/live/pg/server.log -o '-c listen_addresses=127.0.0.1 -c shared_buffers=32MB -c max_connections=40' -w start "$PG_BIN/createdb" -h 127.0.0.1 -U postgres relay export DATABASE_URL=postgres://postgres@127.0.0.1:5432/relay export RELAY_REPLAY_HISTORY=false RELAY_UPSTREAM=bsky.network RELAY_INDEX_PROFILE=bounded export ZKV_TABLE_ENCODING="${3:-legacy}" export RELAY_INDEX_SYNC=true export COLLECTION_INDEX_DIR=/tmp/live/index export RELAY_DATA_DIR=/tmp/live/events FRAME_WORKERS=16 DB_POOL_SIZE=20 uname -a > /tmp/live/output/environment.txt node --version >> /tmp/live/output/environment.txt "$PG_BIN/postgres" --version >> /tmp/live/output/environment.txt ldd /tmp/live/zlay >> /tmp/live/output/environment.txt getconf CLK_TCK >> /tmp/live/output/environment.txt cat /proc/meminfo >> /tmp/live/output/environment.txt cat /proc/cpuinfo >> /tmp/live/output/environment.txt relay_limit=$(( ${1:-45} + 180 )) if [ "${2:-fixed}" = steady ]; then relay_limit=1800; fi relay_limit=$(( relay_limit + ${5:-0} )) timeout -s TERM -k 5 "$relay_limit" /tmp/live/zlay > /tmp/live/output/relay.log 2>&1 & guard=$! for attempt in $(seq 1 45); do if curl -fsS --max-time 2 http://127.0.0.1:3001/_healthz > /dev/null; then break; fi if ! kill -0 "$guard" 2>/dev/null; then echo 'relay exited before readiness'; exit 1; fi sleep 1 done if [ "${1:-45}" -ge 600 ]; then for attempt in $(seq 1 120); do if grep -qE 'startup complete: [1-9][0-9]* host' /tmp/live/output/relay.log; then break; fi if ! kill -0 "$guard" 2>/dev/null; then exit 1; fi sleep 1 done grep -E 'startup complete: [1-9][0-9]* host' /tmp/live/output/relay.log > /tmp/live/output/bootstrap.txt fi pid=$(pgrep -x zlay | head -1) if [ -f /tmp/live/relay-eval.gz ]; then gzip -dc /tmp/live/relay-eval.gz > /tmp/live/relay-eval chmod 0755 /tmp/live/relay-eval timeout -k 5 "$(( ${1:-45} + 45 ))" /tmp/live/relay-eval eval --relays ws://127.0.0.1:3000,bsky.network,relay.waow.tech --window "${1:-45}" --classify-limit 0 --db /tmp/live/output/eval.db --observations /tmp/live/output/eval-observations.json > /tmp/live/output/eval.log 2>&1 & eval_pid=$! fi node /tmp/live/observer.mjs "$pid" "${1:-45}" "${2:-fixed}" "${4:-}" if [ -n "${eval_pid:-}" ]; then wait "$eval_pid" eval_pid= fi if [ "${5:-0}" -gt 0 ]; then for attempt in $(seq 1 "$5"); do if [ -f /tmp/live/evaluation-done ]; then break; fi sleep 1 done fi