1
1
Param (
2
- [string ]$Version = " 5.2.2 " ,
2
+ [string ]$Version = " 5.3.0 " ,
3
3
[int ]$NodeCount = 1 ,
4
4
[bool ]$StartKibana = $true ,
5
5
[int ]$StartPort = 9200 ,
8
8
)
9
9
10
10
If ($env: JAVA_HOME -eq $null -Or -Not (Test-Path - Path $env: JAVA_HOME )) {
11
- Write-Error " Please ensure the latest version of java is installed and the JAVA_HOME environmental variable has been set."
12
- Return
11
+ Write-Error " Please ensure the latest version of java is installed and the JAVA_HOME environmental variable has been set."
12
+ $host.SetShouldExit (1 )
13
+ Return
13
14
}
14
15
15
16
Push-Location $PSScriptRoot
16
17
17
18
If (-Not (Test-Path - Path " elasticsearch-$Version " ) -And -Not (Test-Path - Path " elasticsearch-$Version .zip" )) {
18
- Write-Output " Downloading Elasticsearch $Version ..."
19
- Invoke-WebRequest " https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$Version .zip" - OutFile " elasticsearch-$Version .zip"
19
+ Write-Output " Downloading Elasticsearch $Version ..."
20
+ Invoke-WebRequest " https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-$Version .zip" - OutFile " elasticsearch-$Version .zip"
20
21
} Else {
21
- Write-Output " Using already downloaded Kibana $Version ..."
22
+ Write-Output " Using already downloaded Elasticsearch $Version ..."
22
23
}
23
24
24
25
If ((Test-Path - Path " elasticsearch-$Version .zip" ) -And ! (Test-Path - Path " elasticsearch-$Version " )) {
25
- Write-Output " Extracting Elasticsearch $Version ..."
26
- Add-Type - assembly " system.io.compression.filesystem"
27
- [io.compression.zipfile ]::ExtractToDirectory(" $PSScriptRoot \elasticsearch-$Version .zip" , $PSScriptRoot )
28
- Remove-Item elasticsearch- $Version.zip
26
+ Write-Output " Extracting Elasticsearch $Version ..."
27
+ Add-Type - assembly " system.io.compression.filesystem"
28
+ [io.compression.zipfile ]::ExtractToDirectory(" $PSScriptRoot \elasticsearch-$Version .zip" , $PSScriptRoot )
29
+ Remove-Item elasticsearch- $Version.zip
29
30
} Else {
30
- Write-Output " Using already downloaded and extracted Elasticsearch $Version ..."
31
+ Write-Output " Using already downloaded and extracted Elasticsearch $Version ..."
31
32
}
32
33
33
34
For ($i = 1 ; $i -le $NodeCount ; $i ++ ) {
34
- $nodePort = $StartPort + $i - 1
35
- Write-Output " Starting Elasticsearch $Version node $i port $nodePort "
36
- If (-Not (Test-Path - Path " .\elasticsearch-$Version -node$i " )) {
37
- Copy-Item .\elasticsearch- $Version .\elasticsearch- $Version - node$i - Recurse
38
- Copy-Item .\elasticsearch.yml .\elasticsearch- $Version - node$i \config - Force
39
- Add-Content .\elasticsearch- $Version - node$i \config\elasticsearch.yml " `n http.port: $nodePort "
35
+ $nodePort = $StartPort + $i - 1
36
+ Write-Output " Starting Elasticsearch $Version node $i port $nodePort "
37
+ If (-Not (Test-Path - Path " .\elasticsearch-$Version -node$i " )) {
38
+ Copy-Item .\elasticsearch- $Version .\elasticsearch- $Version - node$i - Recurse
39
+ Copy-Item .\elasticsearch.yml .\elasticsearch- $Version - node$i \config - Force
40
+ Add-Content .\elasticsearch- $Version - node$i \config\elasticsearch.yml " `n http.port: $nodePort "
41
+
42
+ Invoke-Expression " .\elasticsearch-$Version -node$i \bin\elasticsearch-plugin.bat install mapper-size"
43
+ if ($LastExitCode -ne 0 ) {
44
+ $host.SetShouldExit ($LastExitCode )
45
+ Return
40
46
}
47
+ }
41
48
42
- If ($ResetData -And (Test-Path - Path " $ ( Get-Location ) \elasticsearch-$Version -node$i \data" )) {
43
- Write-Output " Resetting node $i data..."
44
- Remove-Item " $ ( Get-Location ) \elasticsearch-$Version -node$i \data" - Recurse - ErrorAction Ignore
45
- }
49
+ If ($ResetData -And (Test-Path - Path " $ ( Get-Location ) \elasticsearch-$Version -node$i \data" )) {
50
+ Write-Output " Resetting node $i data..."
51
+ Remove-Item " $ ( Get-Location ) \elasticsearch-$Version -node$i \data" - Recurse - ErrorAction Ignore
52
+ }
46
53
47
- Start-Process " $ ( Get-Location ) \elasticsearch-$Version -node$i \bin\elasticsearch.bat"
54
+ Start-Process " $ ( Get-Location ) \elasticsearch-$Version -node$i \bin\elasticsearch.bat"
48
55
49
- $attempts = 0
50
- Do {
51
- If ($attempts -gt 0 ) {
52
- Start-Sleep - s 2
53
- }
54
-
55
- Write-Host " Waiting for Elasticsearch $Version node $i to respond..."
56
- $res = $null
56
+ $attempts = 0
57
+ $success = $false
58
+ Do {
59
+ If ($attempts -gt 0 ) {
60
+ Start-Sleep - s 2
61
+ }
57
62
58
- Try {
59
- $res = Invoke-WebRequest http:// localhost:$nodePort - UseBasicParsing
60
- } Catch {}
61
- $attempts = $attempts + 1
62
- } Until ($res -ne $null -And $res.StatusCode -eq 200 -And $attempts -lt 25 )
63
+ Write-Host " Waiting for Elasticsearch $Version node $i to respond ($attempts )..."
64
+ $res = $null
65
+
66
+ Try {
67
+ $res = Invoke-WebRequest http:// localhost:$nodePort - UseBasicParsing
68
+ If ($res -ne $null -And $res.StatusCode -eq 200 ) {
69
+ $success = $true
70
+ Break
71
+ }
72
+ } Catch {}
73
+ $attempts = $attempts + 1
74
+ } Until ($attempts -gt 15 )
75
+
76
+ If ($success -eq $false ) {
77
+ Write-Error " Failed to start Elasticsearch $Version node $i ."
78
+ $host.SetShouldExit ($LastExitCode )
79
+ Return
80
+ }
63
81
}
64
82
65
83
If ($StartKibana -eq $true ) {
66
- If (-Not (Test-Path - Path " kibana-$Version " ) -And -Not (Test-Path - Path " kibana-$Version .zip" )) {
67
- Write-Output " Downloading Kibana $Version ..."
68
- Invoke-WebRequest " https://artifacts.elastic.co/downloads/kibana/kibana-$Version -windows-x86.zip" - OutFile " kibana-$Version .zip"
69
- } Else {
70
- Write-Output " Using already downloaded Kibana $Version ..."
71
- }
84
+ If (-Not (Test-Path - Path " kibana-$Version " ) -And -Not (Test-Path - Path " kibana-$Version .zip" )) {
85
+ Write-Output " Downloading Kibana $Version ..."
86
+ Invoke-WebRequest " https://artifacts.elastic.co/downloads/kibana/kibana-$Version -windows-x86.zip" - OutFile " kibana-$Version .zip"
87
+ } Else {
88
+ Write-Output " Using already downloaded Kibana $Version ..."
89
+ }
72
90
73
- If ((Test-Path - Path " kibana-$Version .zip" ) -And -Not (Test-Path - Path " kibana-$Version " )) {
74
- Write-Output " Extracting Kibana $Version ..."
75
- Add-Type - assembly " system.io.compression.filesystem"
76
- [io.compression.zipfile ]::ExtractToDirectory(" $PSScriptRoot \kibana-$Version .zip" , $PSScriptRoot )
77
- Rename-Item .\kibana- $Version - windows- x86\ kibana- $Version
78
- Remove-Item kibana- $Version.zip
79
- } Else {
80
- Write-Output " Using already downloaded and extracted Kibana $Version ..."
91
+ If ((Test-Path - Path " kibana-$Version .zip" ) -And -Not (Test-Path - Path " kibana-$Version " )) {
92
+ Write-Output " Extracting Kibana $Version ..."
93
+ Add-Type - assembly " system.io.compression.filesystem"
94
+ [io.compression.zipfile ]::ExtractToDirectory(" $PSScriptRoot \kibana-$Version .zip" , $PSScriptRoot )
95
+ Rename-Item .\kibana- $Version - windows- x86\ kibana- $Version
96
+ Remove-Item kibana- $Version.zip
97
+ } Else {
98
+ Write-Output " Using already downloaded and extracted Kibana $Version ..."
99
+ }
100
+
101
+ Write-Output " Starting Kibana $Version "
102
+ Start-Process " $ ( Get-Location ) \kibana-$Version \bin\kibana.bat"
103
+ $attempts = 0
104
+ $success = $false
105
+ Do {
106
+ If ($attempts -gt 0 ) {
107
+ Start-Sleep - s 2
81
108
}
82
109
83
- Write-Output " Starting Kibana $Version "
84
- Start-Process " $ ( Get-Location ) \kibana-$Version \bin\kibana.bat"
85
- $attempts = 0
86
- Do {
87
- If ($attempts -gt 0 ) {
88
- Start-Sleep - s 2
89
- }
90
-
91
- Write-Host " Waiting for Kibana $Version to respond..."
92
- $res = $null
93
-
94
- Try {
95
- $res = Invoke-WebRequest http:// localhost:5601 - UseBasicParsing
96
- } Catch {}
97
- $attempts = $attempts + 1
98
- } Until ($res -ne $null -And $res.StatusCode -eq 200 -And $attempts -lt 25 )
99
-
100
- If ($OpenKibana ) {
101
- Start-Process " http://localhost:5601/app/kibana#/dev_tools/console"
102
- }
110
+ Write-Host " Waiting for Kibana $Version to respond ($attempts )..."
111
+ $res = $null
112
+
113
+ Try {
114
+ $res = Invoke-WebRequest http:// localhost:5601 - UseBasicParsing
115
+ If ($res -ne $null -And $res.StatusCode -eq 200 ) {
116
+ $success = $true
117
+ Break
118
+ }
119
+ } Catch {}
120
+ $attempts = $attempts + 1
121
+ } Until ($attempts -gt 15 )
122
+
123
+ If ($success -eq $false ) {
124
+ Write-Error " Failed to start Kibana $Version ."
125
+ $host.SetShouldExit ($LastExitCode )
126
+ Return
127
+ }
128
+
129
+ If ($OpenKibana ) {
130
+ Start-Process " http://localhost:5601/app/kibana#/dev_tools/console"
131
+ }
103
132
}
104
133
105
134
Pop-Location
0 commit comments