This repository has been archived by the owner on Nov 21, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_servers
executable file
·62 lines (48 loc) · 1.52 KB
/
start_servers
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
# Maximum number of faults that can be tolerated
F=$1
if ! [ $F -gt 0 ] 2> /dev/null; then
echo -e "Usage: $0 F\n\tF -- number of faults that can be tolerated"
exit 1
fi
# Total number of servers (n = 3f + 1)
N=$((3 * $F + 1))
LOWER_PORT=4567
UPPER_PORT=65535
servers="servers="
DIRECTORY="servers.tmp"
function clean_up {
pkill -f "io.github.diogocp.secpassman.server.Main"
}
if [ $(($N + $LOWER_PORT)) -le "$UPPER_PORT" ]; then
trap clean_up SIGTERM SIGINT
for ((i=1; i<=$N; i++)); do
port=$(($i+$LOWER_PORT))
if [ "$i" -lt "$N" ]; then
servers="${servers}localhost:$port,"
else
servers="${servers}localhost:$port"
fi
done
rm -r "$DIRECTORY/"
mkdir "$DIRECTORY"
mkdir "$DIRECTORY/certs"
for ((i=1; i<=$N; i++)); do
port=$(($i+$LOWER_PORT))
mkdir "$DIRECTORY/server_$i/"
pushd "$DIRECTORY/server_$i" > /dev/null
echo "$servers" > "config.properties"
keytool -genkey -alias server -dname "CN=server_$i" -keyalg RSA -keystore server.jks -storepass server -keypass server
keytool -exportcert -alias server -rfc -keystore server.jks -storepass server > "../certs/server_$i.pem"
echo "Starting server $i"
../../server/build/install/server/bin/server $port &
echo "Process ID: $!"
sleep 1
popd > /dev/null
done
echo "All servers started, ready!"
printf "$servers\n" > "config.properties"
wait
else
echo "Invalid number of servers"
fi