Run gcloud_PrepInstancesForSsh in parallel
This commit is contained in:
parent
9365a47d42
commit
2cb1375217
|
@ -123,6 +123,7 @@ prepareInstancesAndWriteConfigFile() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
echo "Looking for leader instance..."
|
||||||
gcloud_FindInstances "name=$prefix-leader" show
|
gcloud_FindInstances "name=$prefix-leader" show
|
||||||
[[ ${#instances[@]} -eq 1 ]] || {
|
[[ ${#instances[@]} -eq 1 ]] || {
|
||||||
echo "Unable to start leader"
|
echo "Unable to start leader"
|
||||||
|
@ -138,6 +139,7 @@ prepareInstancesAndWriteConfigFile() {
|
||||||
echo "leaderIp=()" >> "$configFile"
|
echo "leaderIp=()" >> "$configFile"
|
||||||
gcloud_ForEachInstance recordInstanceIp leaderIp
|
gcloud_ForEachInstance recordInstanceIp leaderIp
|
||||||
|
|
||||||
|
echo "Looking for validator instances..."
|
||||||
gcloud_FindInstances "name~^$prefix-validator" show
|
gcloud_FindInstances "name~^$prefix-validator" show
|
||||||
[[ ${#instances[@]} -gt 0 ]] || {
|
[[ ${#instances[@]} -gt 0 ]] || {
|
||||||
echo "Unable to start validators"
|
echo "Unable to start validators"
|
||||||
|
@ -148,6 +150,7 @@ prepareInstancesAndWriteConfigFile() {
|
||||||
gcloud_ForEachInstance recordInstanceIp validatorIpList
|
gcloud_ForEachInstance recordInstanceIp validatorIpList
|
||||||
|
|
||||||
echo "clientIpList=()" >> "$configFile"
|
echo "clientIpList=()" >> "$configFile"
|
||||||
|
echo "Looking for client instances..."
|
||||||
gcloud_FindInstances "name~^$prefix-client" show
|
gcloud_FindInstances "name~^$prefix-client" show
|
||||||
if [[ ${#instances[@]} -gt 0 ]]; then
|
if [[ ${#instances[@]} -gt 0 ]]; then
|
||||||
gcloud_PrepInstancesForSsh "$gcloud_username" "$sshPrivateKey"
|
gcloud_PrepInstancesForSsh "$gcloud_username" "$sshPrivateKey"
|
||||||
|
|
|
@ -202,7 +202,7 @@ gcloud_FigureRemoteUsername() {
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# gcloud_PrepInstancesForSsh [username] [publicKey] [privateKey]
|
# gcloud_PrepInstancesForSsh [username] [privateKey]
|
||||||
#
|
#
|
||||||
# Prepares all the instances in the `instances` array for ssh with the specified
|
# Prepares all the instances in the `instances` array for ssh with the specified
|
||||||
# keypair. This eliminates the need to use the restrictive |gcloud compute ssh|,
|
# keypair. This eliminates the need to use the restrictive |gcloud compute ssh|,
|
||||||
|
@ -215,6 +215,11 @@ gcloud_PrepInstancesForSsh() {
|
||||||
declare username="$1"
|
declare username="$1"
|
||||||
declare privateKey="$2"
|
declare privateKey="$2"
|
||||||
declare publicKey="$privateKey".pub
|
declare publicKey="$privateKey".pub
|
||||||
|
declare logDir=log/
|
||||||
|
|
||||||
|
mkdir -p $logDir
|
||||||
|
rm -rf $logDir/gcloud_PrepInstancesForSsh-*
|
||||||
|
|
||||||
[[ -r $publicKey ]] || {
|
[[ -r $publicKey ]] || {
|
||||||
echo "Unable to read public key: $publicKey"
|
echo "Unable to read public key: $publicKey"
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -225,9 +230,17 @@ gcloud_PrepInstancesForSsh() {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[ -d $logDir ]] || {
|
||||||
|
echo "logDir does not exist: $logDir"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
declare -a pids
|
||||||
for instanceInfo in "${instances[@]}"; do
|
for instanceInfo in "${instances[@]}"; do
|
||||||
declare name zone publicIp
|
declare name zone publicIp
|
||||||
IFS=: read -r name zone publicIp _ < <(echo "$instanceInfo")
|
IFS=: read -r name zone publicIp _ < <(echo "$instanceInfo")
|
||||||
|
|
||||||
|
logFile="$logDir/gcloud_PrepInstancesForSsh-$name.log"
|
||||||
(
|
(
|
||||||
set -x
|
set -x
|
||||||
|
|
||||||
|
@ -247,13 +260,26 @@ gcloud_PrepInstancesForSsh() {
|
||||||
StrictHostKeyChecking no
|
StrictHostKeyChecking no
|
||||||
\" > .ssh/config;
|
\" > .ssh/config;
|
||||||
"
|
"
|
||||||
#gcloud compute scp --zone "$zone" "$publicKey" "$name":.ssh/authorized_keys
|
|
||||||
scp \
|
scp \
|
||||||
-o StrictHostKeyChecking=no \
|
-o StrictHostKeyChecking=no \
|
||||||
-o UserKnownHostsFile=/dev/null \
|
-o UserKnownHostsFile=/dev/null \
|
||||||
-i "$privateKey" \
|
-i "$privateKey" \
|
||||||
"$privateKey" "$username@$publicIp:.ssh/id_testnet"
|
"$privateKey" "$username@$publicIp:.ssh/id_testnet"
|
||||||
)
|
) > "$logFile" 2>&1 &
|
||||||
|
declare pid=$!
|
||||||
|
|
||||||
|
ln -sfT "$logFile" "$logDir/gcloud_PrepInstancesForSsh-$pid.log"
|
||||||
|
pids+=("$pid")
|
||||||
|
done
|
||||||
|
|
||||||
|
for pid in "${pids[@]}"; do
|
||||||
|
declare ok=true
|
||||||
|
wait "$pid" || ok=false
|
||||||
|
if ! $ok; then
|
||||||
|
cat "$logDir/gcloud_PrepInstancesForSsh-$pid.log"
|
||||||
|
echo ^^^ +++
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue