Skip to content

Commit

Permalink
Merge pull request #1314 from ainblockchain/bugfix/platfowner/bugfix
Browse files Browse the repository at this point in the history
Use $SEASON as directory instead of prefix
  • Loading branch information
platfowner authored Aug 29, 2024
2 parents c8c6e08 + 742508d commit b71b22a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion copy_blockchain_data_gcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function upload_data() {

# 2. Extract tgz file for node
printf "\n\n<<< Extracting tgz file for node $node_index >>>\n\n"
TGZ_CMD="gcloud compute ssh $node_target_addr --command 'cd /home; sudo mkdir -p ain_blockchain_data; sudo chown runner:runner ain_blockchain_data; sudo chmod 777 ain_blockchain_data; cd ain_blockchain_data; gzip -dc ~/ain_blockchain_data.tar.gz | tar xvf -' --project $PROJECT_ID --zone $node_zone"
TGZ_CMD="gcloud compute ssh $node_target_addr --command 'cd /home; sudo mkdir -p ain_blockchain_data; sudo chown $GCP_USER:$GCP_USER ain_blockchain_data; sudo chmod 777 ain_blockchain_data; cd ain_blockchain_data; gzip -dc ~/ain_blockchain_data.tar.gz | tar xvf -' --project $PROJECT_ID --zone $node_zone"
printf "TGZ_CMD=$TGZ_CMD\n\n"
eval $TGZ_CMD

Expand Down
16 changes: 8 additions & 8 deletions copy_blockchain_data_onprem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,21 @@ function download_data() {

# 1. Create tgz file for node
printf "\n\n<<< Creating tgz file for node $node_index >>>\n\n"
TGZ_CMD="ssh -v $node_target_addr 'cd /home/${SEASON}_ain_blockchain_data; tar cvf - chains snapshots | gzip -c > ~/${SEASON}_ain_blockchain_data.tar.gz'"
TGZ_CMD="ssh -v $node_target_addr 'sudo -S ls -la; cd /home/${SEASON}/ain_blockchain_data; tar cvf - chains snapshots | gzip -c > ~/ain_blockchain_data.tar.gz'"
printf "TGZ_CMD=$TGZ_CMD\n\n"
eval "echo ${node_login_pw} | sshpass -f <(printf '%s\n' ${node_login_pw}) ${TGZ_CMD}"

# 2. Copy tgz file from node
printf "\n\n<<< Copying tgz file from node $node_index >>>\n\n"
SCP_CMD="scp -rv $node_target_addr:~/${SEASON}_ain_blockchain_data.tar.gz ."
SCP_CMD="scp -rv $node_target_addr:~/ain_blockchain_data.tar.gz ."
printf "SCP_CMD=$SCP_CMD\n\n"
eval "sshpass -f <(printf '%s\n' ${node_login_pw}) ${SCP_CMD}"

# 3. Clean up tgz file for node
printf "\n\n<<< Cleaning up tgz file for node $node_index >>>\n\n"
CLEANUP_CMD="ssh -v $node_target_addr 'rm ~/${SEASON}_ain_blockchain_data.tar.gz'"
CLEANUP_CMD="ssh -v $node_target_addr 'rm ~/ain_blockchain_data.tar.gz'"
printf "CLEANUP_CMD=$CLEANUP_CMD\n\n"
eval "echo ${node_login_pw} | sshpass -f <(printf '%s\n' ${node_login_pw}) ${CLEANUP_CMD}"
eval "sshpass -f <(printf '%s\n' ${node_login_pw}) ${CLEANUP_CMD}"
}

function upload_data() {
Expand All @@ -109,21 +109,21 @@ function upload_data() {

# 1. Copy tgz file to node
printf "\n\n<<< Copying tgz file to node $node_index >>>\n\n"
SCP_CMD="scp -rv ./${SEASON}_ain_blockchain_data.tar.gz $node_target_addr:~"
SCP_CMD="scp -rv ./ain_blockchain_data.tar.gz $node_target_addr:~"
printf "SCP_CMD=$SCP_CMD\n\n"
eval "sshpass -f <(printf '%s\n' ${node_login_pw}) ${SCP_CMD}"

# 2. Extract tgz file for node
printf "\n\n<<< Extracting tgz file for node $node_index >>>\n\n"
TGZ_CMD="ssh -v $node_target_addr 'cd /home; sudo mkdir -p ${SEASON}_ain_blockchain_data; sudo chown runner:runner ${SEASON}_ain_blockchain_data; sudo chmod 777 ${SEASON}_ain_blockchain_data; cd ${SEASON}_ain_blockchain_data; gzip -dc ~/${SEASON}_ain_blockchain_data.tar.gz | tar xvf -'"
TGZ_CMD="ssh -v $node_target_addr 'sudo -S ls -la; cd /home; sudo mkdir -p ${SEASON}/ain_blockchain_data; sudo chown $ONPREM_USER:$ONPREM_USER ${SEASON} ${SEASON}/ain_blockchain_data; sudo chmod 777 ${SEASON} ${SEASON}/ain_blockchain_data; cd ${SEASON}/ain_blockchain_data; gzip -dc ~/ain_blockchain_data.tar.gz | tar xvf -'"
printf "TGZ_CMD=$TGZ_CMD\n\n"
eval "echo ${node_login_pw} | sshpass -f <(printf '%s\n' ${node_login_pw}) ${TGZ_CMD}"

# 3. Clean up tgz file for node
printf "\n\n<<< Cleaning up tgz file for node $node_index >>>\n\n"
CLEANUP_CMD="ssh -v $node_target_addr 'rm ~/${SEASON}_ain_blockchain_data.tar.gz'"
CLEANUP_CMD="ssh -v $node_target_addr 'rm ~/ain_blockchain_data.tar.gz'"
printf "CLEANUP_CMD=$CLEANUP_CMD\n\n"
eval "echo ${node_login_pw} | sshpass -f <(printf '%s\n' ${node_login_pw}) ${CLEANUP_CMD}"
eval "sshpass -f <(printf '%s\n' ${node_login_pw}) ${CLEANUP_CMD}"
}

if [[ "$COMMAND" = 'upload' ]]; then
Expand Down
16 changes: 8 additions & 8 deletions deploy_blockchain_genesis_onprem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
printf "NODE_TARGET_ADDR=${NODE_TARGET_ADDR}\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}:~/${SEASON}-ain-blockchain/
sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) scp -rv $FILES_FOR_NODE ${NODE_TARGET_ADDR}:~/ain-blockchain/
done
fi
fi
Expand All @@ -273,7 +273,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 -v ${NODE_TARGET_ADDR} "cd ./${SEASON}-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
Expand All @@ -298,7 +298,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 -v ${NODE_TARGET_ADDR} "cd ./${SEASON}-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
Expand Down Expand Up @@ -339,9 +339,9 @@ fi

printf "\nStarting blockchain servers...\n\n"
if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
GO_TO_PROJECT_ROOT_CMD="cd ./${SEASON}-ain-blockchain"
GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain"
else
GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/${SEASON}-ain-blockchain* -maxdepth 0 -type d)"
GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/${SEASON}/ain-blockchain* -maxdepth 0 -type d)"
fi

