-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.sh
58 lines (50 loc) · 1.71 KB
/
test.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
#!/bin/bash
# ^^^^ - NOT /bin/sh, as this code uses arrays
#
# How to run this script:
#
# bash test.sh <IP_ADDRESS> <STARTING_PORT> <NUMBER_OF_NODES> [JOIN_IP:PORT]
# (e.g.) bash test.sh 141.84.15.12 10000 5 141.84.15.12:11111
PIDS=()
# define cleanup function
cleanup() {
for pid in "${PIDS[@]}"; do
kill -0 "$pid" && kill "$pid" # kill process only if it's still running
done
}
# and set that function to run before we exit, or specifically when we get a SIGTERM
trap cleanup EXIT SIGTERM
PROJECT_BUILD="/target/debug/hll-rust"
TEST_IP=$1
STARTING_PORT=$2
NUMBER_OF_NODES=$3
JOIN_IP=$4
cargo build
if [[ -z "$JOIN_IP" ]]
then
echo "Creating a new chord circle with $NUMBER_OF_NODES nodes..."
.${PROJECT_BUILD} ${TEST_IP} ${STARTING_PORT} > /dev/null 2>&1 & PIDS+=( "$!" )
for i in `seq 1 $(($NUMBER_OF_NODES-1))`
do
sleep .5
if (($i == $(($NUMBER_OF_NODES-1))))
then
.${PROJECT_BUILD} ${TEST_IP} $(($STARTING_PORT+$i)) ${TEST_IP}:${STARTING_PORT} & PIDS+=( "$!" )
else
.${PROJECT_BUILD} ${TEST_IP} $(($STARTING_PORT+$i)) ${TEST_IP}:${STARTING_PORT} > /dev/null 2>&1 & PIDS+=( "$!" )
fi
done
else
echo "Creating $NUMBER_OF_NODES Nodes and joining them on $JOIN_IP..."
for i in `seq 0 $(($NUMBER_OF_NODES-1))`
do
sleep .5
if (($i == $(($NUMBER_OF_NODES-1))))
then
.${PROJECT_BUILD} ${TEST_IP} $(($STARTING_PORT+$i)) ${JOIN_IP} & PIDS+=( "$!" )
else
.${PROJECT_BUILD} ${TEST_IP} $(($STARTING_PORT+$i)) ${JOIN_IP} > /dev/null 2>&1 & PIDS+=( "$!" )
fi
done
fi
wait