#!/usr/bin/env bash # Runs as root on node0 (primary). Configures Cassandra on all nodes, # seeds data, then injects fault: brings down enp6s0f1 on node1. set -euo pipefail CLUSTER_NIC="enp6s0f1" SSH_OPTS="-o StrictHostKeyChecking=no -o ConnectTimeout=15 -o BatchMode=yes" # shellcheck source=/opt/syscraft/cloudlab-cluster-info.sh source /opt/syscraft/cloudlab-cluster-info.sh 2>/dev/null || true NODE0_IP="${NODE0_IP:-$(syscraft_node_cluster_ip node0)}" NODE1_IP="${NODE1_IP:-$(syscraft_node_cluster_ip node1)}" NODE2_IP="${NODE2_IP:-$(syscraft_node_cluster_ip node2)}" NODE0_IP="${NODE0_IP:-10.10.1.1}" NODE1_IP="${NODE1_IP:-10.10.1.2}" NODE2_IP="${NODE2_IP:-10.10.1.3}" NODE1_HOST="${NODE1_HOST:-$(syscraft_node_host node1)}" NODE2_HOST="${NODE2_HOST:-$(syscraft_node_host node2)}" if [ -z "$NODE1_HOST" ] || [ -z "$NODE2_HOST" ]; then echo "ERROR: node1/node2 hosts not found in /etc/syscraft/cluster-info" >&2 exit 1 fi # Syscraft connects as root; use root SSH for inter-node calls. remote() { local host="$1"; shift ssh $SSH_OPTS "root@$host" "$@" } ensure_cassandra_ready() { local host="$1" remote "$host" bash -s <<'SCRIPT' set -euo pipefail need_install=0 if ! command -v cassandra >/dev/null 2>&1; then need_install=1 fi if [ ! -f /etc/cassandra/cassandra.yaml ]; then need_install=1 fi python3 - <<'PY' >/dev/null 2>&1 || need_install=1 import yaml PY if [ "$need_install" -eq 1 ]; then export DEBIAN_FRONTEND=noninteractive apt-get update -q apt-get install -y -q openjdk-11-jdk-headless curl gnupg python3-yaml python3-pip if [ ! -f /etc/apt/sources.list.d/cassandra.list ]; then curl -fsSL https://downloads.apache.org/cassandra/KEYS | gpg --dearmor -o /usr/share/keyrings/cassandra-archive.gpg 2>/dev/null echo "deb [signed-by=/usr/share/keyrings/cassandra-archive.gpg] https://debian.cassandra.apache.org 41x main" > /etc/apt/sources.list.d/cassandra.list apt-get update -q fi apt-get install -y -q --reinstall -o Dpkg::Options::="--force-confmiss" cassandra pip3 install cqlsh --break-system-packages 2>/dev/null || true systemctl disable cassandra systemctl stop cassandra || true fi test -f /etc/cassandra/cassandra.yaml python3 - <<'PY' import yaml PY SCRIPT } configure_node() { local host="$1" local listen_ip="$2" remote "$host" bash -s <