2018-06-26 22:56:29 -07:00
#!/bin/bash
2018-06-27 11:19:09 -07:00
ip_addr_file = $1
2018-06-26 22:56:29 -07:00
remote_user = $2
ssh_keys = $3
2018-06-27 11:19:09 -07:00
usage( ) {
2018-06-27 11:39:23 -07:00
echo -e " \\tUsage: $0 <IP Address array> <username> [path to ssh keys]\\n "
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"
2018-06-27 11:19:09 -07:00
}
2018-06-27 07:07:08 -07:00
2018-06-27 11:19:09 -07:00
# 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
2018-06-27 11:49:43 -07:00
ip_addr_array = ( )
2018-06-27 11:19:09 -07:00
# Get IP address array
2018-06-27 11:39:23 -07:00
# shellcheck source=/dev/null
2018-06-27 11:19:09 -07:00
source " $ip_addr_file "
2018-06-27 11:39:23 -07:00
# shellcheck disable=SC2089,SC2016
2018-06-27 07:07:08 -07:00
ssh_command_prefix = 'export PATH="$HOME/.cargo/bin:$PATH"; cd solana; USE_INSTALL=1 ./multinode-demo/'
2018-06-26 22:56:29 -07:00
count = 0
leader =
2018-06-27 07:07:08 -07:00
for ip_addr in " ${ ip_addr_array [@] } " ; do
echo " $ip_addr "
2018-06-27 11:19:09 -07:00
# Deploy build and scripts to remote node
2018-06-27 07:07:08 -07:00
rsync -r -av ~/.cargo/bin " $remote_user " @" $ip_addr " :~/.cargo
rsync -r -av ./multinode-demo " $remote_user " @" $ip_addr " :~/solana/
2018-06-26 22:56:29 -07:00
2018-06-27 11:19:09 -07:00
# If provided, deploy SSH keys
2018-06-27 07:07:08 -07:00
if [ [ -z $ssh_keys ] ] ; then
echo "skip copying the ssh keys"
2018-06-26 22:56:29 -07:00
else
2018-06-27 11:19:09 -07:00
rsync -r -av " $ssh_keys " /* " $remote_user " @" $ip_addr " :~/.ssh/
2018-06-26 22:56:29 -07:00
fi
2018-06-27 11:49:43 -07:00
# Stop current nodes
ssh " $remote_user " @" $ip_addr " 'pkill -9 solana-fullnode'
ssh " $remote_user " @" $ip_addr " 'pkill -9 solana-client-demo'
2018-06-27 11:19:09 -07:00
# Run setup
ssh " $remote_user " @" $ip_addr " " $ssh_command_prefix " 'setup.sh -p "$ip_addr"'
2018-06-26 22:56:29 -07:00
2018-06-27 11:19:09 -07:00
if ( ( !count ) ) ; then
2018-06-26 22:56:29 -07:00
# Start the leader on the first node
2018-06-27 07:07:08 -07:00
echo " Starting leader node $ip_addr "
2018-06-27 11:19:09 -07:00
ssh -n -f " $remote_user " @" $ip_addr " " $ssh_command_prefix " 'leader.sh > leader.log 2>&1'
2018-06-27 07:07:08 -07:00
leader = ${ ip_addr_array [0] }
2018-06-26 22:56:29 -07:00
else
# Start validator on all other nodes
2018-06-27 07:07:08 -07:00
echo " Starting validator node $ip_addr "
2018-06-27 11:39:23 -07:00
ssh -n -f " $remote_user " @" $ip_addr " " $ssh_command_prefix " " validator.sh $remote_user @ $leader :~/solana $leader > validator.log 2>&1 "
2018-06-26 22:56:29 -07:00
fi
( ( count++ ) )
2018-06-27 11:19:09 -07:00
if ( ( count = = ${# ip_addr_array [@] } ) ) ; then
2018-06-26 22:56:29 -07:00
# Launch client demo on the last node
2018-06-27 07:07:08 -07:00
echo " Starting client demo on $ip_addr "
2018-06-27 11:39:23 -07:00
ssh -n -f " $remote_user " @" $ip_addr " " $ssh_command_prefix " " client.sh $remote_user @ $leader :~/solana $count > client.log 2>&1 "
2018-06-26 22:56:29 -07:00
fi
done