Employ a startup script

This commit is contained in:
Michael Vines 2018-09-04 08:34:39 -07:00
parent 6ffe205447
commit 9365a47d42
4 changed files with 31 additions and 29 deletions

View File

@ -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

View File

@ -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/

View File

@ -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

View File

@ -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[@]}"