|
| 1 | +#!/bin/bash |
| 2 | +# Build patched crucible-nbd-server with --address support on proper-raptor |
| 3 | +# |
| 4 | +# This patches the NBD server to support a custom listen address, required |
| 5 | +# for per-VM volumes where each VM needs its own NBD port. |
| 6 | +# |
| 7 | +# After building, the binary is copied to /home/ubuntu/crucible-nbd-server |
| 8 | +# |
| 9 | +set -e |
| 10 | + |
| 11 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 12 | +CRUCIBLE_IP="192.168.4.189" |
| 13 | +CRUCIBLE_HOST="ubuntu@${CRUCIBLE_IP}" |
| 14 | + |
| 15 | +echo "=== Building Patched crucible-nbd-server ===" |
| 16 | +echo "" |
| 17 | + |
| 18 | +# Check SSH access |
| 19 | +if ! ssh -o ConnectTimeout=5 -o BatchMode=yes "$CRUCIBLE_HOST" "echo 'SSH OK'" 2>/dev/null; then |
| 20 | + echo "ERROR: Cannot SSH to $CRUCIBLE_HOST" |
| 21 | + exit 1 |
| 22 | +fi |
| 23 | + |
| 24 | +# Check if Crucible source exists |
| 25 | +if ! ssh "$CRUCIBLE_HOST" "test -d /home/ubuntu/crucible"; then |
| 26 | + echo "ERROR: Crucible source not found at /home/ubuntu/crucible" |
| 27 | + echo "Clone it first: git clone https://github.com/oxidecomputer/crucible" |
| 28 | + exit 1 |
| 29 | +fi |
| 30 | + |
| 31 | +# Apply the patch |
| 32 | +echo "Applying --address patch to nbd_server/src/main.rs..." |
| 33 | + |
| 34 | +ssh "$CRUCIBLE_HOST" "cat > /tmp/patch-nbd-server.sh" << 'REMOTE_SCRIPT' |
| 35 | +#!/bin/bash |
| 36 | +set -e |
| 37 | +
|
| 38 | +cd /home/ubuntu/crucible |
| 39 | +
|
| 40 | +# Check if already patched |
| 41 | +if grep -q '"127.0.0.1:10809"' nbd_server/src/main.rs && \ |
| 42 | + grep -q 'opt.address' nbd_server/src/main.rs; then |
| 43 | + echo "Already patched (opt.address found)" |
| 44 | +else |
| 45 | + echo "Applying patch..." |
| 46 | +
|
| 47 | + # Backup original |
| 48 | + cp nbd_server/src/main.rs nbd_server/src/main.rs.bak |
| 49 | +
|
| 50 | + # Add --address argument to Opt struct (after target) |
| 51 | + # Find the target line and add address after it |
| 52 | + sed -i '/target: Vec<SocketAddr>,/a\ |
| 53 | +\ |
| 54 | + /// Address to bind the NBD server (default: 127.0.0.1:10809)\ |
| 55 | + #[clap(short = '\''a'\'', long, default_value = "127.0.0.1:10809")]\ |
| 56 | + address: String,' nbd_server/src/main.rs |
| 57 | +
|
| 58 | + # Replace hardcoded bind address with opt.address |
| 59 | + # The original line is: let listener = TcpListener::bind("127.0.0.1:10809").await?; |
| 60 | + sed -i 's/TcpListener::bind("127.0.0.1:10809")/TcpListener::bind(\&opt.address)/' nbd_server/src/main.rs |
| 61 | +
|
| 62 | + echo "Patch applied" |
| 63 | +fi |
| 64 | +
|
| 65 | +# Verify changes |
| 66 | +echo "" |
| 67 | +echo "Verifying patch..." |
| 68 | +if grep -q 'address: String' nbd_server/src/main.rs && \ |
| 69 | + grep -q 'bind(&opt.address)' nbd_server/src/main.rs; then |
| 70 | + echo "Patch verified OK" |
| 71 | +else |
| 72 | + echo "ERROR: Patch verification failed" |
| 73 | + echo "Restoring backup..." |
| 74 | + mv nbd_server/src/main.rs.bak nbd_server/src/main.rs |
| 75 | + exit 1 |
| 76 | +fi |
| 77 | +REMOTE_SCRIPT |
| 78 | + |
| 79 | +ssh "$CRUCIBLE_HOST" "chmod +x /tmp/patch-nbd-server.sh && /tmp/patch-nbd-server.sh" |
| 80 | + |
| 81 | +# Build |
| 82 | +echo "" |
| 83 | +echo "Building crucible-nbd-server (this may take a while)..." |
| 84 | +ssh "$CRUCIBLE_HOST" "cd /home/ubuntu/crucible && cargo build --release -p nbd_server 2>&1" | tail -20 |
| 85 | + |
| 86 | +# Copy to home directory |
| 87 | +echo "" |
| 88 | +echo "Copying binary to /home/ubuntu/crucible-nbd-server..." |
| 89 | +ssh "$CRUCIBLE_HOST" "cp /home/ubuntu/crucible/target/release/crucible-nbd-server /home/ubuntu/" |
| 90 | + |
| 91 | +# Verify |
| 92 | +echo "" |
| 93 | +echo "Verifying build..." |
| 94 | +VERSION=$(ssh "$CRUCIBLE_HOST" "/home/ubuntu/crucible-nbd-server --help 2>&1 | head -5" || true) |
| 95 | +echo "$VERSION" |
| 96 | + |
| 97 | +if echo "$VERSION" | grep -q "address"; then |
| 98 | + echo "" |
| 99 | + echo "=== Build Successful ===" |
| 100 | + echo "Binary at: /home/ubuntu/crucible-nbd-server" |
| 101 | + echo "" |
| 102 | + echo "New flag: --address <IP:PORT> (default: 127.0.0.1:10809)" |
| 103 | + echo "" |
| 104 | + echo "Next step: Run deploy-ha-storage.sh to deploy to Proxmox hosts" |
| 105 | +else |
| 106 | + echo "" |
| 107 | + echo "WARNING: --address flag not found in help output" |
| 108 | + echo "Build may have failed or patch not applied correctly" |
| 109 | +fi |
0 commit comments