-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcontrol.sh
More file actions
executable file
·206 lines (171 loc) · 5.25 KB
/
control.sh
File metadata and controls
executable file
·206 lines (171 loc) · 5.25 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
DEFAULT_ENVFILE="$(dirname $0)/defaults.env"
ENVFILE=${ENVFILE:-"$DEFAULT_ENVFILE"}
### Define or load default variables
WORKING_DIR=${WORKING_DIR:-$(realpath $(dirname $0))}
TEMPLATES_DIR=${TEMPLATES_DIR:-$(realpath $(dirname $0)/templates/)}
OUTPUT_DIR=${OUTPUT_DIR:-$(realpath $(dirname $0)/configfiles)}
source $ENVFILE
###
### Source scripts under scripts directory
. $(dirname $0)/scripts/helper_functions.sh
. $(dirname $0)/scripts/gen_valkeys.sh
###
USAGE="$(basename $0) is the main control script for the testnet.
Usage : $(basename $0) <action> <arguments>
Actions:
start --val-num|-n <num of validators>
Starts a network with <num_validators>
configure --val-num|-n <num of validators>
configures a network with <num_validators>
stop
Stops the running network
clean
Cleans up the configuration directories of the network
status
Prints the status of the network
"
function help()
{
echo "$USAGE"
}
function generate_network_configs()
{
nvals=$1
echo "Generating network configuration for $nvals validators..."
generate_keys_and_configs $nvals
dockercompose_testnet_generator $nvals ${OUTPUT_DIR}
echo " done!"
}
function start_network()
{
nvals=$1
echo "Starting network with $nvals validators..."
# check if the network exists and create it
existing_net=$( docker network ls --filter=name="^$TESTNET_NAME$" --format={{.Name}})
if [ -z "$existing_net" ]; then
docker network create ${TESTNET_NAME}
fi
if [[ -n "$UNL_MANAGER_ENABLE" && "$UNL_MANAGER_ENABLE" == true ]]; then
if [[ ! -e ${UNL_SCENARIO_FILE} ]] ; then
echo " ERROR: ${UNL_SCENARIO_FILE} does not exist!!!"
fi;
if [[ ! -e ${OUTPUT_DIR}/unl-manager/validator-token.txt ]] ; then
echo " ERROR: ${OUTPUT_DIR}/unl-manager/validator-token.txt does not exist!!!"
fi;
# Run UNL manager containers
echo "Running UNL manager containers..."
BASE_DIR=$WORKING_DIR/xrpl-unl-manager \
TESTNET_NAME=${TESTNET_NAME} \
VALIDATORS_KEYS_PATH=${OUTPUT_DIR} \
UNL_PUBLISHER_CONTAINER_NAME=${UNL_PUBLISHER_CONTAINER_NAME} \
UNL_SCENARIO_FILE=${UNL_SCENARIO_FILE} \
UNL_MANAGER_KEYFILE=${OUTPUT_DIR}/unl-manager/validator-token.txt \
${WORKING_DIR}/xrpl-unl-manager/start_UNL_manager_services.sh
echo " Done!"
fi;
# TESTNET_NAME=$TESTNET_NAME docker-compose -f docker-compose-testnet.yml up -d
echo "Starting the testnet..."
TESTNET_NAME=${TESTNET_NAME} CONFIGFILES=${OUTPUT_DIR} IMAGE_TAG=${IMAGE_TAG} docker-compose -f ${WORKING_DIR}/${COMPOSE_FILENAME} up -d
echo "Waiting for everything to come up..."
sleep 10
echo "Triggering statsd with inetdd"
docker exec -it xrpl-validator-genesis sh -c "inetd"
for (( i=0; i<"${VAL_NUM}"; i++ ))
do
docker exec -it ${VAL_NAME_PREFIX}$i sh -c "inetd"
done
# setup exporter
echo "Setup exporter in each validator"
docker exec -d ${VAL_NAME_PREFIX}genesis sh -c "python3 exporters/server_info/server_info.py"
for (( i=0; i<"${VAL_NUM}"; i++ ))
do
docker exec -d ${VAL_NAME_PREFIX}$i sh -c "python3 exporters/server_info/server_info.py"
done
echo " network started!"
}
function stop_network()
{
echo "Stopping network..."
# TESTNET_NAME=$TESTNET_NAME docker-compose -f docker-compose-testnet.yml down
CONFIGFILES=${OUTPUT_DIR} IMAGE_TAG=${IMAGE_TAG} TESTNET_NAME=$TESTNET_NAME docker-compose -f ${WORKING_DIR}/${COMPOSE_FILENAME} down
if [[ -n "$UNL_MANAGER_ENABLE" && "$UNL_MANAGER_ENABLE" == true ]]; then
# Stop UNL manager
TESTNET_NAME=$TESTNET_NAME docker-compose -f ${WORKING_DIR}/xrpl-unl-manager/docker/docker-compose.yml down
fi;
#if [[ -n $TESTNET_NAME ]]; then
# running_testnet=$TESTNET_NAME
#else
# running_testnet=$(docker network ls --filter=name=${TESTNET_NAME} --format "{{.Name}}" | head -n 1)
#fi;
#if [[ -n $running_testnet ]] ; then
# echo "Found a running ripple-testnet. Removing..."
# docker network rm $running_testnet
#fi;
echo " stopped!"
}
function print_status()
{
echo "Printing status of the network..."
# TESTNET_NAME=$TESTNET_NAME docker-compose -f docker-compose-testnet.yml status
CONFIGFILES=${OUTPUT_DIR} IMAGE_TAG=${IMAGE_TAG} TESTNET_NAME=$TESTNET_NAME docker-compose -f ${WORKING_DIR}/${COMPOSE_FILENAME} ps
echo " Finished!"
}
function do_cleanup()
{
echo "Cleaning up network configuration..."
# rm -rf ${DEPLOYMENT_DIR}/*
set -x
rm -rf ${OUTPUT_DIR}/*
rm ${WORKING_DIR}/${COMPOSE_FILENAME}
set +x
echo " clean up finished!"
}
ARGS="$@"
if [ $# -lt 1 ]
then
#echo "No args"
help
exit 1
fi
while [ "$1" != "" ]; do
case $1 in
"start" ) shift
while [ "$1" != "" ]; do
case $1 in
-n|--val-num ) shift
VAL_NUM=$1
;;
esac
shift
done
start_network $VAL_NUM
exit
;;
"configure" ) shift
while [ "$1" != "" ]; do
case $1 in
-n|--val-num ) shift
VAL_NUM=$1
;;
esac
shift
done
generate_network_configs $VAL_NUM
exit
;;
"stop" ) shift
stop_network
exit
;;
"status" ) shift
print_status
exit
;;
"clean" ) shift
do_cleanup
exit
;;
esac
shift
done