-
Notifications
You must be signed in to change notification settings - Fork 28
/
deploy_monitoring_gcp.sh
65 lines (54 loc) · 2.89 KB
/
deploy_monitoring_gcp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
if [[ "$#" -lt 1 ]]; then
printf "Usage: bash deploy_monitoring_gcp.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [--setup]\n"
printf "Example: bash deploy_monitoring_gcp.sh dev --setup\n"
printf "Example: bash deploy_monitoring_gcp.sh dev\n"
printf "\n"
exit
fi
printf "\n[[[[[ deploy_monitoring_gcp.sh ]]]]]\n\n"
if [[ "$1" = 'dev' ]] || [[ "$1" = 'staging' ]] || [[ "$1" = 'sandbox' ]] || [[ "$1" = 'exp' ]] || [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]] || [[ "$1" = 'mainnet' ]]; then
SEASON="$1"
if [[ "$1" = 'mainnet' ]]; then
PROJECT_ID="mainnet-prod-ground"
elif [[ "$1" = 'spring' ]] || [[ "$1" = 'summer' ]]; then
PROJECT_ID="testnet-prod-ground"
else
PROJECT_ID="testnet-$1-ground"
fi
else
printf "Invalid project/season argument: $1\n"
exit
fi
printf "SEASON=$SEASON\n"
printf "PROJECT_ID=$PROJECT_ID\n"
GCP_USER="runner"
printf "GCP_USER=$GCP_USER\n"
OPTIONS="$2"
printf "OPTIONS=$OPTIONS\n"
# Get confirmation.
printf "\n"
read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r
printf "\n\n"
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
[[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell
fi
FILES_FOR_MONITORING="monitoring/ setup_monitoring_gcp.sh setup_monitoring_ubuntu.sh start_monitoring_gcp.sh"
MONITORING_TARGET_ADDR="${GCP_USER}@${SEASON}-monitoring-taiwan"
MONITORING_ZONE="asia-east1-b"
# kill any processes still alive
gcloud compute ssh $MONITORING_TARGET_ADDR --command "sudo killall prometheus" --project $PROJECT_ID --zone $MONITORING_ZONE
gcloud compute ssh $MONITORING_TARGET_ADDR --command "sudo killall grafana-server" --project $PROJECT_ID --zone $MONITORING_ZONE
# deploy files to GCP instances
printf "\nDeploying monitoring..."
printf "\nDeploying files to ${MONITORING_TARGET_ADDR}..."
gcloud compute ssh ${MONITORING_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $MONITORING_ZONE
gcloud compute scp --recurse $FILES_FOR_MONITORING ${MONITORING_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $MONITORING_ZONE
# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME)
if [[ $OPTIONS = "--setup" ]]; then
printf "\n\n##########################\n# Setting up monitoring #\n###########################\n\n"
gcloud compute ssh $MONITORING_TARGET_ADDR --command "cd ./ain-blockchain; . setup_monitoring_ubuntu.sh" --project $PROJECT_ID
fi
# ssh into each instance, install packages and start up the server
printf "\n\n############################\n# Running monitoring #\n############################\n\n"
gcloud compute ssh $MONITORING_TARGET_ADDR --command "cd ./ain-blockchain; . setup_monitoring_gcp.sh $SEASON $GCP_USER && . start_monitoring_gcp.sh" --project $PROJECT_ID --zone $MONITORING_ZONE