forked from arangodb/arangodb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartLocalCluster.ps1
128 lines (117 loc) · 3.65 KB
/
startLocalCluster.ps1
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
param(
[int] $AgentCount = 1,
[int] $CoordinatorCount = 1,
[int] $DBServerCount = 2,
[int] $AgentStartPort = 4001,
[int] $CoordinatorStartPort = 8530,
[int] $DBServerStartPort = 8629,
[string] $JwtSecret = ""
)
$commonArguments = @(
"-c", "none",
"--javascript.app-path=.\js\apps",
"--javascript.startup-directory=.\js",
"--javascript.module-directory=.\enterprise\js",
"--log.force-direct=true"
)
if ($JwtSecret) {
$commonArguments += "--server.authentication=true","--server.jwt-secret=$JwtSecret"
} else {
$commonArguments += "--server.authentication=false"
}
$ports=@()
Remove-Item -Recurse -Force cluster | Out-Null
New-Item -Path cluster -Force -ItemType Directory | Out-Null
$agentArguments = @(
"--agency.activate=true",
"--agency.supervision=true",
"--agency.size=$AgentCount",
"--javascript.v8-contexts=1",
"--server.statistics=false",
"--agency.endpoint=tcp://[::1]:$AgentStartPort"
)
$processes = @()
$agentArguments += $commonArguments
for ($i=0;$i -lt $AgentCount;$i++) {
$port = $AgentStartPort + $i
$ports+=$port
Write-Host "Starting AGENT on $port"
$arguments = @(
"--agency.my-address=tcp://[::1]:$port",
"--database.directory=cluster\data$port",
"--log.file=cluster\$port.log",
"--server.endpoint=tcp://[::1]:$port"
)
$arguments += $agentArguments
$processes += Start-Process `
-RedirectStandardError "cluster\$port.err" `
-RedirectStandardOutput "cluster\$port.out" `
-FilePath .\build\bin\arangod.exe `
-ArgumentList $arguments `
-NoNewWindow `
-PassThru
}
$map=@{
"COORDINATOR"= @{
"count"= $CoordinatorCount;
"startport"= $CoordinatorStartPort
}
"PRIMARY"= @{
"count"= $DBServerCount;
"startport"= $DBServerStartPort
}
}
foreach ($it in $map.GetEnumerator()) {
$role = $it.Key
$struct = $it.Value
for ($i=0;$i -lt $struct.count;$i++) {
$port = $struct.startport + $i
$ports+=$port
$roleArguments = @(
"--cluster.agency-endpoint=tcp://[::1]:$AgentStartPort",
"--cluster.my-role=$role",
"--cluster.my-address=tcp://[::1]:$port",
"--database.directory=cluster\data$port",
"--server.endpoint=tcp://[::1]:$port",
"--log.file=cluster\$port.log"
)
$roleArguments += $commonArguments
Write-Host "Starting $role on $port"
$processes += Start-Process `
-RedirectStandardError "cluster\$port.err" `
-RedirectStandardOutput "cluster\$port.out" `
-FilePath .\build\bin\arangod.exe `
-ArgumentList $roleArguments `
-NoNewWindow `
-PassThru
}
}
while ($ports -gt 0) {
$newPorts=@()
foreach ($port in $ports) {
try {
$InvokeWebRequestArgs = @{
"TimeoutSec"=1;
"UseBasicParsing"=true;
"URI"="http://[::1]:$port/_api/version";
}
if ($JwtSecret) {
$InvokeWebRequestArgs["Headers"] = @{"Authorization"="bearer $(jwtgen -a HS256 -s $JwtSecret -c 'iss=arangodb' -c 'server_id=setup')"}
}
$req=Invoke-WebRequest @InvokeWebRequestArgs
Write-Host "$port became ready!"
} catch {
$newPorts += $port;
}
}
$ports=$newPorts
if ($ports -gt 0) {
Write-Host -NoNewline "."
Start-Sleep -Seconds 1
}
}
Write-Host ""
Write-Host "ArangoDB Cluster is ready!"
Write-Host "Connect using an arangosh:"
Write-Host ""
Write-Host " .\build\bin\arangosh --server.endpoint=tcp://[::1]:$CoordinatorStartPort"