Address review comments

This commit is contained in:
Pankaj Garg
2018-06-27 11:19:09 -07:00
committed by Greg Fitzgerald
parent f8352bac2f
commit 9ffc50bead

View File

@ -1,13 +1,37 @@
#!/bin/bash #!/bin/bash
nodes_file=$1 ip_addr_file=$1
remote_user=$2 remote_user=$2
ssh_keys=$3 ssh_keys=$3
oldIFS="$IFS" usage() {
IFS=$'\n' ip_addr_array=($(<$nodes_file)) echo -e "\tUsage: $0 <IP Address array> <username> [path to ssh keys]\n"
IFS="$oldIFS" echo -e "\t <IP Address array>: A bash script that exports an array of IP addresses, ip_addr_array. Elements of the array are public IP address of remote nodes."
echo -e "\t <username>: The username for logging into remote nodes."
echo -e "\t [path to ssh keys]: The public/private key pair that remote nodes can use to perform rsync and ssh among themselves. Must contain pub, priv and authorized_keys.\n"
}
# Sample IP Address array file contents
# ip_addr_array=(192.168.1.1 192.168.1.5 192.168.2.2)
if [[ -z "$ip_addr_file" ]]; then
usage
exit 1
fi
if [[ -z "$remote_user" ]]; then
usage
exit 1
fi
# Build and install locally
PATH="$HOME"/.cargo/bin:"$PATH"
cargo install --force
# Get IP address array
source "$ip_addr_file"
# shellcheck disable=SC2089
ssh_command_prefix='export PATH="$HOME/.cargo/bin:$PATH"; cd solana; USE_INSTALL=1 ./multinode-demo/' ssh_command_prefix='export PATH="$HOME/.cargo/bin:$PATH"; cd solana; USE_INSTALL=1 ./multinode-demo/'
count=0 count=0
@ -15,34 +39,37 @@ leader=
for ip_addr in "${ip_addr_array[@]}"; do for ip_addr in "${ip_addr_array[@]}"; do
echo "$ip_addr" echo "$ip_addr"
# Deploy build and scripts to remote node
rsync -r -av ~/.cargo/bin "$remote_user"@"$ip_addr":~/.cargo rsync -r -av ~/.cargo/bin "$remote_user"@"$ip_addr":~/.cargo
rsync -r -av ./multinode-demo "$remote_user"@"$ip_addr":~/solana/ rsync -r -av ./multinode-demo "$remote_user"@"$ip_addr":~/solana/
# If provided, deploy SSH keys
if [[ -z $ssh_keys ]]; then if [[ -z $ssh_keys ]]; then
echo "skip copying the ssh keys" echo "skip copying the ssh keys"
else else
echo "rsync -r -av $ssh_keys/* $remote_user@$ip_addr:~/.ssh/" rsync -r -av "$ssh_keys"/* "$remote_user"@"$ip_addr":~/.ssh/
fi fi
ssh "$remote_user"@"$ip_addr" $ssh_command_prefix'setup.sh' # Run setup
ssh "$remote_user"@"$ip_addr" "$ssh_command_prefix"'setup.sh -p "$ip_addr"'
if [[ "$count" -eq 0 ]]; then if (( !count )); then
# Start the leader on the first node # Start the leader on the first node
echo "Starting leader node $ip_addr" echo "Starting leader node $ip_addr"
ssh -n -f "$remote_user"@"$ip_addr" $ssh_command_prefix'leader.sh > leader.log 2>&1' ssh -n -f "$remote_user"@"$ip_addr" "$ssh_command_prefix"'leader.sh > leader.log 2>&1'
leader=${ip_addr_array[0]} leader=${ip_addr_array[0]}
else else
# Start validator on all other nodes # Start validator on all other nodes
echo "Starting validator node $ip_addr" echo "Starting validator node $ip_addr"
ssh -n -f "$remote_user"@"$ip_addr" $ssh_command_prefix"validator.sh $remote_user@$leader:~/solana $leader > validator.log 2>&1" ssh -n -f "$remote_user"@"$ip_addr" "$ssh_command_prefix""validator.sh "$remote_user"@"$leader":~/solana "$leader" > validator.log 2>&1"
fi fi
(( count++ )) (( count++ ))
if [[ "$count" -eq ${#ip_addr_array[@]} ]]; then if (( count == ${#ip_addr_array[@]} )); then
# Launch client demo on the last node # Launch client demo on the last node
echo "Starting client demo on $ip_addr" echo "Starting client demo on $ip_addr"
ssh -n -f "$remote_user"@"$ip_addr" $ssh_command_prefix"client.sh $remote_user@$leader:~/solana $count > client.log 2>&1" ssh -n -f "$remote_user"@"$ip_addr" "$ssh_command_prefix""client.sh "$remote_user"@"$leader":~/solana "$count" > client.log 2>&1"
fi fi
done done