From a6b2fd99f7d548cba82623a0508e854587d816bb Mon Sep 17 00:00:00 2001 From: platfowner Date: Tue, 23 Jul 2024 17:45:30 +0900 Subject: [PATCH 01/18] Add deploy_blockchain_genesis_onprem.sh --- deploy_blockchain_genesis_onprem.sh | 528 ++++++++++++++++++++++++++++ 1 file changed, 528 insertions(+) create mode 100644 deploy_blockchain_genesis_onprem.sh diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh new file mode 100644 index 000000000..ec2bbf0a8 --- /dev/null +++ b/deploy_blockchain_genesis_onprem.sh @@ -0,0 +1,528 @@ +#!/bin/bash + +if [[ $# -lt 4 ]] || [[ $# -gt 10 ]]; then + printf "Usage: bash deploy_blockchain_genesis_onprem.sh [dev|staging|sandbox|exp|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--kill-only|--skip-kill]\n" + printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 -1 4 --keystore --no-keep-code\n" + printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 0 0 --keystore --keep-code\n" + printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 -1 -1 --setup --keystore --no-keep-code\n" + printf "Example: bash deploy_blockchain_genesis_onprem.sh dev 0 0 0 --setup --keystore --no-keep-code\n" + printf "Note: = -1 is for tracker\n" + printf "Note: is inclusive\n" + printf "\n" + exit +fi +printf "\n[[[[[ deploy_blockchain_genesis_onprem.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" + +number_re='^[0-9]+$' +if [[ ! $2 =~ $number_re ]] ; then + printf "Invalid <# of Shards> argument: $2\n" + exit +fi +NUM_SHARDS=$2 +printf "NUM_SHARDS=$NUM_SHARDS\n" +PARENT_NODE_INDEX_BEGIN=$3 +printf "PARENT_NODE_INDEX_BEGIN=$PARENT_NODE_INDEX_BEGIN\n" +PARENT_NODE_INDEX_END=$4 +printf "PARENT_NODE_INDEX_END=$PARENT_NODE_INDEX_END\n" +printf "\n" + + +function parse_options() { + local option="$1" + if [[ $option = '--setup' ]]; then + SETUP_OPTION="$option" + elif [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keystore' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--mnemonic' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--no-chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--kill-only' ]]; then + if [[ "$KILL_OPTION" ]]; then + printf "You cannot use both --skip-kill and --kill-only\n" + exit + fi + KILL_OPTION="$option" + elif [[ $option = '--skip-kill' ]]; then + if [[ "$KILL_OPTION" ]]; then + printf "You cannot use both --skip-kill and --kill-only\n" + exit + fi + KILL_OPTION="$option" + else + printf "Invalid options: $option\n" + exit + fi +} + +# Parse options. +SETUP_OPTION="" +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" +CHOWN_DATA_OPTION="--no-chown-data" +KILL_OPTION="" + +ARG_INDEX=5 +while [ $ARG_INDEX -le $# ]; do + parse_options "${!ARG_INDEX}" + ((ARG_INDEX++)) +done +printf "SETUP_OPTION=$SETUP_OPTION\n" +printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" +printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" +printf "KILL_OPTION=$KILL_OPTION\n" + +# Json-RPC-enabled blockchain nodes +JSON_RPC_NODE_INDEX_GE=0 +JSON_RPC_NODE_INDEX_LE=4 +# Rest-Function-enabled blockchain nodes +REST_FUNC_NODE_INDEX_GE=0 +REST_FUNC_NODE_INDEX_LE=2 +# Event-Handler-enabled blockchain nodes +EVENT_HANDLER_NODE_INDEX_GE=0 +EVENT_HANDLER_NODE_INDEX_LE=4 + +printf "\n" +printf "JSON_RPC_NODE_INDEX_GE=$JSON_RPC_NODE_INDEX_GE\n" +printf "JSON_RPC_NODE_INDEX_LE=$JSON_RPC_NODE_INDEX_LE\n" +printf "REST_FUNC_NODE_INDEX_LE=$REST_FUNC_NODE_INDEX_LE\n" +printf "REST_FUNC_NODE_INDEX_GE=$REST_FUNC_NODE_INDEX_GE\n" +printf "EVENT_HANDLER_NODE_INDEX_GE=$EVENT_HANDLER_NODE_INDEX_GE\n" +printf "EVENT_HANDLER_NODE_INDEX_LE=$EVENT_HANDLER_NODE_INDEX_LE\n" + +if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then + printf "Must provide an ACCOUNT_INJECTION_OPTION\n" + exit +fi + +# Get confirmation. +if [[ "$SEASON" = "mainnet" ]]; then + printf "\n" + printf "Do you want to proceed for $SEASON? Enter [mainnet]: " + read CONFIRM + printf "\n" + if [[ ! $CONFIRM = "mainnet" ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi +elif [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then + printf "\n" + printf "Do you want to proceed for $SEASON? Enter [testnet]: " + read CONFIRM + printf "\n" + if [[ ! $CONFIRM = "testnet" ]]; then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi +else + 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 +fi + +if [[ ! $KILL_OPTION = '--kill-only' ]]; then + # Read node ip addresses + IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt + if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then + # Get keystore password + printf "Enter password: " + read -s PASSWORD + printf "\n\n" + + if [[ "$SEASON" = "mainnet" ]]; then + KEYSTORE_DIR="mainnet_prod_keys" + elif [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then + KEYSTORE_DIR="testnet_prod_keys" + else + KEYSTORE_DIR="testnet_dev_staging_keys" + fi + elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then + IFS=$'\n' read -d '' -r -a MNEMONIC_LIST < ./testnet_mnemonics/$SEASON.txt + fi +fi + +function inject_account() { + local node_index="$1" + local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then + printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "node_ip_addr='$node_ip_addr'\n" + + KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" + { + echo $KEYSTORE_FILE_PATH + sleep 1 + echo $PASSWORD + } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then + local MNEMONIC=${MNEMONIC_LIST[${node_index}]} + printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "node_ip_addr='$node_ip_addr'\n" + { + echo $MNEMONIC + sleep 1 + echo 0 + } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + else + printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "node_ip_addr='$node_ip_addr'\n" + local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" + if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then + GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" + fi + PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') + echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + fi +} + +# deploy files +FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" + +TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan" +NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan" +NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-node-1-oregon" +NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-node-2-singapore" +NODE_3_TARGET_ADDR="${GCP_USER}@${SEASON}-node-3-iowa" +NODE_4_TARGET_ADDR="${GCP_USER}@${SEASON}-node-4-netherlands" +NODE_5_TARGET_ADDR="${GCP_USER}@${SEASON}-node-5-taiwan" +NODE_6_TARGET_ADDR="${GCP_USER}@${SEASON}-node-6-oregon" +NODE_7_TARGET_ADDR="${GCP_USER}@${SEASON}-node-7-singapore" +NODE_8_TARGET_ADDR="${GCP_USER}@${SEASON}-node-8-iowa" +NODE_9_TARGET_ADDR="${GCP_USER}@${SEASON}-node-9-netherlands" + +TRACKER_ZONE="asia-east1-b" +NODE_0_ZONE="asia-east1-b" +NODE_1_ZONE="us-west1-b" +NODE_2_ZONE="asia-southeast1-b" +NODE_3_ZONE="us-central1-a" +NODE_4_ZONE="europe-west4-a" +NODE_5_ZONE="asia-east1-b" +NODE_6_ZONE="us-west1-b" +NODE_7_ZONE="asia-southeast1-b" +NODE_8_ZONE="us-central1-a" +NODE_9_ZONE="europe-west4-a" + +printf "###############################################################################\n" +printf "# Deploying parent blockchain #\n" +printf "###############################################################################\n\n" + +# deploy files to GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} + gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi +fi + +# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +if [[ $SETUP_OPTION = "--setup" ]]; then + # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi +fi + +# install node modules on GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi +fi + +if [[ $KILL_OPTION = "--skip-kill" ]]; then + printf "\nSkipping process kill...\n" +else + # kill any processes still alive + printf "\nKilling tracker / blockchain node jobs...\n" + + # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 + if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE + fi + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} + done + fi + + if [[ $NUM_SHARDS -gt 0 ]]; then + for i in $(seq $NUM_SHARDS); do + printf "shard #$i\n" + + SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" + SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" + SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" + SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" + + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE + done + fi +fi + +# If --kill-only, do not proceed any further +if [[ $KILL_OPTION = "--kill-only" ]]; then + exit +fi + +printf "\nStarting blockchain servers...\n\n" +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" +else + GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" +fi +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then + # restart after removing chains, snapshots, and log files (but keep the keys) + CHAINS_DIR=/home/ain_blockchain_data/chains + SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots + LOGS_DIR=/home/ain_blockchain_data/logs + START_TRACKER_CMD_BASE="sudo rm -rf /home/ain_blockchain_data/ && $GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" + START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +else + # restart with existing chains, snapshots, and log files + START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" + START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +fi +printf "\n" +printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" +printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" + +# Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 +if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then + printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + + printf "\n" + printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" + printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" + START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" + printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" + eval $START_TRACKER_CMD +fi + +begin_index=$PARENT_NODE_INDEX_BEGIN +if [[ $begin_index -lt 0 ]]; then + begin_index=0 +fi +if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Starting parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + + if [[ $node_index -ge $JSON_RPC_NODE_INDEX_GE ]] && [[ $node_index -le $JSON_RPC_NODE_INDEX_LE ]]; then + JSON_RPC_OPTION="--json-rpc" + else + JSON_RPC_OPTION="" + fi + UPDATE_FRONT_DB_OPTION="--update-front-db" + if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then + REST_FUNC_OPTION="--rest-func" + else + REST_FUNC_OPTION="" + fi + if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then + EVENT_HANDLER_OPTION="--event-handler" + else + EVENT_HANDLER_OPTION="" + fi + + printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" + printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" + printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" + printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" + printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" + printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" + printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" + printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" + printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" + + printf "\n" + START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON $GCP_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + sleep 5 + inject_account "$node_index" + done +fi + + +if [[ $NUM_SHARDS -gt 0 ]]; then + for shard_index in $(seq $NUM_SHARDS); do + printf "###############################################################################\n" + printf "# Deploying shard $shard_index blockchain #\n" + printf "###############################################################################\n\n" + + + # generate genesis config files in ./blockchain/shard_$shard_index + if [[ $SETUP_OPTION = "--setup" ]]; then + node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index + fi + + SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" + SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" + SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" + SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" + + # deploy files to GCP instances + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) + if [[ $SETUP_OPTION = "--setup" ]]; then + printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # install node modules on GCP instances + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # ssh into each instance, install packages and start up the server + printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" + printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" + eval $START_TRACKER_CMD + printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + done +fi From 299acb5bb1c51f702437adc41cff4960b5337b7a Mon Sep 17 00:00:00 2001 From: platfowner Date: Thu, 25 Jul 2024 14:53:33 +0900 Subject: [PATCH 02/18] Rename: GCP_USER -> ONPREM_USER --- deploy_blockchain_genesis_onprem.sh | 595 ++++++++++++++-------------- 1 file changed, 298 insertions(+), 297 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index ec2bbf0a8..ab001a2a0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -29,8 +29,8 @@ fi printf "SEASON=$SEASON\n" printf "PROJECT_ID=$PROJECT_ID\n" -GCP_USER="runner" -printf "GCP_USER=$GCP_USER\n" +ONPREM_USER="nvidia" +printf "ONPREM_USER=$ONPREM_USER\n" number_re='^[0-9]+$' if [[ ! $2 =~ $number_re ]] ; then @@ -218,22 +218,22 @@ function inject_account() { } # deploy files -FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +#FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" -TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan" -NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan" -NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-node-1-oregon" -NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-node-2-singapore" -NODE_3_TARGET_ADDR="${GCP_USER}@${SEASON}-node-3-iowa" -NODE_4_TARGET_ADDR="${GCP_USER}@${SEASON}-node-4-netherlands" -NODE_5_TARGET_ADDR="${GCP_USER}@${SEASON}-node-5-taiwan" -NODE_6_TARGET_ADDR="${GCP_USER}@${SEASON}-node-6-oregon" -NODE_7_TARGET_ADDR="${GCP_USER}@${SEASON}-node-7-singapore" -NODE_8_TARGET_ADDR="${GCP_USER}@${SEASON}-node-8-iowa" -NODE_9_TARGET_ADDR="${GCP_USER}@${SEASON}-node-9-netherlands" - -TRACKER_ZONE="asia-east1-b" +#TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-tracker-taiwan" +NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-0-taiwan" +NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-1-oregon" +NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-2-singapore" +NODE_3_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-3-iowa" +NODE_4_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-4-netherlands" +NODE_5_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-5-taiwan" +NODE_6_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-6-oregon" +NODE_7_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-7-singapore" +NODE_8_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-8-iowa" +NODE_9_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-9-netherlands" + +#TRACKER_ZONE="asia-east1-b" NODE_0_ZONE="asia-east1-b" NODE_1_ZONE="us-west1-b" NODE_2_ZONE="asia-southeast1-b" @@ -245,284 +245,285 @@ NODE_7_ZONE="asia-southeast1-b" NODE_8_ZONE="us-central1-a" NODE_9_ZONE="europe-west4-a" -printf "###############################################################################\n" -printf "# Deploying parent blockchain #\n" -printf "###############################################################################\n\n" - -# deploy files to GCP instances -if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} - gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi -fi - -# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) -if [[ $SETUP_OPTION = "--setup" ]]; then - # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi -fi - -# install node modules on GCP instances -if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi -fi - -if [[ $KILL_OPTION = "--skip-kill" ]]; then - printf "\nSkipping process kill...\n" -else - # kill any processes still alive - printf "\nKilling tracker / blockchain node jobs...\n" - - # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 - if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - fi - - begin_index=$PARENT_NODE_INDEX_BEGIN - if [[ $begin_index -lt 0 ]]; then - begin_index=0 - fi - if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} - done - fi - - if [[ $NUM_SHARDS -gt 0 ]]; then - for i in $(seq $NUM_SHARDS); do - printf "shard #$i\n" - - SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" - SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" - SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" - SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" - - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE - done - fi -fi - -# If --kill-only, do not proceed any further -if [[ $KILL_OPTION = "--kill-only" ]]; then - exit -fi - -printf "\nStarting blockchain servers...\n\n" -if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" -else - GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" -fi -if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then - # restart after removing chains, snapshots, and log files (but keep the keys) - CHAINS_DIR=/home/ain_blockchain_data/chains - SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots - LOGS_DIR=/home/ain_blockchain_data/logs - START_TRACKER_CMD_BASE="sudo rm -rf /home/ain_blockchain_data/ && $GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" - START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -else - # restart with existing chains, snapshots, and log files - START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" - START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -fi -printf "\n" -printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" -printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" - -# Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 -if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then - printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - - printf "\n" - printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" - printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" - START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" - printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" - eval $START_TRACKER_CMD -fi - -begin_index=$PARENT_NODE_INDEX_BEGIN -if [[ $begin_index -lt 0 ]]; then - begin_index=0 -fi -if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then - for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE - - printf "\n* >> Starting parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - - if [[ $node_index -ge $JSON_RPC_NODE_INDEX_GE ]] && [[ $node_index -le $JSON_RPC_NODE_INDEX_LE ]]; then - JSON_RPC_OPTION="--json-rpc" - else - JSON_RPC_OPTION="" - fi - UPDATE_FRONT_DB_OPTION="--update-front-db" - if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then - REST_FUNC_OPTION="--rest-func" - else - REST_FUNC_OPTION="" - fi - if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then - EVENT_HANDLER_OPTION="--event-handler" - else - EVENT_HANDLER_OPTION="" - fi - - printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" - printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" - printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" - printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" - printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" - printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" - printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" - printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" - printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" - - printf "\n" - START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON $GCP_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - sleep 5 - inject_account "$node_index" - done -fi - - -if [[ $NUM_SHARDS -gt 0 ]]; then - for shard_index in $(seq $NUM_SHARDS); do - printf "###############################################################################\n" - printf "# Deploying shard $shard_index blockchain #\n" - printf "###############################################################################\n\n" - - - # generate genesis config files in ./blockchain/shard_$shard_index - if [[ $SETUP_OPTION = "--setup" ]]; then - node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index - fi - - SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" - SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" - SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" - SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" - - # deploy files to GCP instances - if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) - if [[ $SETUP_OPTION = "--setup" ]]; then - printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # install node modules on GCP instances - if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # ssh into each instance, install packages and start up the server - printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $GCP_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" - printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" - eval $START_TRACKER_CMD - printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $GCP_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - done -fi +#printf "###############################################################################\n" +#printf "# Deploying parent blockchain #\n" +#printf "###############################################################################\n\n" +# +## deploy files to GCP instances +#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} +# gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +#fi +# +## ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +#if [[ $SETUP_OPTION = "--setup" ]]; then +# # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +#fi +# +## install node modules on GCP instances +#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +#fi +# +#if [[ $KILL_OPTION = "--skip-kill" ]]; then +# printf "\nSkipping process kill...\n" +#else +# # kill any processes still alive +# printf "\nKilling tracker / blockchain node jobs...\n" +# +# # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 +# if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE +# fi +# +# begin_index=$PARENT_NODE_INDEX_BEGIN +# if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +# fi +# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} +# done +# fi +# +# if [[ $NUM_SHARDS -gt 0 ]]; then +# for i in $(seq $NUM_SHARDS); do +# printf "shard #$i\n" +# +# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-tracker-taiwan" +# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-0-taiwan" +# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-1-oregon" +# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-2-singapore" +# +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE +# done +# fi +#fi +# +## If --kill-only, do not proceed any further +#if [[ $KILL_OPTION = "--kill-only" ]]; then +# exit +#fi +# +#printf "\nStarting blockchain servers...\n\n" +#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" +#else +# GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" +#fi +#if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then +# # restart after removing chains, snapshots, and log files (but keep the keys) +# CHAINS_DIR=/home/ain_blockchain_data/chains +# SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots +# LOGS_DIR=/home/ain_blockchain_data/logs +# START_TRACKER_CMD_BASE="sudo rm -rf /home/ain_blockchain_data/ && $GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" +# START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +#else +# # restart with existing chains, snapshots, and log files +# START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" +# START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +#fi +#printf "\n" +#printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" +#printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" +# +## Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 +#if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then +# printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# +# printf "\n" +# printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +# printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +# START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $ONPREM_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" +# printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" +# eval $START_TRACKER_CMD +#fi +# +#begin_index=$PARENT_NODE_INDEX_BEGIN +#if [[ $begin_index -lt 0 ]]; then +# begin_index=0 +#fi +#if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then +# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do +# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR +# NODE_ZONE=NODE_${node_index}_ZONE +# +# printf "\n* >> Starting parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" +# +# if [[ $node_index -ge $JSON_RPC_NODE_INDEX_GE ]] && [[ $node_index -le $JSON_RPC_NODE_INDEX_LE ]]; then +# JSON_RPC_OPTION="--json-rpc" +# else +# JSON_RPC_OPTION="" +# fi +# UPDATE_FRONT_DB_OPTION="--update-front-db" +# if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then +# REST_FUNC_OPTION="--rest-func" +# else +# REST_FUNC_OPTION="" +# fi +# if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then +# EVENT_HANDLER_OPTION="--event-handler" +# else +# EVENT_HANDLER_OPTION="" +# fi +# +# printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +# printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +# printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +# printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" +# printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" +# printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" +# printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" +# printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" +# printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" +# +# printf "\n" +# START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# sleep 5 +# inject_account "$node_index" +# done +#fi +# +# +#if [[ $NUM_SHARDS -gt 0 ]]; then +# for shard_index in $(seq $NUM_SHARDS); do +# printf "###############################################################################\n" +# printf "# Deploying shard $shard_index blockchain #\n" +# printf "###############################################################################\n\n" +# +# +# # generate genesis config files in ./blockchain/shard_$shard_index +# if [[ $SETUP_OPTION = "--setup" ]]; then +# node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index +# fi +# +# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" +# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" +# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" +# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" +# +# # deploy files to GCP instances +# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE +# printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE +# printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE +# printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE +# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE +# fi +# +# # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +# if [[ $SETUP_OPTION = "--setup" ]]; then +# printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE +# printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE +# printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE +# fi +# +# # install node modules on GCP instances +# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE +# printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE +# printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE +# printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE +# fi +# +# # ssh into each instance, install packages and start up the server +# printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" +# START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $ONPREM_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" +# printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" +# eval $START_TRACKER_CMD +# printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" +# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" +# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" +# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" +# printf "START_NODE_CMD=$START_NODE_CMD\n" +# eval $START_NODE_CMD +# done +#fi +# \ No newline at end of file From df3e7668ac6d6bc33c9fc34d083e177ee46ed0e8 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 09:45:25 +0900 Subject: [PATCH 03/18] Tweak some variable names --- config_client_api_ip_whitelist.sh | 16 ++++++++-------- config_node_param.sh | 16 ++++++++-------- deploy_blockchain_genesis_gcp.sh | 24 ++++++++++++------------ deploy_blockchain_genesis_onprem.sh | 24 ++++++++++++------------ deploy_blockchain_incremental_gcp.sh | 28 ++++++++++++++-------------- deploy_blockchain_sandbox_gcp.sh | 10 +++++----- inject_node_account.js | 2 +- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/config_client_api_ip_whitelist.sh b/config_client_api_ip_whitelist.sh index 1e0773737..85a0781de 100644 --- a/config_client_api_ip_whitelist.sh +++ b/config_client_api_ip_whitelist.sh @@ -64,12 +64,12 @@ else fi fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt # Get keystore password -printf "Enter password: " -read -s PASSWORD +printf "Enter keystore password: " +read -s KEYSTORE_PW printf "\n\n" if [[ $SEASON = "mainnet" ]]; then CHAIN_ID="1" @@ -96,19 +96,19 @@ printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n" function config_node() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} - printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n" + printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH" + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH" if [[ ! $COMMAND = "get" ]]; then CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$IP_ADDR'" fi printf "\n" printf "CONFIG_NODE_CMD=$CONFIG_NODE_CMD\n\n" - eval "echo $PASSWORD | $CONFIG_NODE_CMD" + eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD" } for j in `seq $(( 0 )) $(( 9 ))`; do diff --git a/config_node_param.sh b/config_node_param.sh index 698423e79..55679bf4e 100644 --- a/config_node_param.sh +++ b/config_node_param.sh @@ -73,12 +73,12 @@ else fi fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt # Get keystore password -printf "Enter password: " -read -s PASSWORD +printf "Enter keystore password: " +read -s KEYSTORE_PW printf "\n\n" if [[ $SEASON = "mainnet" ]]; then CHAIN_ID="1" @@ -107,19 +107,19 @@ printf "COMMAND_NODE_JS_FILE=$COMMAND_NODE_JS_FILE\n" function config_node() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} - printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_ip_addr) >>>\n\n" + printf "\n\n<<< Configuring ip whitelist of node $node_index ($node_url) >>>\n\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" - CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_ip_addr $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM" + CONFIG_NODE_CMD="node tools/api-access/$COMMAND_NODE_JS_FILE $node_url $CHAIN_ID keystore $KEYSTORE_FILE_PATH $PARAM" if [[ ! $COMMAND = "get" ]]; then CONFIG_NODE_CMD="$CONFIG_NODE_CMD '$VALUE'" fi printf "\n" printf "CONFIG_NODE_CMD=$CONFIG_NODE_CMD\n\n" - eval "echo $PASSWORD | $CONFIG_NODE_CMD" + eval "echo $KEYSTORE_PW | $CONFIG_NODE_CMD" } for j in `seq $(( 0 )) $(( 9 ))`; do diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 72d4d6eab..a17d29b09 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -163,12 +163,12 @@ else fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then - # Read node ip addresses - IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt + # Read node urls + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password - printf "Enter password: " - read -s PASSWORD + printf "Enter keystore password: " + read -s KEYSTORE_PW printf "\n\n" if [[ "$SEASON" = "mainnet" ]]; then @@ -185,35 +185,35 @@ fi function inject_account() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" { echo $KEYSTORE_FILE_PATH sleep 1 - echo $PASSWORD - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $KEYSTORE_PW + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then local MNEMONIC=${MNEMONIC_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" { echo $MNEMONIC sleep 1 echo 0 - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION else printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" fi PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION fi } diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index ab001a2a0..cb203cd26 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -163,12 +163,12 @@ else fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then - # Read node ip addresses - IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt + # Read node urls + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password - printf "Enter password: " - read -s PASSWORD + printf "Enter keystore password: " + read -s KEYSTORE_PW printf "\n\n" if [[ "$SEASON" = "mainnet" ]]; then @@ -185,35 +185,35 @@ fi function inject_account() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" { echo $KEYSTORE_FILE_PATH sleep 1 - echo $PASSWORD - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $KEYSTORE_PW + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION elif [[ "$ACCOUNT_INJECTION_OPTION" = "--mnemonic" ]]; then local MNEMONIC=${MNEMONIC_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" { echo $MNEMONIC sleep 1 echo 0 - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION else printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" fi PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION fi } diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index a76939487..84e6a156c 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -148,12 +148,12 @@ else fi fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then # Get keystore password - printf "Enter password: " - read -s PASSWORD + printf "Enter keystore password: " + read -s KEYSTORE_PW printf "\n\n" if [[ $SEASON = "mainnet" ]]; then KEYSTORE_DIR="mainnet_prod_keys" @@ -286,37 +286,37 @@ function deploy_node() { # 4. Inject node account sleep 5 if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} printf "\n* >> Initializing account for node $node_index ($node_target_addr) ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" KEYSTORE_FILE_PATH="$KEYSTORE_DIR/keystore_node_$node_index.json" { echo $KEYSTORE_FILE_PATH sleep 1 - echo $PASSWORD - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $KEYSTORE_PW + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} local MNEMONIC=${MNEMONIC_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ($node_target_addr) ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" { echo $MNEMONIC sleep 1 echo 0 - } | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + } | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION else - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} printf "\n* >> Injecting an account for node $node_index ($node_target_addr) ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then GENESIS_ACCOUNTS_PATH="blockchain-configs/testnet-prod/genesis_accounts.json" fi PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION fi # 5. Wait until node is synced diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index c1679ed28..f6982ff8e 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -90,17 +90,17 @@ then [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell fi -# Read node ip addresses -IFS=$'\n' read -d '' -r -a IP_ADDR_LIST < ./ip_addresses/$SEASON.txt +# Read node urls +IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt function inject_account() { local node_index="$1" - local node_ip_addr=${IP_ADDR_LIST[${node_index}]} + local node_url=${NODE_URL_LIST[${node_index}]} local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" printf "\n* >> Injecting an account for node $node_index ********************\n\n" - printf "node_ip_addr='$node_ip_addr'\n" + printf "node_url='$node_url'\n" PRIVATE_KEY=$(cat $GENESIS_ACCOUNTS_PATH | jq -r '.others['$node_index'].private_key') - echo $PRIVATE_KEY | node inject_node_account.js $node_ip_addr $ACCOUNT_INJECTION_OPTION + echo $PRIVATE_KEY | node inject_node_account.js $node_url $ACCOUNT_INJECTION_OPTION } # GCP node address diff --git a/inject_node_account.js b/inject_node_account.js index d0784efee..53088988e 100644 --- a/inject_node_account.js +++ b/inject_node_account.js @@ -61,7 +61,7 @@ async function injectAccount(endpointUrl, accountInjectionOption) { }) properties.push({ name: 'password', - description: 'Enter password:', + description: 'Enter keystore password:', hidden: true }) break; From 3bbd6cad1655d269027328714495b1aa8a390a14 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:14:08 +0900 Subject: [PATCH 04/18] Add file deploy part for onpremise --- deploy_blockchain_genesis_onprem.sh | 76 +++++++++++------------------ 1 file changed, 29 insertions(+), 47 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index cb203cd26..9f058f2d9 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -164,7 +164,10 @@ fi if [[ ! $KILL_OPTION = '--kill-only' ]]; then # Read node urls - IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/$SEASON.txt + IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_onprem.txt + # Read node ip addresses and passwords + IFS=$'\n' read -d '' -r -a NODE_IP_LIST < ./ip_addresses/${SEASON}_onprem_ip.txt + IFS=$'\n' read -d '' -r -a NODE_PW_LIST < ./ip_addresses/${SEASON}_onprem_pw.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password printf "Enter keystore password: " @@ -221,59 +224,38 @@ function inject_account() { #FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" -#TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-tracker-taiwan" -NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-0-taiwan" -NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-1-oregon" -NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-2-singapore" -NODE_3_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-3-iowa" -NODE_4_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-4-netherlands" -NODE_5_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-5-taiwan" -NODE_6_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-6-oregon" -NODE_7_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-7-singapore" -NODE_8_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-8-iowa" -NODE_9_TARGET_ADDR="${ONPREM_USER}@${SEASON}-node-9-netherlands" +printf "###############################################################################\n" +printf "# Deploying parent blockchain #\n" +printf "###############################################################################\n\n" -#TRACKER_ZONE="asia-east1-b" -NODE_0_ZONE="asia-east1-b" -NODE_1_ZONE="us-west1-b" -NODE_2_ZONE="asia-southeast1-b" -NODE_3_ZONE="us-central1-a" -NODE_4_ZONE="europe-west4-a" -NODE_5_ZONE="asia-east1-b" -NODE_6_ZONE="us-west1-b" -NODE_7_ZONE="asia-southeast1-b" -NODE_8_ZONE="us-central1-a" -NODE_9_ZONE="europe-west4-a" - -#printf "###############################################################################\n" -#printf "# Deploying parent blockchain #\n" -#printf "###############################################################################\n\n" -# -## deploy files to GCP instances -#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# deploy files to GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # # Tracker server is deployed with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE # gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} -# gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + printf "NODE_LOGIN_PW=${NODE_LOGIN_PW}\n" + + printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) scp -rv $FILES_FOR_NODE ${NODE_TARGET_ADDR}:~/ain-blockchain/ + #sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "ls -la" + done + fi +fi + ## ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) #if [[ $SETUP_OPTION = "--setup" ]]; then # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 From 50a1add718d04246231299061b4b473944241330 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:30:44 +0900 Subject: [PATCH 05/18] Tweak filename: setup_blockchain_ubuntu_gcp.sh --- README.md | 4 ++-- deploy_blockchain_genesis_gcp.sh | 16 ++++++++-------- deploy_blockchain_genesis_onprem.sh | 16 ++++++++-------- deploy_blockchain_incremental_gcp.sh | 8 ++++---- deploy_blockchain_sandbox_gcp.sh | 4 ++-- deploy_test_gcp.sh | 4 ++-- ...n_ubuntu.sh => setup_blockchain_ubuntu_gcp.sh | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) rename setup_blockchain_ubuntu.sh => setup_blockchain_ubuntu_gcp.sh (96%) diff --git a/README.md b/README.md index abe9ebad3..9bd5db8db 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer ``` - Set up Ubuntu machine (if it's on a new VM) ``` -bash setup_blockchain_ubuntu.sh +bash setup_blockchain_ubuntu_gcp.sh ``` - Start tracker server job ``` @@ -136,7 +136,7 @@ bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|exp|spring|summer ``` - Set up Ubuntu machine (if it's on a new VM) ``` -bash setup_blockchain_ubuntu.sh +bash setup_blockchain_ubuntu_gcp.sh ``` - Start Node server job (set shard index to 0 if you're running a root chain node) ``` diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index a17d29b09..580e097e2 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -218,8 +218,8 @@ function inject_account() { } # deploy files -FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" -FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_gcp.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-tracker-taiwan" NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-node-0-taiwan" @@ -279,7 +279,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE fi begin_index=$PARENT_NODE_INDEX_BEGIN @@ -292,7 +292,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then NODE_ZONE=NODE_${node_index}_ZONE printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} done fi fi @@ -486,13 +486,13 @@ if [[ $NUM_SHARDS -gt 0 ]]; then # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) if [[ $SETUP_OPTION = "--setup" ]]; then printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_0_ZONE printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_1_ZONE printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_2_ZONE fi # install node modules on GCP instances diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 9f058f2d9..cf8256a6c 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -221,8 +221,8 @@ function inject_account() { } # deploy files -#FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" -FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +#FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_gcp.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" printf "###############################################################################\n" printf "# Deploying parent blockchain #\n" @@ -261,7 +261,7 @@ fi # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # fi # # begin_index=$PARENT_NODE_INDEX_BEGIN @@ -274,7 +274,7 @@ fi # NODE_ZONE=NODE_${node_index}_ZONE # # printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} # done # fi #fi @@ -468,13 +468,13 @@ fi # # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) # if [[ $SETUP_OPTION = "--setup" ]]; then # printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_0_ZONE # printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_1_ZONE # printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_2_ZONE # fi # # # install node modules on GCP instances diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 84e6a156c..d64b9b054 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -166,8 +166,8 @@ elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then IFS=$'\n' read -d '' -r -a MNEMONIC_LIST < ./testnet_mnemonics/$SEASON.txt fi -FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" -FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_gcp.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" NUM_SHARD_NODES=3 @@ -204,7 +204,7 @@ function deploy_tracker() { if [[ $SETUP_OPTION = "--setup" ]]; then # 2. Set up tracker printf "\n\n[[[ Setting up tracker ]]]\n\n" - SETUP_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone $TRACKER_ZONE" + SETUP_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh' --project $PROJECT_ID --zone $TRACKER_ZONE" printf "SETUP_CMD=$SETUP_CMD\n\n" eval $SETUP_CMD fi @@ -243,7 +243,7 @@ function deploy_node() { if [[ $SETUP_OPTION = "--setup" ]]; then # 2. Set up node printf "\n\n<<< Setting up node $node_index >>>\n\n" - SETUP_CMD="gcloud compute ssh $node_target_addr --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone $node_zone" + SETUP_CMD="gcloud compute ssh $node_target_addr --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh' --project $PROJECT_ID --zone $node_zone" printf "SETUP_CMD=$SETUP_CMD\n\n" eval $SETUP_CMD fi diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index f6982ff8e..e12f7c1be 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -308,7 +308,7 @@ NODE_98_ZONE="us-central1-a" NODE_99_ZONE="europe-west4-a" # deploy files -FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh" # Work in progress spinner spin="-\|/" @@ -380,7 +380,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR NODE_ZONE=NODE_${index}_ZONE - SETUP_BLOCKCHAIN_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '. setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone ${!NODE_ZONE}" + SETUP_BLOCKCHAIN_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '. setup_blockchain_ubuntu_gcp.sh' --project $PROJECT_ID --zone ${!NODE_ZONE}" # NOTE(minsulee2): Keep printf for extensibility experiment debugging purpose # printf "SETUP_BLOCKCHAIN_CMD=$SETUP_BLOCKCHAIN_CMD\n" if [[ $index < "$(($NUM_NODES - 1))" ]]; then diff --git a/deploy_test_gcp.sh b/deploy_test_gcp.sh index c604d88bf..3e1e59b4f 100644 --- a/deploy_test_gcp.sh +++ b/deploy_test_gcp.sh @@ -92,7 +92,7 @@ function stop_servers() { } # deploy files -FILES_FOR_TEST="afan_client/ blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ test/ tools/ tracker-server/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu.sh stop_local_blockchain.sh" +FILES_FOR_TEST="afan_client/ blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ test/ tools/ tracker-server/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh stop_local_blockchain.sh" printf "\n" PROJECT_ID="testnet-dev-ground" @@ -129,7 +129,7 @@ function deploy_test() { # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) if [[ $SETUP_OPTION = "--setup" ]]; then printf "\n >> Setting up instance [$instance_index] ($test_target_addr) >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n\n" - gcloud compute ssh ${test_target_addr} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${TEST_ZONE} + gcloud compute ssh ${test_target_addr} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${TEST_ZONE} fi if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then diff --git a/setup_blockchain_ubuntu.sh b/setup_blockchain_ubuntu_gcp.sh similarity index 96% rename from setup_blockchain_ubuntu.sh rename to setup_blockchain_ubuntu_gcp.sh index a230b78a1..adeb6800b 100644 --- a/setup_blockchain_ubuntu.sh +++ b/setup_blockchain_ubuntu_gcp.sh @@ -1,6 +1,6 @@ #!/bin/bash -printf "\n[[[[[ setup_blockchain_ubuntu.sh ]]]]]\n\n" +printf "\n[[[[[ setup_blockchain_ubuntu_gcp.sh ]]]]]\n\n" printf '\n[[ Upgrading apt.. ]]\n' sudo apt update From 01f5e81a155c85bf3e84c8967cd74e62c922a947 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:33:07 +0900 Subject: [PATCH 06/18] Add setup_blockchain_ubuntu_onprem.sh --- deploy_blockchain_genesis_onprem.sh | 16 ++++----- setup_blockchain_ubuntu_onprem.sh | 56 +++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 setup_blockchain_ubuntu_onprem.sh diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index cf8256a6c..fef8971a0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -221,8 +221,8 @@ function inject_account() { } # deploy files -#FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_gcp.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" -FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_gcp.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +#FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_onprem.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_onprem.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" printf "###############################################################################\n" printf "# Deploying parent blockchain #\n" @@ -261,7 +261,7 @@ fi # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # fi # # begin_index=$PARENT_NODE_INDEX_BEGIN @@ -274,7 +274,7 @@ fi # NODE_ZONE=NODE_${node_index}_ZONE # # printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} +# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} # done # fi #fi @@ -468,13 +468,13 @@ fi # # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) # if [[ $SETUP_OPTION = "--setup" ]]; then # printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $TRACKER_ZONE +# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_0_ZONE +# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_0_ZONE # printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_1_ZONE +# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_1_ZONE # printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_gcp.sh" --project $PROJECT_ID --zone $NODE_2_ZONE +# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_2_ZONE # fi # # # install node modules on GCP instances diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh new file mode 100644 index 000000000..19572bae1 --- /dev/null +++ b/setup_blockchain_ubuntu_onprem.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +printf "\n[[[[[ setup_blockchain_ubuntu_onprem.sh ]]]]]\n\n" + +printf '\n[[ Upgrading apt.. ]]\n' +sudo apt update +# skip prompting (see https://serverfault.com/questions/527789/how-to-automate-changed-config-files-during-apt-get-upgrade-in-ubuntu-12) +sudo apt-get --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade + +printf '\n[[ Uninstalling NodeJS.. ]]\n' +sudo apt-get -y purge nodejs +sudo apt-get -y autoremove + +printf '\n[[ Installing NodeJS.. ]]\n' +sudo apt update +sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates +curl -sL https://deb.nodesource.com/setup_18.x | sudo -E bash - +# skip prompting for daemon restart (see https://askubuntu.com/questions/1367139/apt-get-upgrade-auto-restart-services) +sudo NEEDRESTART_MODE=a apt -y install nodejs + +printf 'node -v\n' +node -v + +printf 'npm --version\n' +npm --version + + +printf '\n[[ Installing yarn.. ]]\n' +sudo npm install -g yarn + +printf 'yarn --version\n' +sudo yarn --version + + +printf '\n[[ Installing make.. ]]\n' +sudo apt update +# skip prompting for daemon restart (see https://askubuntu.com/questions/1367139/apt-get-upgrade-auto-restart-services) +sudo NEEDRESTART_MODE=a apt-get install -y build-essential + +printf 'make --version\n' +make --version + + +printf '\n[[ Installing vim.. ]]\n' +sudo apt update +sudo apt install -y vim + +printf 'vim --version\n' +vim --version + +printf '\n[[ Installing jq.. ]]\n' +sudo apt update +sudo apt install -y jq + +printf 'jq --version\n' +jq --version \ No newline at end of file From a69deefd07425371e9e346c9599d0089ddba72be Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 10:38:34 +0900 Subject: [PATCH 07/18] Add ubuntu setup part for onpremise --- deploy_blockchain_genesis_onprem.sh | 42 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index fef8971a0..946f2e76f 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -247,38 +247,38 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" - printf "NODE_LOGIN_PW=${NODE_LOGIN_PW}\n" - printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + printf "\n* >> Deploying files for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) scp -rv $FILES_FOR_NODE ${NODE_TARGET_ADDR}:~/ain-blockchain/ - #sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "ls -la" done fi fi -## ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) -#if [[ $SETUP_OPTION = "--setup" ]]; then +# ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) +if [[ $SETUP_OPTION = "--setup" ]]; then # # Tracker server is set up with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Setting up parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" + done + fi +fi + ## install node modules on GCP instances #if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 From f85aca985c0eb838de4595df26a9e034033e2a52 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 11:18:42 +0900 Subject: [PATCH 08/18] Fix on-premise ubuntu setup --- setup_blockchain_ubuntu_onprem.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh index 19572bae1..f2627bc27 100644 --- a/setup_blockchain_ubuntu_onprem.sh +++ b/setup_blockchain_ubuntu_onprem.sh @@ -7,6 +7,10 @@ sudo apt update # skip prompting (see https://serverfault.com/questions/527789/how-to-automate-changed-config-files-during-apt-get-upgrade-in-ubuntu-12) sudo apt-get --yes -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade +# needed for on-premise nvidia machines +printf '\n[ apt --fix-broken install ]\n' +sudo apt -y --fix-broken install + printf '\n[[ Uninstalling NodeJS.. ]]\n' sudo apt-get -y purge nodejs sudo apt-get -y autoremove From 3f53f78984ef2b6e1eb771fef93b1734cd93130f Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 11:24:27 +0900 Subject: [PATCH 09/18] Add yarn install part for onpremise --- deploy_blockchain_genesis_onprem.sh | 38 +++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 946f2e76f..74911cd86 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -279,29 +279,31 @@ if [[ $SETUP_OPTION = "--setup" ]]; then fi fi -## install node modules on GCP instances -#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then +# install node modules on GCP instances +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # # Tracker server is installed with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Installing node modules for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" + done + fi +fi + #if [[ $KILL_OPTION = "--skip-kill" ]]; then # printf "\nSkipping process kill...\n" #else From bc3959df986dfecb41afbbf522fb44f33905a482 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 13:21:18 +0900 Subject: [PATCH 10/18] Add process kill part for onpremise --- deploy_blockchain_genesis_onprem.sh | 81 ++++++++++++----------------- 1 file changed, 34 insertions(+), 47 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 74911cd86..64b46511e 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -162,12 +162,13 @@ else fi fi +# Read node ip addresses and passwords +IFS=$'\n' read -d '' -r -a NODE_IP_LIST < ./ip_addresses/${SEASON}_onprem_ip.txt +IFS=$'\n' read -d '' -r -a NODE_PW_LIST < ./ip_addresses/${SEASON}_onprem_pw.txt + if [[ ! $KILL_OPTION = '--kill-only' ]]; then # Read node urls IFS=$'\n' read -d '' -r -a NODE_URL_LIST < ./ip_addresses/${SEASON}_onprem.txt - # Read node ip addresses and passwords - IFS=$'\n' read -d '' -r -a NODE_IP_LIST < ./ip_addresses/${SEASON}_onprem_ip.txt - IFS=$'\n' read -d '' -r -a NODE_PW_LIST < ./ip_addresses/${SEASON}_onprem_pw.txt if [[ "$ACCOUNT_INJECTION_OPTION" = "--keystore" ]]; then # Get keystore password printf "Enter keystore password: " @@ -298,60 +299,46 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" - printf "\n* >> Installing node modules for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + printf "\n* >> Installing node modules for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" done fi fi -#if [[ $KILL_OPTION = "--skip-kill" ]]; then -# printf "\nSkipping process kill...\n" -#else -# # kill any processes still alive -# printf "\nKilling tracker / blockchain node jobs...\n" -# +if [[ $KILL_OPTION = "--skip-kill" ]]; then + printf "\nSkipping process kill...\n" +else + # kill any processes still alive + printf "\nKilling tracker / blockchain node jobs...\n" + # # Tracker server is killed with PARENT_NODE_INDEX_BEGIN = -1 # if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" # gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE # fi -# -# begin_index=$PARENT_NODE_INDEX_BEGIN -# if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -# fi -# if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} -# done -# fi -# -# if [[ $NUM_SHARDS -gt 0 ]]; then -# for i in $(seq $NUM_SHARDS); do -# printf "shard #$i\n" -# -# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-tracker-taiwan" -# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-0-taiwan" -# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-1-oregon" -# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${i}-node-2-singapore" -# -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE -# done -# fi -#fi -# -## If --kill-only, do not proceed any further -#if [[ $KILL_OPTION = "--kill-only" ]]; then -# exit -#fi -# + + begin_index=$PARENT_NODE_INDEX_BEGIN + if [[ $begin_index -lt 0 ]]; then + begin_index=0 + fi + if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Killing node $node_index job (${NODE_TARGET_ADDR}) *********************************************************\n\n" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "sudo killall node" + done + fi +fi + +# If --kill-only, do not proceed any further +if [[ $KILL_OPTION = "--kill-only" ]]; then + exit +fi + #printf "\nStarting blockchain servers...\n\n" #if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" From 240aa8051e5ddf4f578c67debe20e1545a242c57 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 14:47:34 +0900 Subject: [PATCH 11/18] Add start job part for onpremise --- deploy_blockchain_genesis_onprem.sh | 213 +++++++++------------------- 1 file changed, 68 insertions(+), 145 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 64b46511e..4be729b04 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -339,28 +339,28 @@ if [[ $KILL_OPTION = "--kill-only" ]]; then exit fi -#printf "\nStarting blockchain servers...\n\n" -#if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then -# GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" -#else -# GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" -#fi -#if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then -# # restart after removing chains, snapshots, and log files (but keep the keys) -# CHAINS_DIR=/home/ain_blockchain_data/chains -# SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots -# LOGS_DIR=/home/ain_blockchain_data/logs +printf "\nStarting blockchain servers...\n\n" +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" +else + GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" +fi +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then + # restart after removing chains, snapshots, and log files (but keep the keys) + CHAINS_DIR=/home/ain_blockchain_data/chains + SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots + LOGS_DIR=/home/ain_blockchain_data/logs # START_TRACKER_CMD_BASE="sudo rm -rf /home/ain_blockchain_data/ && $GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" -# START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -#else -# # restart with existing chains, snapshots, and log files + START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +else + # restart with existing chains, snapshots, and log files # START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" -# START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" -#fi -#printf "\n" + START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" +fi +printf "\n" #printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" -#printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" -# +printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" + ## Tracker server is started with PARENT_NODE_INDEX_BEGIN = -1 #if [[ $PARENT_NODE_INDEX_BEGIN = -1 ]]; then # printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" @@ -372,129 +372,52 @@ fi # printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" # eval $START_TRACKER_CMD #fi -# -#begin_index=$PARENT_NODE_INDEX_BEGIN -#if [[ $begin_index -lt 0 ]]; then -# begin_index=0 -#fi -#if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then -# for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do -# NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR -# NODE_ZONE=NODE_${node_index}_ZONE -# -# printf "\n* >> Starting parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" -# -# if [[ $node_index -ge $JSON_RPC_NODE_INDEX_GE ]] && [[ $node_index -le $JSON_RPC_NODE_INDEX_LE ]]; then -# JSON_RPC_OPTION="--json-rpc" -# else -# JSON_RPC_OPTION="" -# fi -# UPDATE_FRONT_DB_OPTION="--update-front-db" -# if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then -# REST_FUNC_OPTION="--rest-func" -# else -# REST_FUNC_OPTION="" -# fi -# if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then -# EVENT_HANDLER_OPTION="--event-handler" -# else -# EVENT_HANDLER_OPTION="" -# fi -# -# printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" -# printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" -# printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" -# printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" -# printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" -# printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" -# printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" -# printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" -# printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" -# -# printf "\n" -# START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# sleep 5 -# inject_account "$node_index" -# done -#fi -# -# -#if [[ $NUM_SHARDS -gt 0 ]]; then -# for shard_index in $(seq $NUM_SHARDS); do -# printf "###############################################################################\n" -# printf "# Deploying shard $shard_index blockchain #\n" -# printf "###############################################################################\n\n" -# -# -# # generate genesis config files in ./blockchain/shard_$shard_index -# if [[ $SETUP_OPTION = "--setup" ]]; then -# node ./tools/generateShardGenesisFiles.js $SEASON 10 $shard_index -# fi -# -# SHARD_TRACKER_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-tracker-taiwan" -# SHARD_NODE_0_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-0-taiwan" -# SHARD_NODE_1_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-1-oregon" -# SHARD_NODE_2_TARGET_ADDR="${ONPREM_USER}@${SEASON}-shard-${shard_index}-node-2-singapore" -# -# # deploy files to GCP instances -# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then -# printf "\n* >> Deploying files to shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE -# gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE -# printf "\n* >> Deploying files to shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE -# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE -# printf "\n* >> Deploying files to shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE -# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE -# printf "\n* >> Deploying files to shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE -# gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE -# fi -# -# # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) -# if [[ $SETUP_OPTION = "--setup" ]]; then -# printf "\n* >> Setting up shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $TRACKER_ZONE -# printf "\n* >> Setting up shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_0_ZONE -# printf "\n* >> Setting up shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_1_ZONE -# printf "\n* >> Setting up shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu_onprem.sh" --project $PROJECT_ID --zone $NODE_2_ZONE -# fi -# -# # install node modules on GCP instances -# if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then -# printf "\n* >> Installing node modules for shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $TRACKER_ZONE -# printf "\n* >> Installing node modules for shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_0_ZONE -# printf "\n* >> Installing node modules for shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_1_ZONE -# printf "\n* >> Installing node modules for shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "cd ./ain-blockchain; yarn install --ignore-engines" --project $PROJECT_ID --zone $NODE_2_ZONE -# fi -# -# # ssh into each instance, install packages and start up the server -# printf "\n* >> Starting shard_$shard_index tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" -# START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $ONPREM_USER $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" -# printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" -# eval $START_TRACKER_CMD -# printf "\n* >> Starting shard_$shard_index node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" -# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# printf "\n* >> Starting shard_$shard_index node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" -# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# printf "\n* >> Starting shard_$shard_index node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" -# START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $ONPREM_USER $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION $CHOWN_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" -# printf "START_NODE_CMD=$START_NODE_CMD\n" -# eval $START_NODE_CMD -# done -#fi -# \ No newline at end of file + +begin_index=$PARENT_NODE_INDEX_BEGIN +if [[ $begin_index -lt 0 ]]; then + begin_index=0 +fi +if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then + for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do + NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" + printf "\n" + printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" + + printf "\n* >> Starting parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" + + if [[ $node_index -ge $JSON_RPC_NODE_INDEX_GE ]] && [[ $node_index -le $JSON_RPC_NODE_INDEX_LE ]]; then + JSON_RPC_OPTION="--json-rpc" + else + JSON_RPC_OPTION="" + fi + UPDATE_FRONT_DB_OPTION="--update-front-db" + if [[ $node_index -ge $REST_FUNC_NODE_INDEX_GE ]] && [[ $node_index -le $REST_FUNC_NODE_INDEX_LE ]]; then + REST_FUNC_OPTION="--rest-func" + else + REST_FUNC_OPTION="" + fi + if [[ $node_index -ge $EVENT_HANDLER_NODE_INDEX_GE ]] && [[ $node_index -le $EVENT_HANDLER_NODE_INDEX_LE ]]; then + EVENT_HANDLER_OPTION="--event-handler" + else + EVENT_HANDLER_OPTION="" + fi + + printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" + printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" + printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" + printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" + printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" + printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" + printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" + printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" + printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" + + printf "\n" + START_NODE_CMD="ssh ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" + sleep 5 + inject_account "$node_index" + done +fi From a154436a566433d472cc77f82f494fde02f74404 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 15:11:10 +0900 Subject: [PATCH 12/18] Fix sudo blocking issue in ubuntu setup --- deploy_blockchain_genesis_onprem.sh | 2 +- setup_blockchain_ubuntu_onprem.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 4be729b04..e81044e2c 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -275,7 +275,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" printf "\n* >> Setting up parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" - sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" + echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" done fi fi diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh index f2627bc27..b7b145a6e 100644 --- a/setup_blockchain_ubuntu_onprem.sh +++ b/setup_blockchain_ubuntu_onprem.sh @@ -2,6 +2,15 @@ printf "\n[[[[[ setup_blockchain_ubuntu_onprem.sh ]]]]]\n\n" +# Get keystore password +printf "Enter keystore password: " +read -s NODE_LOGIN_PW +printf "\n\n" + +# needed for on-premise nvidia machines +# do sudo once with a dummy command +echo $NODE_LOGIN_PW | sudo -S ls -la + printf '\n[[ Upgrading apt.. ]]\n' sudo apt update # skip prompting (see https://serverfault.com/questions/527789/how-to-automate-changed-config-files-during-apt-get-upgrade-in-ubuntu-12) From 9ac388fc0a15679ed2d2d1bde4f7fcb8bf3b2377 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 15:31:03 +0900 Subject: [PATCH 13/18] Add start_node_genesis_onprem.sh --- start_node_genesis_onprem.sh | 332 +++++++++++++++++++++++++++++++++++ 1 file changed, 332 insertions(+) create mode 100644 start_node_genesis_onprem.sh diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh new file mode 100644 index 000000000..04ffe6faa --- /dev/null +++ b/start_node_genesis_onprem.sh @@ -0,0 +1,332 @@ +#!/bin/bash + +# NOTE(minsulee2): Since exit really exits terminals, those are replaced to return 1. +if [[ $# -lt 4 ]] || [[ $# -gt 13 ]]; then + printf "Usage: bash start_node_genesis_onprem.sh [dev|staging|sandbox|exp|spring|summer|mainnet] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--chown-data|--no-chown-data] [--json-rpc] [--update-front-db] [--rest-func] [--event-handler]\n" + printf "Example: bash start_node_genesis_onprem.sh spring gcp_user 0 0 --keystore --no-keep-code --full-sync --no-chown-data\n" + printf "\n" + return 1 +fi +printf "\n[[[[[ start_node_genesis_onprem.sh ]]]]]\n\n" + +function parse_options() { + local option="$1" + if [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keystore' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--mnemonic' ]]; then + ACCOUNT_INJECTION_OPTION="$option" + elif [[ $option = '--keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--no-chown-data' ]]; then + CHOWN_DATA_OPTION="$option" + elif [[ $option = '--json-rpc' ]]; then + JSON_RPC_OPTION="$option" + elif [[ $option = '--update-front-db' ]]; then + UPDATE_FRONT_DB_OPTION="$option" + elif [[ $option = '--rest-func' ]]; then + REST_FUNC_OPTION="$option" + elif [[ $option = '--event-handler' ]]; then + EVENT_HANDLER_OPTION="$option" + else + printf "Invalid options: $option\n" + return 1 + fi +} + +# Parse options. +SEASON="$1" +GCP_USER="$2" + +number_re='^[0-9]+$' +if ! [[ $3 =~ $number_re ]] ; then + printf "Invalid argument: $3\n" + return 1 +fi +SHARD_INDEX="$3" + +if ! [[ $4 =~ $number_re ]] ; then + printf "Invalid argument: $4\n" + return 1 +fi +# NOTE(minsulee2): Sandbox has 100 nodes. +if [[ "$4" -lt 0 ]] || [[ "$4" -gt 100 ]]; then + printf "Invalid argument: $4\n" + return 1 +fi +NODE_INDEX="$4" + +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" +CHOWN_DATA_OPTION="--no-chown-data" +JSON_RPC_OPTION="" +UPDATE_FRONT_DB_OPTION="" +REST_FUNC_OPTION="" +EVENT_HANDLER_OPTION="" + +ARG_INDEX=5 +while [ $ARG_INDEX -le $# ]; do + parse_options "${!ARG_INDEX}" + ((ARG_INDEX++)) +done + +printf "SEASON=$SEASON\n" +printf "GCP_USER=$GCP_USER\n" +printf "SHARD_INDEX=$SHARD_INDEX\n" +printf "NODE_INDEX=$NODE_INDEX\n" +printf "\n" + +printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" +printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" +printf "CHOWN_DATA_OPTION=$CHOWN_DATA_OPTION\n" +printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" +printf "UPDATE_FRONT_DB_OPTION=$UPDATE_FRONT_DB_OPTION\n" +printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" +printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" + +# Peer-whitelisting-enabled blockchain nodes +# Peer whitelisting is disabled now with 5 core blockchain nodes on GCP. +#PEER_WHITELIST_NODE_INDEX_GE=0 +#PEER_WHITELIST_NODE_INDEX_LE=4 +PEER_WHITELIST_NODE_INDEX_GE=-1 +PEER_WHITELIST_NODE_INDEX_LE=-1 + +printf "\n" +printf "PEER_WHITELIST_NODE_INDEX_GE=$PEER_WHITELIST_NODE_INDEX_GE\n" +printf "PEER_WHITELIST_NODE_INDEX_LE=$PEER_WHITELIST_NODE_INDEX_LE\n" + +# NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. +if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then + printf 'Invalid account injection option\n' + return 1 +fi + +if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then + printf "Must provide an ACCOUNT_INJECTION_OPTION\n" + return 1 +fi + +if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then + export ACCOUNT_INJECTION_OPTION=keystore +elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then + export ACCOUNT_INJECTION_OPTION=mnemonic +else + export ACCOUNT_INJECTION_OPTION=private_key +fi +if [[ $SYNC_MODE_OPTION = "--full-sync" ]]; then + export SYNC_MODE=full +else + export SYNC_MODE=fast +fi +if [[ $SEASON = "staging" ]] || [[ $SEASON = "exp" ]]; then + # staging: for performance test pipeline + # exp: for performance test + export ENABLE_EXPRESS_RATE_LIMIT=false +else + export ENABLE_EXPRESS_RATE_LIMIT=true +fi +if [[ $JSON_RPC_OPTION ]]; then + export ENABLE_JSON_RPC_API=true +else + export ENABLE_JSON_RPC_API=false +fi +if [[ $UPDATE_FRONT_DB_OPTION ]]; then + export UPDATE_NEW_FINAL_FRONT_DB_WITH_TX_POOL=true +else + export UPDATE_NEW_FINAL_FRONT_DB_WITH_TX_POOL=false +fi +if [[ $REST_FUNC_OPTION ]]; then + export ENABLE_REST_FUNCTION_CALL=true +else + export ENABLE_REST_FUNCTION_CALL=false +fi +if [[ $EVENT_HANDLER_OPTION ]]; then + export ENABLE_EVENT_HANDLER=true +else + export ENABLE_EVENT_HANDLER=false +fi + +printf '\n' +printf 'Killing old jobs..\n' +sudo killall node +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf '\n' + printf 'Setting up new working directory..\n' + sudo rm -rf /home/ain-blockchain* + CODE_CMD="cd ~; sudo mv ain-blockchain /home; sudo chmod -R 777 /home/ain-blockchain; sudo chown -R $GCP_USER:$GCP_USER /home/ain-blockchain; cd /home/ain-blockchain" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD +else + printf '\n' + printf 'Reusing existing working directory..\n' + OLD_DIR_PATH=$(find /home/ain-blockchain* -maxdepth 0 -type d) + printf "OLD_DIR_PATH=$OLD_DIR_PATH\n" + CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R $GCP_USER:$GCP_USER $OLD_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD +fi +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then + printf '\n' + printf 'Setting up new data directory..\n' + sudo rm -rf /home/ain_blockchain_data/chains + sudo rm -rf /home/ain_blockchain_data/snapshots + sudo rm -rf /home/ain_blockchain_data/logs + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R $GCP_USER:$GCP_USER /home/ain_blockchain_data" + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD +else + printf 'Reusing existing data directory..\n' + if [[ $CHOWN_DATA_OPTION = "--no-chown-data" ]]; then + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod 777 /home/ain_blockchain_data; sudo chown $GCP_USER:$GCP_USER /home/ain_blockchain_data" + else + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R $GCP_USER:$GCP_USER /home/ain_blockchain_data" + fi + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD +fi + + +if [[ $SEASON = 'mainnet' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/mainnet-prod + export PEER_CANDIDATE_JSON_RPC_URL="http://104.199.237.250:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x000C63907F7Aeca56A72F5a4F7cd00EfFCF11c3A,0x001C3C9C4a5669eCD8b78946f6fa5549b33362F8,0x002C76f0aeA9Ba615428d9dF7fedEC6f8ed5369f,0x003C9d091584fEC96bC3bD8423c884680BEAaf4E,0x004C4328B6c2ABF7c4Df897a8124b36E3f00a2FC,0x005C99Db64845e5BF24cd152b22c932989479907,0x006C672861e9DBb09232307c17Be6554BC90687c,0x007C36bf5D0F77836eE138EEAc8df7051b43209b,0x008C287187a5626D0a25DbD67327B36AC55B998E,0x009C66DBce144003f8C4B859fFFce78F80fDD639" + fi +elif [[ $SEASON = 'summer' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod + export TRACKER_UPDATE_JSON_RPC_URL="http://35.194.172.106:8080/json-rpc" + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.169.78:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x000AF024FEDb636294867bEff390bCE6ef9C5fc4,0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d,0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211,0x003AD6FdB06684175e7D95EcC36758B014517E4b,0x004A2550661c8a306207C9dabb279d5701fFD66e,0x005A3c55EcE1A593b761D408B6E6BC778E0a638B,0x006Af719E197bC81BBb75d2fec7Ea217D1750bAe,0x007Ac58EAc5F0D0bDd10Af8b90799BcF849c2E74,0x008AeBc041B7ceABc53A4cf393ccF16c10c29dba,0x009A97c0cF07fdbbcdA1197aE11792258b6EcedD" + fi +elif [[ $SEASON = 'spring' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-prod + export PEER_CANDIDATE_JSON_RPC_URL="http://35.221.184.48:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x000AF024FEDb636294867bEff390bCE6ef9C5fc4,0x001Ac309EFFFF6d307CbC2d09C811aCD7dD8A35d,0x002A273ECd3aAEc4d8748f4E06eAdE3b34d83211,0x003AD6FdB06684175e7D95EcC36758B014517E4b,0x004A2550661c8a306207C9dabb279d5701fFD66e,0x005A3c55EcE1A593b761D408B6E6BC778E0a638B,0x006Af719E197bC81BBb75d2fec7Ea217D1750bAe,0x007Ac58EAc5F0D0bDd10Af8b90799BcF849c2E74,0x008AeBc041B7ceABc53A4cf393ccF16c10c29dba,0x009A97c0cF07fdbbcdA1197aE11792258b6EcedD" + fi +elif [[ "$SEASON" = "sandbox" ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-sandbox + if [[ $NODE_INDEX -lt 10 ]]; then + # Nodes 10 & above will use https://sandbox-api.ainetwork.ai/json-rpc. + export PEER_CANDIDATE_JSON_RPC_URL="http://130.211.244.169:8080/json-rpc" + fi + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi +elif [[ $SEASON = 'staging' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-staging + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.139.219:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi +elif [[ $SEASON = 'exp' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-exp + export PEER_CANDIDATE_JSON_RPC_URL="http://34.81.178.195:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi +elif [[ $SEASON = 'dev' ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/testnet-dev + if [[ $SHARD_INDEX = 0 ]]; then + export PEER_CANDIDATE_JSON_RPC_URL="http://35.194.235.180:8080/json-rpc" + if [[ $NODE_INDEX -ge $PEER_WHITELIST_NODE_INDEX_GE ]] && [[ $NODE_INDEX -le $PEER_WHITELIST_NODE_INDEX_LE ]]; then + export PEER_WHITELIST="0x00ADEc28B6a845a085e03591bE7550dd68673C1C,0x01A0980d2D4e418c7F27e1ef539d01A5b5E93204,0x02A2A1DF4f630d760c82BE07F18e5065d103Fa00,0x03AAb7b6f16A92A1dfe018Fe34ee420eb098B98A,0x04A456C92A880cd59D7145C457475515a6f6E0f2,0x05A1247A7400f0C2A893611adD1505743552c631,0x06AD9C8F611f1e9d9CACD4738167A51aA2e80a1A,0x07A43138CC760C85A5B1F115aa60eADEaa0bf417,0x08Aed7AF9354435c38d52143EE50ac839D20696b,0x09A0d53FDf1c36A131938eb379b98910e55EEfe1" + fi + elif [[ $SHARD_INDEX = 1 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.187.153.22:8080/json-rpc" # dev-shard-1-tracker-ip + elif [[ $SHARD_INDEX = 2 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.203.104:8080/json-rpc" # dev-shard-2-tracker-ip + elif [[ $SHARD_INDEX = 3 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.189.174.17:8080/json-rpc" # dev-shard-3-tracker-ip + elif [[ $SHARD_INDEX = 4 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.221.164.158:8080/json-rpc" # dev-shard-4-tracker-ip + elif [[ $SHARD_INDEX = 5 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.234.46.65:8080/json-rpc" # dev-shard-5-tracker-ip + elif [[ $SHARD_INDEX = 6 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.221.210.171:8080/json-rpc" # dev-shard-6-tracker-ip + elif [[ $SHARD_INDEX = 7 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.222.121:8080/json-rpc" # dev-shard-7-tracker-ip + elif [[ $SHARD_INDEX = 8 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.221.200.95:8080/json-rpc" # dev-shard-8-tracker-ip + elif [[ $SHARD_INDEX = 9 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.216.199:8080/json-rpc" # dev-shard-9-tracker-ip + elif [[ $SHARD_INDEX = 10 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.161.85:8080/json-rpc" # dev-shard-10-tracker-ip + elif [[ $SHARD_INDEX = 11 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.194.239.169:8080/json-rpc" # dev-shard-11-tracker-ip + elif [[ $SHARD_INDEX = 12 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.185.156.22:8080/json-rpc" # dev-shard-12-tracker-ip + elif [[ $SHARD_INDEX = 13 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.229.247.143:8080/json-rpc" # dev-shard-13-tracker-ip + elif [[ $SHARD_INDEX = 14 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.229.226.47:8080/json-rpc" # dev-shard-14-tracker-ip + elif [[ $SHARD_INDEX = 15 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.234.61.23:8080/json-rpc" # dev-shard-15-tracker-ip + elif [[ $SHARD_INDEX = 16 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.66.41:8080/json-rpc" # dev-shard-16-tracker-ip + elif [[ $SHARD_INDEX = 17 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.229.143.18:8080/json-rpc" # dev-shard-17-tracker-ip + elif [[ $SHARD_INDEX = 18 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.234.58.137:8080/json-rpc" # dev-shard-18-tracker-ip + elif [[ $SHARD_INDEX = 19 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://34.80.249.104:8080/json-rpc" # dev-shard-19-tracker-ip + elif [[ $SHARD_INDEX = 20 ]]; then + export TRACKER_UPDATE_JSON_RPC_URL="http://35.201.248.92:8080/json-rpc" # dev-shard-20-tracker-ip + else + printf "Invalid shard ID argument: $SHARD_INDEX\n" + return 1 + fi + if [[ $SHARD_INDEX -gt 0 ]]; then + export BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/sim-shard + fi +else + printf "Invalid season argument: $SEASON\n" + return 1 +fi + +printf "\n" +printf "TRACKER_UPDATE_JSON_RPC_URL=$TRACKER_UPDATE_JSON_RPC_URL\n" +printf "BLOCKCHAIN_CONFIGS_DIR=$BLOCKCHAIN_CONFIGS_DIR\n" +printf "PEER_CANDIDATE_JSON_RPC_URL=$PEER_CANDIDATE_JSON_RPC_URL\n" +printf "PEER_WHITELIST=$PEER_WHITELIST\n" + +export STAKE=100000 +printf "STAKE=$STAKE\n" +export LOG_BANDAGE_INFO=true +printf "LOG_BANDAGE_INFO=$LOG_BANDAGE_INFO\n" +# uncomment and set value when necessary +#export TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER=124440 # summer +#printf "TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER=$TIMER_FLAG_EARLY_APPLIED_BLOCK_NUMBER\n" + +if [[ "$SEASON" = "sandbox" ]]; then + MAX_OLD_SPACE_SIZE_MB=11000 +else + MAX_OLD_SPACE_SIZE_MB=55000 +fi + +printf "\nStarting up Blockchain Node server..\n\n" +START_CMD="nohup node --async-stack-traces --max-old-space-size=$MAX_OLD_SPACE_SIZE_MB client/index.js >/dev/null 2>error_logs.txt &" +printf "\nSTART_CMD=$START_CMD\n" +printf "START_CMD=$START_CMD\n" >> start_commands.txt +eval $START_CMD + + +printf "\nBlockchain Node server [$SEASON $SHARD_INDEX $NODE_INDEX] is now up!\n\n" From 0d2c2cbf2ba50dd2bf4abbc8f146a915007316f5 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 15:43:06 +0900 Subject: [PATCH 14/18] Use start_node_genesis_onprem.sh --- deploy_blockchain_genesis_onprem.sh | 14 ++++++++------ setup_blockchain_ubuntu_onprem.sh | 7 +++---- start_node_genesis_onprem.sh | 9 +++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index e81044e2c..b317a23fd 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -223,7 +223,7 @@ function inject_account() { # deploy files #FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu_onprem.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" -FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_onprem.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" +FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ package.json setup_blockchain_ubuntu_onprem.sh start_node_genesis_onprem.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh stop_local_blockchain.sh" printf "###############################################################################\n" printf "# Deploying parent blockchain #\n" @@ -351,11 +351,11 @@ if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots LOGS_DIR=/home/ain_blockchain_data/logs # START_TRACKER_CMD_BASE="sudo rm -rf /home/ain_blockchain_data/ && $GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" - START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" + START_NODE_CMD_BASE="sudo rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR && $GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_onprem.sh" else # restart with existing chains, snapshots, and log files # START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh" - START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_gcp.sh" + START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_genesis_onprem.sh" fi printf "\n" #printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" @@ -414,9 +414,11 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" printf "\n" - START_NODE_CMD="ssh ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" + #START_NODE_CMD="ssh ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'" + #START_NODE_CMD="ssh ${NODE_TARGET_ADDR} $START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION" + #printf "START_NODE_CMD=$START_NODE_CMD\n" + #eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" + echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION" sleep 5 inject_account "$node_index" done diff --git a/setup_blockchain_ubuntu_onprem.sh b/setup_blockchain_ubuntu_onprem.sh index b7b145a6e..7943e579b 100644 --- a/setup_blockchain_ubuntu_onprem.sh +++ b/setup_blockchain_ubuntu_onprem.sh @@ -2,12 +2,11 @@ printf "\n[[[[[ setup_blockchain_ubuntu_onprem.sh ]]]]]\n\n" -# Get keystore password -printf "Enter keystore password: " +# needed for on-premise nvidia machines +# Get node login password +printf "Enter node login password: " read -s NODE_LOGIN_PW printf "\n\n" - -# needed for on-premise nvidia machines # do sudo once with a dummy command echo $NODE_LOGIN_PW | sudo -S ls -la diff --git a/start_node_genesis_onprem.sh b/start_node_genesis_onprem.sh index 04ffe6faa..b16e40c49 100644 --- a/start_node_genesis_onprem.sh +++ b/start_node_genesis_onprem.sh @@ -7,6 +7,15 @@ if [[ $# -lt 4 ]] || [[ $# -gt 13 ]]; then printf "\n" return 1 fi + +# needed for on-premise nvidia machines +# Get node login password +printf "Enter node login password: " +read -s NODE_LOGIN_PW +printf "\n\n" +# do sudo once with a dummy command +echo $NODE_LOGIN_PW | sudo -S ls -la + printf "\n[[[[[ start_node_genesis_onprem.sh ]]]]]\n\n" function parse_options() { From 61ae9f354058e2b5b1500a584881386b73be4447 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 17:27:51 +0900 Subject: [PATCH 15/18] Fix start node part for onpremise --- deploy_blockchain_genesis_onprem.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index b317a23fd..1d88be7a0 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -414,11 +414,9 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" printf "\n" - #START_NODE_CMD="ssh ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'" - #START_NODE_CMD="ssh ${NODE_TARGET_ADDR} $START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION" - #printf "START_NODE_CMD=$START_NODE_CMD\n" - #eval "sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" - echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION" + START_NODE_CMD="ssh ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval "echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" sleep 5 inject_account "$node_index" done From e69bab5afb7480c54341d8160c4d568bfe23e4b8 Mon Sep 17 00:00:00 2001 From: platfowner Date: Fri, 26 Jul 2024 18:00:53 +0900 Subject: [PATCH 16/18] Check --setup option along with --no-keep-code option --- deploy_blockchain_genesis_gcp.sh | 6 ++++++ deploy_blockchain_genesis_onprem.sh | 6 ++++++ deploy_blockchain_incremental_gcp.sh | 5 +++++ deploy_blockchain_sandbox_gcp.sh | 6 ++++++ deploy_test_gcp.sh | 6 ++++++ 5 files changed, 29 insertions(+) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 580e097e2..90a6509ff 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -104,6 +104,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 1d88be7a0..b2850ea54 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -104,6 +104,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index d64b9b054..f2ad47dec 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -91,6 +91,11 @@ while [ $ARG_INDEX -le $# ]; do ((ARG_INDEX++)) done +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index e12f7c1be..3bec26142 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -74,6 +74,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" diff --git a/deploy_test_gcp.sh b/deploy_test_gcp.sh index 3e1e59b4f..b88394daf 100644 --- a/deploy_test_gcp.sh +++ b/deploy_test_gcp.sh @@ -63,6 +63,12 @@ while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done + +if [[ $SETUP_OPTION = "--setup" ]] && [[ ! $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "You cannot use --setup without --no-keep-code\n" + exit +fi + printf "SETUP_OPTION=$SETUP_OPTION\n" printf "CAT_LOG_OPTION=$CAT_LOG_OPTION\n" printf "STOP_ONLY_OPTION=$STOP_ONLY_OPTION\n" From f14baeba0120c2cc367c2407d7c19a7cc3eb0698 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 29 Jul 2024 11:20:13 +0900 Subject: [PATCH 17/18] Add -v option to ssh --- deploy_blockchain_genesis_onprem.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index b2850ea54..4f42d4180 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -281,7 +281,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" printf "\n* >> Setting up parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" - echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" + echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "cd ./ain-blockchain; . setup_blockchain_ubuntu_onprem.sh" done fi fi @@ -306,7 +306,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" printf "\n* >> Installing node modules for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n" - sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "cd ./ain-blockchain; yarn install --ignore-engines" done fi fi @@ -335,7 +335,7 @@ else printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" printf "\n* >> Killing node $node_index job (${NODE_TARGET_ADDR}) *********************************************************\n\n" - sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh ${NODE_TARGET_ADDR} "sudo killall node" + sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo killall node" done fi fi @@ -420,7 +420,7 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g printf "EVENT_HANDLER_OPTION=$EVENT_HANDLER_OPTION\n" printf "\n" - START_NODE_CMD="ssh ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'" + START_NODE_CMD="ssh -v ${NODE_TARGET_ADDR} '$START_NODE_CMD_BASE $SEASON $ONPREM_USER 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $CHOWN_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $UPDATE_FRONT_DB_OPTION $REST_FUNC_OPTION $EVENT_HANDLER_OPTION'" printf "START_NODE_CMD=$START_NODE_CMD\n" eval "echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ${START_NODE_CMD}" sleep 5 From a1a385e4907c2b779f53ccef2ebef4a05345ddb1 Mon Sep 17 00:00:00 2001 From: platfowner Date: Mon, 29 Jul 2024 14:43:09 +0900 Subject: [PATCH 18/18] Use ONPREM_USER --- deploy_blockchain_genesis_onprem.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/deploy_blockchain_genesis_onprem.sh b/deploy_blockchain_genesis_onprem.sh index 4f42d4180..809461a41 100644 --- a/deploy_blockchain_genesis_onprem.sh +++ b/deploy_blockchain_genesis_onprem.sh @@ -250,7 +250,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" @@ -275,7 +275,7 @@ if [[ $SETUP_OPTION = "--setup" ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" @@ -300,7 +300,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" @@ -329,7 +329,7 @@ else fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n" @@ -385,7 +385,7 @@ if [[ $begin_index -lt 0 ]]; then fi if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -ge 0 ]]; then for node_index in `seq $(( $begin_index )) $(( $PARENT_NODE_INDEX_END ))`; do - NODE_TARGET_ADDR="nvidia@${NODE_IP_LIST[${node_index}]}" + NODE_TARGET_ADDR="${ONPREM_USER}@${NODE_IP_LIST[${node_index}]}" NODE_LOGIN_PW="${NODE_PW_LIST[${node_index}]}" printf "\n" printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\n"