-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathstart_tracker_genesis_gcp.sh
62 lines (52 loc) · 1.84 KB
/
start_tracker_genesis_gcp.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/bin/bash
if [[ $# -gt 2 ]]; then
printf "Usage: bash start_tracker_genesis_gcp.sh <GCP Username> [--keep-code|--no-keep-code]\n"
printf "Example: bash start_tracker_genesis_gcp.sh gcp_user --keep-code\n"
printf "\n"
exit
fi
printf "\n[[[[[ start_tracker_genesis_gcp.sh ]]]]]\n\n"
GCP_USER="$1"
KEEP_CODE_OPTION="--keep-code"
if [[ $# = 2 ]]; then
if [[ $2 = '--keep-code' ]]; then
KEEP_CODE_OPTION=$2
elif [[ $2 = '--no-keep-code' ]]; then
KEEP_CODE_OPTION=$2
else
printf "Invalid option: $2\n"
exit
fi
fi
printf "GCP_USER=$GCP_USER\n"
printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n"
printf '\n'
printf 'Killing jobs..\n'
killall node
if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then
printf '\n'
printf 'Creating 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
printf '\n'
printf 'Installing node modules..\n'
INSTALL_CMD="yarn install --ignore-engines"
printf "\nINSTALL_CMD=$INSTALL_CMD\n"
eval $INSTALL_CMD
else
printf '\n'
printf 'Using old 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
printf "\nStarting up Blockchain Tracker server..\n\n"
START_CMD="nohup node --async-stack-traces tracker-server/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 Tracker server is now up!\n\n"