-
Notifications
You must be signed in to change notification settings - Fork 2
/
run-vaults.bash
executable file
·128 lines (110 loc) · 4.67 KB
/
run-vaults.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
## Currently, this script runs vaults on localhost (since that's the default if no IP address is given to the vaults)
## for the purposes of testing
# ****************************** The following can be modified as needed **********************************************
# 0 => No user interaction. The script will use the values set in the config variable below or defaults in some cases.
# 1 => User interaction turned on. The script will ask the values from the user in an interactive fashion.
INTERACTIVE=1;
# ------ Config options: Modify these to change the defaults and specially if using the non-interactive mode ------
# 0 => No debug output from the script.
# 1 => Debug output from the script.
DEBUG=1;
# Interval in seconds between starting of the vaults.
INTERVAL_BETWEEN_VAULTS=5;
# The directory containing the output directories for all the vaults started by this script.
VAULTS_GRP_DIR="./vaults";
# Number of vaults to spawn with the first one being the genesis. This number should be greater than 0.
NUM_VAULTS=8;
# Path to the vault executable file. This should include the file name too, not just the path to the directory as no
# assumption is made on the name of the executable (and hence must be provided by the user).
VAULT_EXE="./safe_vault";
# Vebosity level for vault logs.
# <blank> => log error.
# -v => log error, warn.
# -vv => log error, warn, info.
# -vvv => log error, warn, info, debug.
# -vvvv => log error, warn, info, debug, trace.
VAULT_LOGGING_VERBOSITY="-vv";
# *********************************************************************************************************************
# *********************************************************************************************************************
if [[ ${INTERACTIVE} != 0 ]]; then
read -p "Group directory for all vaults [default = ${VAULTS_GRP_DIR}]: " VAULTS_GRP_DIR_INPUT;
if [[ "${VAULTS_GRP_DIR_INPUT}" != "" ]]; then
VAULTS_GRP_DIR="${VAULTS_GRP_DIR_INPUT}";
fi
fi
mkdir -p "${VAULTS_GRP_DIR}";
regex_check_num='^[0-9]+$';
if [[ ${INTERACTIVE} != 0 ]]; then
read -p "Total number of vaults to run [default = ${NUM_VAULTS}]: " NUM_VAULTS_INPUT;
if [[ "${NUM_VAULTS_INPUT}" != "" ]]; then
NUM_VAULTS="${NUM_VAULTS_INPUT}";
fi
fi
if [[ ! ${NUM_VAULTS} =~ ${regex_check_num} ]]; then
printf 'ERROR: Unable to parse the number of vaults to run as a number.\n';
exit 1;
fi
if [[ ${NUM_VAULTS} < 1 ]]; then
printf 'No vaults to run.\n'
exit 0;
fi
regex_check_verbosity='^-v{,4}$';
if [[ ${INTERACTIVE} != 0 ]]; then
read -p 'Vault logging verbosity [check config section of this script for description]: ' VAULT_LOGGING_VERBOSITY;
if [[ "${VAULT_LOGGING_VERBOSITY}" != "" && ! "${VAULT_LOGGING_VERBOSITY}" =~ ${regex_check_verbosity} ]]; then
printf 'ERROR: Invalid verbosity specified. It must be either left blank or one of -v, -vv, -vvv or -vvvv.\n';
exit 1;
fi
fi
if [[ ${INTERACTIVE} != 0 ]]; then
read -p "Full path to safe_vault executable [default = ${VAULT_EXE}]: " VAULT_EXE_INPUT;
if [[ "${VAULT_EXE_INPUT}" != "" ]]; then
VAULT_EXE="${VAULT_EXE_INPUT}";
fi
fi
if [[ ! -f "${VAULT_EXE}" ]]; then
printf 'ERROR: The given path does not correspond to a vault executable: %s\n' "${VAULT_EXE}";
exit 1;
fi
if [[ ${DEBUG} != 0 ]]; then
printf 'Running genesis vault: %s\n' "${VAULT_EXE}";
fi
root_dir="${VAULTS_GRP_DIR}"/safe-vault-genesis;
mkdir -p "${root_dir}";
nohup "${VAULT_EXE}" "${VAULT_LOGGING_VERBOSITY}" --first --root-dir="${root_dir}" &> "${root_dir}"/vault.stdout &
if [[ ${DEBUG} != 0 ]]; then
printf 'Waiting for genesis vault to start up...\n';
fi
sleep 2;
hcc="$(grep "peer_addr" "${root_dir}"/vault.stdout)";
if [[ ${hcc} == "" ]]; then
printf 'Genesis vault did not print its connection info or printed it in an unrecognised format\n.';
exit 1;
else
#Convert it into an array
hcc="[${hcc}]";
fi
if [[ ${DEBUG} != 0 ]]; then
printf 'Genesis vault started with connection-info: %s\n' "${hcc}";
fi
for((i=2; i <= ${NUM_VAULTS}; ++i)); do
if [[ ${DEBUG} != 0 ]]; then
printf '\nRunning vault number: %d in... ' ${i};
fi
for((j=${INTERVAL_BETWEEN_VAULTS}; j > 0; --j)); do
if [[ ${DEBUG} != 0 ]]; then
printf '%d ' ${j};
fi
sleep 1;
done
root_dir="${VAULTS_GRP_DIR}"/safe-vault-${i};
mkdir -p "${root_dir}";
nohup "${VAULT_EXE}" "${VAULT_LOGGING_VERBOSITY}" --root-dir="${root_dir}" --hard-coded-contacts="${hcc}" &> "${root_dir}"/vault.stdout &
if [[ ${DEBUG} != 0 ]]; then
printf '\nVault number: %d has been started.' ${i};
fi
done
if [[ ${DEBUG} != 0 ]]; then
printf '\n\nDone!\n';
fi