forked from arangodb/arangodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
startArangoDBClusterLocal.sh
executable file
·215 lines (197 loc) · 6.59 KB
/
startArangoDBClusterLocal.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
#!/bin/bash
if [ -z "$XTERM" ] ; then
XTERM=x-terminal-emulator
fi
if [ -z "$XTERMOPTIONS" ] ; then
XTERMOPTIONS="--geometry=80x43"
fi
ARANGOD=/usr/sbin/arangod
NRAGENTS=$1
if [ "$NRAGENTS" == "" ] ; then
NRAGENTS=1
fi
if [[ $(( $NRAGENTS % 2 )) == 0 ]]; then
echo Number of agents must be odd.
exit 1
fi
echo Number of Agents: $NRAGENTS
NRDBSERVERS=$2
if [ "$NRDBSERVERS" == "" ] ; then
NRDBSERVERS=2
fi
echo Number of DBServers: $NRDBSERVERS
NRCOORDINATORS=$3
if [ "$NRCOORDINATORS" == "" ] ; then
NRCOORDINATORS=1
fi
echo Number of Coordinators: $NRCOORDINATORS
if [ ! -z "$4" ] ; then
if [ "$4" == "C" ] ; then
COORDINATORCONSOLE=1
echo Starting one coordinator in terminal with --console
fi
fi
SECONDARIES="$5"
MINP=0.5
MAXP=2.5
COMP=1000
BASE=4001
NATH=$(( $NRDBSERVERS + $NRCOORDINATORS + $NRAGENTS ))
rm -rf /tmp/cluster
mkdir /tmp/cluster
echo Starting agency ...
if [ $NRAGENTS -gt 1 ]; then
for aid in `seq 0 $(( $NRAGENTS - 2 ))`; do
port=$(( $BASE + $aid ))
${ARANGOD} \
--agency.id $aid \
--agency.compaction-step-size $COMP \
--agency.election-timeout-min $MINP \
--agency.election-timeout-max $MAXP \
--agency.size $NRAGENTS \
--agency.supervision true \
--agency.wait-for-sync false \
--database.directory /tmp/cluster/data$port \
--javascript.app-path /tmp/cluster/jsapps$port \
--javascript.v8-contexts 1 \
--log.file /tmp/cluster/$port.log \
--server.authentication false \
--server.endpoint tcp:https://127.0.0.1:$port \
--server.statistics false \
--server.threads $NATH \
--log.force-direct true \
> /tmp/cluster/$port.stdout 2>&1 &
done
fi
for aid in `seq 0 $(( $NRAGENTS - 1 ))`; do
endpoints="$endpoints --agency.endpoint tcp:https://localhost:$(( $BASE + $aid ))"
done
${ARANGOD} \
$endpoints \
--agency.id $(( $NRAGENTS - 1 )) \
--agency.compaction-step-size $COMP \
--agency.election-timeout-min $MINP \
--agency.election-timeout-max $MAXP \
--agency.notify true \
--agency.size $NRAGENTS \
--agency.supervision true \
--agency.wait-for-sync false \
--database.directory /tmp/cluster/data$(( $BASE + $aid )) \
--javascript.app-path /tmp/cluster/jsapps$port \
--javascript.v8-contexts 1 \
--log.file /tmp/cluster/$(( $BASE + $aid )).log \
--server.authentication false \
--server.endpoint tcp:https://127.0.0.1:$(( $BASE + $aid )) \
--server.statistics false \
--server.threads 4 \
--log.force-direct true \
> /tmp/cluster/$(( $BASE + $aid )).stdout 2>&1 &
start() {
if [ "$1" == "dbserver" ]; then
ROLE="PRIMARY"
elif [ "$1" == "coordinator" ]; then
ROLE="COORDINATOR"
sleep 1
fi
TYPE=$1
PORT=$2
mkdir /tmp/cluster/data$PORT
echo Starting $TYPE on port $PORT
${ARANGOD} --database.directory /tmp/cluster/data$PORT \
--cluster.agency-endpoint tcp:https://127.0.0.1:$BASE \
--cluster.my-address tcp:https://127.0.0.1:$PORT \
--server.endpoint tcp:https://127.0.0.1:$PORT \
--cluster.my-local-info $TYPE:127.0.0.1:$PORT \
--cluster.my-role $ROLE \
--log.file /tmp/cluster/$PORT.log \
--log.level info \
--javascript.app-path /tmp/cluster/jsapps$port \
--server.statistics true \
--server.threads 5 \
--server.authentication false \
--log.force-direct true \
> /tmp/cluster/$PORT.stdout 2>&1 &
}
startTerminal() {
if [ "$1" == "dbserver" ]; then
ROLE="PRIMARY"
elif [ "$1" == "coordinator" ]; then
ROLE="COORDINATOR"
fi
TYPE=$1
PORT=$2
mkdir /tmp/cluster/data$PORT
echo Starting $TYPE on port $PORT
$XTERM $XTERMOPTIONS -e ${ARANGOD} \
--database.directory /tmp/cluster/data$PORT \
--cluster.agency-endpoint tcp:https://127.0.0.1:$BASE \
--cluster.my-address tcp:https://127.0.0.1:$PORT \
--server.endpoint tcp:https://127.0.0.1:$PORT \
--cluster.my-local-info $TYPE:127.0.0.1:$PORT \
--cluster.my-role $ROLE \
--javascript.app-path /tmp/cluster/jsapps$port \
--log.file /tmp/cluster/$PORT.log \
--log.level info \
--server.statistics true \
--server.threads 5 \
--server.authentication false \
--console &
}
PORTTOPDB=`expr 8629 + $NRDBSERVERS - 1`
for p in `seq 8629 $PORTTOPDB` ; do
start dbserver $p
done
PORTTOPCO=`expr 8530 + $NRCOORDINATORS - 1`
for p in `seq 8530 $PORTTOPCO` ; do
if [ $p == "8530" -a ! -z "$COORDINATORCONSOLE" ] ; then
startTerminal coordinator $p
else
start coordinator $p
fi
done
echo Waiting for cluster to come up...
testServer() {
PORT=$1
while true ; do
curl -s -f -X GET "http:https://127.0.0.1:$PORT/_api/version" > /dev/null 2>&1
if [ "$?" != "0" ] ; then
echo Server on port $PORT does not answer yet.
else
echo Server on port $PORT is ready for business.
break
fi
sleep 1
done
}
for p in `seq 8629 $PORTTOPDB` ; do
testServer $p
done
for p in `seq 8530 $PORTTOPCO` ; do
testServer $p
done
if [ -n "$SECONDARIES" ]; then
let index=1
PORTTOPSE=`expr 8729 + $NRDBSERVERS - 1`
for PORT in `seq 8729 $PORTTOPSE` ; do
mkdir /tmp/cluster/data$PORT
CLUSTER_ID="Secondary$index"
echo Registering secondary $CLUSTER_ID for "DBServer$index"
curl -f -X PUT --data "{\"primary\": \"DBServer$index\", \"oldSecondary\": \"none\", \"newSecondary\": \"$CLUSTER_ID\"}" -H "Content-Type: application/json" localhost:8530/_admin/cluster/replaceSecondary
echo Starting Secondary $CLUSTER_ID on port $PORT
${ARANGOD} --database.directory /tmp/cluster/data$PORT \
--cluster.agency-endpoint tcp:https://127.0.0.1:$BASE \
--cluster.my-address tcp:https://127.0.0.1:$PORT \
--server.endpoint tcp:https://127.0.0.1:$PORT \
--cluster.my-id $CLUSTER_ID \
--javascript.app-path /tmp/cluster/jsapps$port \
--log.file /tmp/cluster/$PORT.log \
--server.statistics true \
--server.authentication false \
> /tmp/cluster/$PORT.stdout 2>&1 &
let index=$index+1
done
fi
echo Done, your cluster is ready at
for p in `seq 8530 $PORTTOPCO` ; do
echo " arangosh --server.authentication false --server.endpoint tcp:https://127.0.0.1:$p"
done