#START_TRACKER_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_tracker_genesis_gcp.sh"
Expand Down Expand Up @@ -376,9 +376,9 @@ if [[ $begin_index -le $PARENT_NODE_INDEX_END ]] && [[ $PARENT_NODE_INDEX_END -g
if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then
printf "\n* >> Removing old data for parent node $node_index (${NODE_TARGET_ADDR}) *********************************************************\n\n"

CHAINS_DIR=/home/${SEASON}_ain_blockchain_data/chains
SNAPSHOTS_DIR=/home/${SEASON}_ain_blockchain_data/snapshots
LOGS_DIR=/home/${SEASON}_ain_blockchain_data/logs
CHAINS_DIR=/home/${SEASON}/ain_blockchain_data/chains
SNAPSHOTS_DIR=/home/${SEASON}/ain_blockchain_data/snapshots
LOGS_DIR=/home/${SEASON}/ain_blockchain_data/logs
echo ${NODE_LOGIN_PW} | sshpass -f <(printf '%s\n' ${NODE_LOGIN_PW}) ssh -v ${NODE_TARGET_ADDR} "sudo -S rm -rf $CHAINS_DIR $SNAPSHOTS_DIR $LOGS_DIR"
fi

Expand Down
26 changes: 13 additions & 13 deletions start_node_genesis_onprem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function parse_options() {

# Parse options.
SEASON="$1"
GCP_USER="$2"
ONPREM_USER="$2"

number_re='^[0-9]+$'
if ! [[ $3 =~ $number_re ]] ; then
Expand Down Expand Up @@ -95,7 +95,7 @@ while [ $ARG_INDEX -le $# ]; do
done

printf "SEASON=$SEASON\n"
printf "GCP_USER=$GCP_USER\n"
printf "ONPREM_USER=$ONPREM_USER\n"
printf "SHARD_INDEX=$SHARD_INDEX\n"
printf "NODE_INDEX=$NODE_INDEX\n"
printf "\n"
Expand Down Expand Up @@ -178,35 +178,35 @@ sudo killall "client/${SEASON}-ain-blockchain-index.js"
if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
printf '\n'
printf 'Setting up new working directory..\n'
sudo rm -rf /home/${SEASON}-ain-blockchain*
sudo rm -rf /home/${SEASON}/ain-blockchain*
# NOTE(platfowner): Add $SEASON to the node job name to be selectively killed in restarts.
CODE_CMD="cd ~; sudo mv ${SEASON}-ain-blockchain /home; sudo chmod -R 777 /home/${SEASON}-ain-blockchain; sudo chown -R $GCP_USER:$GCP_USER /home/${SEASON}-ain-blockchain; cd /home/${SEASON}-ain-blockchain; mv client/index.js client/${SEASON}-ain-blockchain-index.js"
CODE_CMD="sudo mkdir -p /home/${SEASON}; sudo chmod -R 777 /home/${SEASON}; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}; cd ~; sudo mv ./ain-blockchain /home/${SEASON}; sudo chmod -R 777 /home/${SEASON}/ain-blockchain; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}/ain-blockchain; cd /home/${SEASON}/ain-blockchain; mv client/index.js client/${SEASON}-ain-blockchain-index.js"
printf "\nCODE_CMD=$CODE_CMD\n"
eval $CODE_CMD
else
printf '\n'
printf 'Reusing existing working directory..\n'
OLD_DIR_PATH=$(find /home/${SEASON}-ain-blockchain* -maxdepth 0 -type d)
OLD_DIR_PATH=$(find /home/${SEASON}/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"
CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R $ONPREM_USER:$ONPREM_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/${SEASON}_ain_blockchain_data/chains
sudo rm -rf /home/${SEASON}_ain_blockchain_data/snapshots
sudo rm -rf /home/${SEASON}_ain_blockchain_data/logs
DATA_CMD="sudo mkdir -p /home/${SEASON}_ain_blockchain_data; sudo chmod -R 777 /home/${SEASON}_ain_blockchain_data; sudo chown -R $GCP_USER:$GCP_USER /home/${SEASON}_ain_blockchain_data"
sudo rm -rf /home/${SEASON}/ain_blockchain_data/chains
sudo rm -rf /home/${SEASON}/ain_blockchain_data/snapshots
sudo rm -rf /home/${SEASON}/ain_blockchain_data/logs
DATA_CMD="sudo mkdir -p /home/${SEASON}/ain_blockchain_data; sudo chmod -R 777 /home/${SEASON}/ain_blockchain_data; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}/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/${SEASON}_ain_blockchain_data; sudo chmod 777 /home/${SEASON}_ain_blockchain_data; sudo chown $GCP_USER:$GCP_USER /home/${SEASON}_ain_blockchain_data"
DATA_CMD="sudo mkdir -p /home/${SEASON}/ain_blockchain_data; sudo chmod 777 /home/${SEASON}/ain_blockchain_data; sudo chown $ONPREM_USER:$ONPREM_USER /home/${SEASON}/ain_blockchain_data"
else
DATA_CMD="sudo mkdir -p /home/${SEASON}_ain_blockchain_data; sudo chmod -R 777 /home/${SEASON}_ain_blockchain_data; sudo chown -R $GCP_USER:$GCP_USER /home/${SEASON}_ain_blockchain_data"
DATA_CMD="sudo mkdir -p /home/${SEASON}/ain_blockchain_data; sudo chmod -R 777 /home/${SEASON}/ain_blockchain_data; sudo chown -R $ONPREM_USER:$ONPREM_USER /home/${SEASON}/ain_blockchain_data"
fi
printf "\nDATA_CMD=$DATA_CMD\n"
eval $DATA_CMD
Expand Down Expand Up @@ -329,7 +329,7 @@ printf "LOG_BANDAGE_INFO=$LOG_BANDAGE_INFO\n"
export HOSTING_ENV="comcom"
printf "HOSTING_ENV=$HOSTING_ENV\n"
# on-premise nodes run with a blockchain data directory prefixed by ${SEASON}_
export BLOCKCHAIN_DATA_DIR="/home/${SEASON}_ain_blockchain_data"
export BLOCKCHAIN_DATA_DIR="/home/${SEASON}/ain_blockchain_data"
printf "BLOCKCHAIN_DATA_DIR=$BLOCKCHAIN_DATA_DIR\n"

if [[ "$SEASON" = "sandbox" ]]; then
Expand Down

0 comments on commit b71b22a

Please sign in to comment.