diff --git a/multinode-demo/gce_multinode.sh b/multinode-demo/gce_multinode.sh new file mode 100755 index 00000000000000..53fb30e4587356 --- /dev/null +++ b/multinode-demo/gce_multinode.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +command=$1 +prefix= +num_nodes= +out_file= +image_name="ubuntu-16-04-cuda-9-2-new" + +shift + +usage() { + exitcode=0 + if [[ -n "$1" ]]; then + exitcode=1 + echo "Error: $*" + fi + cat < <-p prefix> <-n num_nodes> <-o file> [-i image-name] + +Manage a GCE multinode network + + create|delete - Create or delete the network + -p prefix - A common prefix for node names, to avoid collision + -n num_nodes - Number of nodes + -o out_file - Used for create option. Outputs an array of IP addresses + of new nodes to the file + -i image_name - Existing image on GCE (default $image_name) + +EOF + exit $exitcode +} + +while getopts "h?p:i:n:o:" opt; do + case $opt in + h | \?) + usage + ;; + p) + prefix=$OPTARG + ;; + i) + image_name=$OPTARG + ;; + o) + out_file=$OPTARG + ;; + n) + num_nodes=$OPTARG + ;; + *) + usage "Error: unhandled option: $opt" + ;; + esac +done + +set -e + +[[ -n $command ]] || usage "Need a command (create|delete)" + +[[ -n $prefix ]] || usage "Need a prefix for GCE instance names" + +[[ -n $num_nodes ]] || usage "Need number of nodes" + +nodes=() +for i in $(seq 1 "$num_nodes"); do + nodes+=("$prefix$i") +done + +if [[ $command == "create" ]]; then + [[ -n $out_file ]] || usage "Need an outfile to store IP Addresses" + + ip_addr_list=$(gcloud beta compute instances create "${nodes[@]}" --zone=us-west1-b --tags=testnet \ + --image="$image_name" | awk '/RUNNING/ {print $5}') + + echo "ip_addr_array=($ip_addr_list)" >"$out_file" +elif [[ $command == "delete" ]]; then + gcloud beta compute instances delete "${nodes[@]}" +else + usage "Unknown command: $command" +fi diff --git a/multinode-demo/start_nodes.sh b/multinode-demo/start_nodes.sh index 40061712b2c0ab..5014633a2709dd 100755 --- a/multinode-demo/start_nodes.sh +++ b/multinode-demo/start_nodes.sh @@ -58,16 +58,16 @@ for ip_addr in "${ip_addr_array[@]}"; do # Deploy build and scripts to remote node ssh "$remote_user@$ip_addr" 'mkdir ~/solana' - rsync -r -av ~/.cargo/bin "$remote_user"@"$ip_addr":~/.cargo - rsync -r -av ./multinode-demo "$remote_user"@"$ip_addr":~/solana/ + rsync -vPrz ~/.cargo/bin "$remote_user"@"$ip_addr":~/.cargo + rsync -vPrz ./multinode-demo "$remote_user"@"$ip_addr":~/solana/ # If provided, deploy SSH keys if [[ -z $ssh_keys ]]; then echo "skip copying the ssh keys" else - rsync -r -av "$ssh_keys"/id_rsa "$remote_user@$ip_addr":~/.ssh/ - rsync -r -av "$ssh_keys"/id_rsa.pub "$remote_user@$ip_addr":~/.ssh/ - rsync -r -av "$ssh_keys"/id_rsa.pub "$remote_user@$ip_addr":~/.ssh/authorized_keys + rsync -vPrz "$ssh_keys"/id_rsa "$remote_user@$ip_addr":~/.ssh/ + rsync -vPrz "$ssh_keys"/id_rsa.pub "$remote_user@$ip_addr":~/.ssh/ + rsync -vPrz "$ssh_keys"/id_rsa.pub "$remote_user@$ip_addr":~/.ssh/authorized_keys ssh -n -f "$remote_user@$ip_addr" 'chmod 600 ~/.ssh/authorized_keys ~/.ssh/id_rsa' fi