-
Notifications
You must be signed in to change notification settings - Fork 347
/
tessera-start-remote.sh
executable file
·272 lines (231 loc) · 7.93 KB
/
tessera-start-remote.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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#!/bin/bash
set -u
set -e
function usage() {
echo ""
echo "Usage:"
echo " $0 [--tesseraJar path to Tessera jar file] [--remoteDebug] [--jvmParams \"JVM parameters\"] [--remoteEnclaves <number of remote enclaves>]"
echo ""
echo "Where:"
echo " --tesseraJar specifies path to the jar file, default is to use the vagrant location"
echo " --remoteDebug enables remote debug on port 500n for each Tessera node (for use with JVisualVm etc)"
echo " --jvmParams specifies parameters to be used by JVM when running Tessera"
echo " --remoteEnclaves specifies the number of nodes that should be using a remote enclave"
echo "Notes:"
echo " - Tessera/Enclave .jar and extracted .tar dists supported."
echo " Tessera jar location defaults to ${tesseraJarDefault}."
echo " Tessera extracted runscript location defaults to ${tesseraScriptDefault}."
echo " Enclave jar location defaults to ${enclaveJarDefault};"
echo " Enclave extracted runscript location defaults to ${enclaveScriptDefault};"
echo " Environment variables TESSERA_JAR, TESSERA_SCRIPT, ENCLAVE_JAR, and ENCLAVE_SCRIPT can be used to override these defaults."
echo ""
exit -1
}
defaultNumberOfRemoteEnclaves=4
tesseraJarDefault="/home/vagrant/tessera/tessera.jar"
tesseraScriptDefault="/home/vagrant/tessera/tessera/bin/tessera"
enclaveJarDefault="/home/vagrant/tessera/enclave.jar"
enclaveScriptDefault="/home/vagrant/tessera/enclave-jaxrs/bin/enclave-jaxrs"
tesseraJar=${TESSERA_JAR:-$tesseraJarDefault}
tesseraScript=${TESSERA_SCRIPT:-$tesseraScriptDefault}
enclaveJar=${ENCLAVE_JAR:-$enclaveJarDefault}
enclaveScript=${ENCLAVE_SCRIPT:-$enclaveScriptDefault}
numberOfRemoteEnclaves=${defaultNumberOfRemoteEnclaves}
remoteDebug=false
jvmParams=
while (( "$#" )); do
case "$1" in
--tesseraJar)
tesseraJar=$2
shift 2
;;
--remoteEnclaves)
numberOfRemoteEnclaves=$2
shift 2
;;
--enclaveJar)
enclaveJar=$2
shift 2
;;
--remoteDebug)
remoteDebug=true
shift
;;
--jvmParams)
jvmParams=$2
shift 2
;;
--help)
shift
usage
;;
*)
echo "Error: Unsupported command line parameter $1"
usage
;;
esac
done
if [ ! -f "${tesseraJar}" ] && [ ! -f "${tesseraScript}" ]; then
echo "ERROR: no Tessera jar or executable script found at ${tesseraJar} or ${tesseraScript}. Use TESSERA_JAR or TESSERA_SCRIPT env vars to specify the path to an executable jar or script."
exit -1
fi
if [ ! -f "${enclaveJar}" ] && [ ! -f "${enclaveScript}" ]; then
echo "ERROR: no Tessera Enclave jar or executable script found at ${enclaveJar} or ${enclaveScript}. Use ENCLAVE_JAR or ENCLAVE_SCRIPT env vars to specify the path to an executable jar or script."
exit -1
fi
if [ -f "${tesseraJar}" ]; then
TESSERA_VERSION=$(unzip -p $tesseraJar META-INF/MANIFEST.MF | grep Tessera-Version | cut -d" " -f2)
else
TESSERA_VERSION=$($tesseraScript version)
fi
echo "Tessera version: $TESSERA_VERSION"
TESSERA_CONFIG_TYPE="-09-"
#if the Tessera version is 0.10, use this config version
if [ "$TESSERA_VERSION" \> "0.10" ] || [ "$TESSERA_VERSION" == "0.10" ]; then
TESSERA_CONFIG_TYPE="-09-"
fi
echo "Config type $TESSERA_CONFIG_TYPE"
# Order of operation:
# Start up the remote enclaves
# Wait for remote enclaves to finish startup
# Start up remote enclave enabled transaction managers
# Start up local enclave transaction managers
# Wait for all transaction managers to finish startup
#Start up all remote enclaves (from node 1 to numberOfRemoteEnclaves)
for ((i=1;i<=numberOfRemoteEnclaves;i++));
do
DDIR="qdata/c$i"
mkdir -p ${DDIR}
mkdir -p qdata/logs
rm -f "$DDIR/tm.ipc"
DEBUG=""
if [ "$remoteDebug" == "true" ]; then
DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=501$i -Xdebug"
fi
#Only set heap size if not specified on command line
MEMORY=
if [[ ! "$jvmParams" =~ "Xm" ]]; then
MEMORY="-Xms128M -Xmx128M"
fi
if [ -f "${enclaveJar}" ]; then
enclaveExec="java $jvmParams $DEBUG $MEMORY -jar ${enclaveJar}"
else
export JAVA_OPTS="$jvmParams $DEBUG $MEMORY"
enclaveExec=${enclaveScript}
fi
CMD="${enclaveExec} -configfile $DDIR/enclave$TESSERA_CONFIG_TYPE$i.json"
echo "$CMD >> qdata/logs/enclave$i.log 2>&1 &"
${CMD} >> "qdata/logs/enclave$i.log" 2>&1 &
sleep 1
done
#Wait until all Enclaves are running
echo "Waiting until all Tessera enclaves are running..."
DOWN=true
k=10
while ${DOWN}; do
sleep 1
DOWN=false
for ((i=1;i<=numberOfRemoteEnclaves;i++));
do
set +e
result=$(curl -s http://localhost:918${i}/ping)
set -e
if [ ! "${result}" == "STARTED" ]; then
echo "Enclave ${i} is not yet listening on http"
DOWN=true
fi
done
k=$((k - 1))
if [ ${k} -le 0 ]; then
echo "Tessera is taking a long time to start. Look at the Tessera logs in qdata/logs/ for help diagnosing the problem."
fi
echo "Waiting until all Tessera enclaves are running..."
sleep 5
done
#Startup all remote enclave Transaction Managers (from nodes 1 to numberOfRemoteEnclaves)
currentDir=`pwd`
for ((i=1;i<=numberOfRemoteEnclaves;i++));
do
DDIR="qdata/c$i"
mkdir -p ${DDIR}
mkdir -p qdata/logs
rm -f "$DDIR/tm.ipc"
DEBUG=""
if [ "$remoteDebug" == "true" ]; then
DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=500$i -Xdebug"
fi
#Only set heap size if not specified on command line
MEMORY=
if [[ ! "$jvmParams" =~ "Xm" ]]; then
MEMORY="-Xms128M -Xmx128M"
fi
if [ -f "${tesseraJar}" ]; then
tesseraExec="java $jvmParams $DEBUG $MEMORY -jar ${tesseraJar}"
else
export JAVA_OPTS="$jvmParams $DEBUG $MEMORY"
tesseraExec=${tesseraScript}
fi
CMD="${tesseraExec} -configfile $DDIR/tessera-config-enclave$TESSERA_CONFIG_TYPE$i.json"
echo "$CMD >> qdata/logs/tessera$i.log 2>&1 &"
${CMD} >> "qdata/logs/tessera$i.log" 2>&1 &
sleep 1
done
#Startup all local enclave Transaction Managers (from nodes numberOfRemoteEnclaves+1 to 7)
for ((i=numberOfRemoteEnclaves+1;i<=7;i++));
do
DDIR="qdata/c$i"
mkdir -p ${DDIR}
mkdir -p qdata/logs
rm -f "$DDIR/tm.ipc"
DEBUG=""
if [ "$remoteDebug" == "true" ]; then
DEBUG="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=500$i -Xdebug"
fi
#Only set heap size if not specified on command line
MEMORY=
if [[ ! "$jvmParams" =~ "Xm" ]]; then
MEMORY="-Xms128M -Xmx128M"
fi
if [ -f "${tesseraJar}" ]; then
tesseraExec="java $jvmParams $DEBUG $MEMORY -jar ${tesseraJar}"
else
export JAVA_OPTS="$jvmParams $DEBUG $MEMORY"
tesseraExec=${tesseraScript}
fi
CMD="${tesseraExec} -configfile $DDIR/tessera-config$TESSERA_CONFIG_TYPE$i.json"
echo "$CMD >> qdata/logs/tessera$i.log 2>&1 &"
${CMD} >> "qdata/logs/tessera$i.log" 2>&1 &
sleep 1
done
#Wait until all 7 transaction managers are running
echo "Waiting until all Tessera nodes are running..."
DOWN=true
k=10
while ${DOWN}; do
sleep 1
DOWN=false
for ((i=1;i<=7;i++));
do
if [ ! -S "qdata/c${i}/tm.ipc" ]; then
echo "Node ${i} is not yet listening on tm.ipc"
DOWN=true
fi
set +e
#NOTE: if using https, change the scheme
#NOTE: if using the IP whitelist, change the host to an allowed host
result=$(curl -s http://localhost:900${i}/upcheck)
set -e
if [ ! "${result}" == "I'm up!" ]; then
echo "Node ${i} is not yet listening on http"
DOWN=true
fi
done
k=$((k - 1))
if [ ${k} -le 0 ]; then
echo "Tessera is taking a long time to start. Look at the Tessera logs in qdata/logs/ for help diagnosing the problem."
fi
echo "Waiting until all Tessera nodes are running..."
sleep 5
done
echo "All Tessera nodes started"
exit 0