Skip to content

Commit

Permalink
Update gcloud-add-replicas.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
fixone committed Oct 29, 2017
1 parent 31b21f7 commit 9bfc8e6
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions gcloud-add-replicas.sh
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
PROJECT="project-id-here"
MACHINE="n1-standard-1"
ZONE="europe-west1-d"
MACHINE="g1-small"
NODE="cass2"
SEED="cass1"
NODE="node02"

if [ $# -ge 1 ]
then
NODE=$1
NODE=$1
fi

echo "using ${NODE} as instance name"

if [ $# -ge 2 ]
then
SEED=$2
SEED=$2
else
echo "looking for a running instance that has 'cassandra-seed' label set to 'true'"
SEED=$(gcloud compute instances list --filter="labels.cassandra-seed=true" --format="value(name)")
fi

echo "using ${SEED} as seed instance name"

gcloud compute instances create $NODE --zone $ZONE --machine-type $MACHINE --network "default" --maintenance-policy "MIGRATE" --scopes default="https://www.googleapis.com/auth/devstorage.read_only","https://www.googleapis.com/auth/logging.write","https://www.googleapis.com/auth/monitoring.write","https://www.googleapis.com/auth/servicecontrol","https://www.googleapis.com/auth/service.management.readonly","https://www.googleapis.com/auth/trace.append" --image "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts" --boot-disk-size "10" --boot-disk-type "pd-standard" --boot-disk-device-name "$NODEd1" --project $PROJECT
gcloud compute instances create ${NODE} --zone ${ZONE} --machine-type ${MACHINE} --maintenance-policy "MIGRATE" --image "https://www.googleapis.com/compute/v1/projects/ubuntu-os-cloud/global/images/family/ubuntu-1604-lts" --boot-disk-size "20" --boot-disk-type "pd-standard" --boot-disk-device-name "${NODE}disk"

echo "waiting for the machine to come up"
sleep 30

gcloud compute ssh --project $PROJECT $NODE --zone $ZONE --command "wget -qO- https://raw.githubusercontent.com/academyofdata/cassandra-cluster/master/setup39.sh | bash"
gcloud compute ssh $NODE --zone $ZONE --command "wget -qO- https://raw.githubusercontent.com/academyofdata/cassandra-cluster/master/setup39.sh | bash"


IPADDR=`gcloud compute instances list --project $PROJECT --format=text $NODE | grep '^networkInterfaces\[[0-9]\+\]\.networkIP:' | sed 's/^.* //g'`
SEEDIP=`gcloud compute instances list --project $PROJECT --format=text $SEED | grep '^networkInterfaces\[[0-9]\+\]\.networkIP:' | sed 's/^.* //g'`
IPADDR=$(gcloud compute instances list --filter="name=${NODE}" --format="value(networkInterfaces[0].networkIP)")
SEEDIP=$(gcloud compute instances list --filter="name=${SEED}" --format="value(networkInterfaces[0].networkIP)")

echo "configuring cassandra after installation with $IPADDR and seed $SEEDIP"
gcloud compute ssh --project $PROJECT $NODE --zone $ZONE --command "wget -qO- https://raw.githubusercontent.com/academyofdata/cassandra-cluster/master/config-cassandra.sh | bash -s $IPADDR $SEEDIP"
gcloud compute ssh $NODE --zone $ZONE --command "wget -qO- https://raw.githubusercontent.com/academyofdata/cassandra-cluster/master/config-cassandra.sh | bash -s $IPADDR $SEEDIP"

gcloud compute instances add-labels ${NODE} --zone ${ZONE} --labels=cassandra-cluster-name=cassandra-training

0 comments on commit 9bfc8e6

Please sign in to comment.