/ .devnet / start_sync_test.sh
start_sync_test.sh
 1  #!/bin/bash
 2  
 3  # Determine the number of AWS EC2 instances by checking ~/.ssh/config
 4  NODE_ID=0
 5  while [ -n "$(grep "aws-n${NODE_ID}" ~/.ssh/config)" ]; do
 6      NODE_ID=$((NODE_ID + 1))
 7  done
 8  
 9  # Read the number of AWS EC2 instances to query from the user
10  read -p "Enter the number of AWS EC2 instances to query (default: $NODE_ID): " NUM_INSTANCES
11  NUM_INSTANCES="${NUM_INSTANCES:-$NODE_ID}"
12  
13  echo "Using $NUM_INSTANCES AWS EC2 instances for querying."
14  
15  # Read the network ID from user or use a default value of 1
16  read -p "Enter the network ID (mainnet = 0, testnet = 1, canary = 2) (default: 1): " NETWORK_ID
17  NETWORK_ID=${NETWORK_ID:-1}
18  
19  echo "Using network ID $NETWORK_ID."
20  
21  # Read the verbosity level from the user (default: 1)
22  read -p "Enter the verbosity level (default: 1): " VERBOSITY
23  VERBOSITY="${VERBOSITY:-1}"
24  
25  echo "Using verbosity level $VERBOSITY."
26  
27  # Get the IP address of NODE 0 from the SSH config for aws-n0
28  NODE_0_IP=$(awk '/Host aws-n0/{f=1} f&&/HostName/{print $2; exit}' ~/.ssh/config)
29  
30  # Define a function to start snarkOS in a tmux session on a node
31  start_snarkos_in_tmux() {
32    local NODE_ID=$1
33    local NODE_IP=$2
34  
35    # SSH into the node and start snarkOS in a new tmux session
36    ssh -o StrictHostKeyChecking=no aws-n$NODE_ID << EOF
37      # Commands to run on the remote instance
38      sudo -i  # Switch to root user
39      WORKSPACE=~/snarkOS
40      cd \$WORKSPACE
41  
42      # Start snarkOS within a new tmux session named "snarkos-session"
43      tmux new-session -d -s snarkos-session
44  
45      # Send the snarkOS start command to the tmux session with the NODE_ID
46      tmux send-keys -t "snarkos-session" "snarkos start --client --nocdn --nodisplay --rest 0.0.0.0:3030 --node 0.0.0.0:4130 --verbosity 4 --network $NETWORK_ID --metrics --logfile "/tmp/snarkos-syncing-range-3.log" --peers 167.71.249.65:4130,157.245.218.195:4130,167.71.249.55:4130" C-m
47  
48      exit  # Exit root user
49  EOF
50  
51    # Check the exit status of the SSH command
52    if [ $? -eq 0 ]; then
53      echo "snarkOS started successfully in a tmux session on aws-n$NODE_ID."
54    else
55      echo "Failed to start snarkOS in a tmux session on aws-n$NODE_ID."
56    fi
57  }
58  
59  # Loop through aws-n nodes and start snarkOS in tmux sessions in parallel
60  for NODE_ID in $(seq 0 $(($NUM_INSTANCES - 1))); do
61    start_snarkos_in_tmux $NODE_ID "$NODE_0_IP" &
62  done
63  
64  # Wait for all background jobs to finish
65  wait