From 9365a47d425720dec42260bed5f294349379ec74 Mon Sep 17 00:00:00 2001 From: Michael Vines Date: Tue, 4 Sep 2018 08:34:39 -0700 Subject: [PATCH] Employ a startup script --- net/gce.sh | 24 +++--------------------- net/net.sh | 1 + net/remote/remote_startup.sh | 11 +++++++++++ scripts/gcloud.sh | 24 ++++++++++++++++-------- 4 files changed, 31 insertions(+), 29 deletions(-) create mode 100644 net/remote/remote_startup.sh diff --git a/net/gce.sh b/net/gce.sh index 4a8bb9065f..a564a20750 100755 --- a/net/gce.sh +++ b/net/gce.sh @@ -123,21 +123,6 @@ prepareInstancesAndWriteConfigFile() { fi } - prepareInstance() { - declare name="$1" - declare publicIp="$3" - - # TODO: Make the following a requirement of $imageName - # instead of a manual install - ssh "${sshOptions[@]}" "$publicIp" " - set -ex; - sudo systemctl disable apt-daily.service # disable run when system boot - sudo systemctl disable apt-daily.timer # disable timer run - sudo apt-get --assume-yes install rsync libssl-dev; - mkdir -p ~/solana ~/.cargo/bin; - " - } - gcloud_FindInstances "name=$prefix-leader" show [[ ${#instances[@]} -eq 1 ]] || { echo "Unable to start leader" @@ -152,7 +137,6 @@ prepareInstancesAndWriteConfigFile() { echo "leaderIp=()" >> "$configFile" gcloud_ForEachInstance recordInstanceIp leaderIp - gcloud_ForEachInstance prepareInstance gcloud_FindInstances "name~^$prefix-validator" show [[ ${#instances[@]} -gt 0 ]] || { @@ -162,14 +146,12 @@ prepareInstancesAndWriteConfigFile() { echo "validatorIpList=()" >> "$configFile" gcloud_PrepInstancesForSsh "$gcloud_username" "$sshPrivateKey" gcloud_ForEachInstance recordInstanceIp validatorIpList - gcloud_ForEachInstance prepareInstance echo "clientIpList=()" >> "$configFile" gcloud_FindInstances "name~^$prefix-client" show if [[ ${#instances[@]} -gt 0 ]]; then gcloud_PrepInstancesForSsh "$gcloud_username" "$sshPrivateKey" gcloud_ForEachInstance recordInstanceIp clientIpList - gcloud_ForEachInstance prepareInstance fi echo "Wrote $configFile" @@ -196,12 +178,12 @@ create) echo ================================================================== echo gcloud_CreateInstances "$prefix-leader" 1 \ - "$zone" "$imageName" "$leaderMachineType" "$leaderAccelerator" + "$zone" "$imageName" "$leaderMachineType" "$leaderAccelerator" "$here/remote/remote_startup.sh" gcloud_CreateInstances "$prefix-validator" "$validatorNodeCount" \ - "$zone" "$imageName" "$validatorMachineType" "$validatorAccelerator" + "$zone" "$imageName" "$validatorMachineType" "$validatorAccelerator" "$here/remote/remote_startup.sh" if [[ -n $clientNodeCount ]]; then gcloud_CreateInstances "$prefix-client" "$clientNodeCount" \ - "$zone" "$imageName" "$clientMachineType" "$clientAccelerator" + "$zone" "$imageName" "$clientMachineType" "$clientAccelerator" "$here/remote/remote_startup.sh" fi prepareInstancesAndWriteConfigFile diff --git a/net/net.sh b/net/net.sh index 1eae72b039..0027e63c9c 100755 --- a/net/net.sh +++ b/net/net.sh @@ -120,6 +120,7 @@ common_start_setup() { ( set -x test -d "$SOLANA_ROOT" + ssh "${sshOptions[@]}" "$ipAddress" "mkdir -p ~/solana ~/.cargo/bin" rsync -vPrz -e "ssh ${sshOptions[*]}" \ "$SOLANA_ROOT"/{fetch-perf-libs.sh,scripts,net,multinode-demo} \ "$ipAddress":~/solana/ diff --git a/net/remote/remote_startup.sh b/net/remote/remote_startup.sh new file mode 100644 index 0000000000..388f138db4 --- /dev/null +++ b/net/remote/remote_startup.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# +# Runs at boot on each instance as root +# +# TODO: Make the following a requirement of the Instance image +# instead of a manual install? + +systemctl disable apt-daily.service # disable run when system boot +systemctl disable apt-daily.timer # disable timer run +apt-get --assume-yes install rsync libssl-dev + diff --git a/scripts/gcloud.sh b/scripts/gcloud.sh index 1efb0c20da..ceb5eae787 100644 --- a/scripts/gcloud.sh +++ b/scripts/gcloud.sh @@ -75,17 +75,18 @@ gcloud_ForEachInstance() { } # -# gcloud_CreateInstances [namePrefix] [numNodes] [zone] [imageName] [machineType] [accelerator] +# gcloud_CreateInstances [namePrefix] [numNodes] [zone] [imageName] [machineType] [accelerator] [startupScript] # # Creates one more identical instances. # -# namePrefix - unique string to prefix all the instance names with -# numNodes - number of instances to create -# zone - zone to create the instances in -# imageName - Disk image for the instances -# machineType - GCE machine type -# accelerator - Optional accelerator to attach to the instance(s), see -# eg, request 4 K80 GPUs with "count=4,type=nvidia-tesla-k80" +# namePrefix - unique string to prefix all the instance names with +# numNodes - number of instances to create +# zone - zone to create the instances in +# imageName - Disk image for the instances +# machineType - GCE machine type +# accelerator - Optional accelerator to attach to the instance(s), see +# eg, request 4 K80 GPUs with "count=4,type=nvidia-tesla-k80" +# startupScript - Optional startup script to execute when the instance boots # # Tip: use gcloud_FindInstances to locate the instances once this function # returns @@ -96,6 +97,7 @@ gcloud_CreateInstances() { declare imageName="$4" declare machineType="$5" declare optionalAccelerator="$6" + declare optionalStartupScript="$7" declare nodes if [[ $numNodes = 1 ]]; then @@ -119,6 +121,12 @@ gcloud_CreateInstances() { ) fi + if [[ -n $optionalStartupScript ]]; then + args+=( + --metadata-from-file "startup-script=$optionalStartupScript" + ) + fi + ( set -x gcloud beta compute instances create "${nodes[@]}" "${args[@]}"