Skip to content

Commit 0d5fa35

Browse files
committed
install kibana
1 parent 5588d44 commit 0d5fa35

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed

Vagrantfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ Vagrant.configure(2) do |config|
1010
config.vm.provision "shell", inline: "$env:chocolateyVersion='0.10.8'; iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex", name: "Install Chocolatey"
1111
config.vm.provision "shell", path: "Vagrantfile-locale.ps1"
1212
config.vm.provision "shell", path: "Vagrantfile-provision.ps1"
13+
config.vm.provision "shell", path: "Vagrantfile-provision-kibana.ps1"
1314
end

Vagrantfile-provision-kibana.ps1

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Set-StrictMode -Version Latest
2+
$ProgressPreference = 'SilentlyContinue'
3+
$ErrorActionPreference = 'Stop'
4+
trap {
5+
Write-Output "ERROR: $_"
6+
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
7+
Write-Output (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
8+
Exit 1
9+
}
10+
11+
# wrap the choco command (to make sure this script aborts when it fails).
12+
function Start-Choco([string[]]$Arguments, [int[]]$SuccessExitCodes=@(0)) {
13+
$command, $commandArguments = $Arguments
14+
if ($command -eq 'install') {
15+
$Arguments = @($command, '--no-progress') + $commandArguments
16+
}
17+
for ($n = 0; $n -lt 10; ++$n) {
18+
if ($n) {
19+
# NB sometimes choco fails with "The package was not found with the source(s) listed."
20+
# but normally its just really a transient "network" error.
21+
Write-Host "Retrying choco install..."
22+
Start-Sleep -Seconds 3
23+
}
24+
&C:\ProgramData\chocolatey\bin\choco.exe @Arguments
25+
if ($SuccessExitCodes -Contains $LASTEXITCODE) {
26+
return
27+
}
28+
}
29+
throw "$(@('choco')+$Arguments | ConvertTo-Json -Compress) failed with exit code $LASTEXITCODE"
30+
}
31+
function choco {
32+
Start-Choco $Args
33+
}
34+
35+
Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1
36+
37+
Write-Output "Installing Kibana..."
38+
Push-Location $env:TEMP
39+
$p = Start-Process git clone,https://github.com/rgl/kibana-chocolatey-package -PassThru -Wait
40+
if ($p.ExitCode) {
41+
throw "git failed with exit code $($p.ExitCode)"
42+
}
43+
cd kibana-chocolatey-package
44+
choco pack
45+
choco install -y nssm
46+
choco install -y kibana -Source $PWD
47+
Pop-Location
48+
49+
$kibanaHome = "$env:ChocolateyInstall\lib\kibana\kibana"
50+
$serviceName = 'kibana'
51+
$serviceUsername = "NT SERVICE\$serviceName"
52+
Write-Output "Modifying the $serviceName service to use the $serviceUsername managed service account instead of LocalSystem..."
53+
$result = sc.exe sidtype $serviceName unrestricted
54+
if ($result -ne '[SC] ChangeServiceConfig2 SUCCESS') {
55+
throw "sc.exe sidtype failed with $result"
56+
}
57+
$result = sc.exe config $serviceName obj= $serviceUsername
58+
if ($result -ne '[SC] ChangeServiceConfig SUCCESS') {
59+
throw "sc.exe config failed with $result"
60+
}
61+
$result = sc.exe failure $serviceName reset= 0 actions= restart/1000
62+
if ($result -ne '[SC] ChangeServiceConfig2 SUCCESS') {
63+
throw "sc.exe failure failed with $result"
64+
}
65+
$result = sc.exe config $serviceName start= auto
66+
if ($result -ne '[SC] ChangeServiceConfig SUCCESS') {
67+
throw "sc.exe config failed with $result"
68+
}
69+
70+
Write-Output "Modifying the $serviceName service to write the kibana output into a log file..."
71+
nssm set $serviceName AppRotateFiles 1
72+
nssm set $serviceName AppRotateOnline 1
73+
nssm set $serviceName AppRotateSeconds 86400
74+
nssm set $serviceName AppRotateBytes (10*1024*1024)
75+
nssm set $serviceName AppStdout $kibanaHome\logs\service.log
76+
nssm set $serviceName AppStderr $kibanaHome\logs\service.log
77+
78+
choco install -y carbon
79+
Update-SessionEnvironment
80+
81+
Write-Output "Granting write permissions to selected directories...."
82+
@('optimize', 'data', 'logs') | ForEach-Object {
83+
$path = "$kibanaHome\$_"
84+
mkdir -Force $path | Out-Null
85+
Disable-AclInheritance $path
86+
'Administrators',$serviceUsername | ForEach-Object {
87+
Write-Host "Granting $_ FullControl to $path..."
88+
Grant-Permission `
89+
-Identity $_ `
90+
-Permission FullControl `
91+
-Path $path
92+
}
93+
}
94+
95+
Write-Output "Starting the $serviceName service..."
96+
Start-Service $serviceName
97+
98+
# add Local Kibana shortcut to the Desktop.
99+
[IO.File]::WriteAllText(
100+
"$env:USERPROFILE\Desktop\Kibana.url",
101+
@"
102+
[InternetShortcut]
103+
URL=http://localhost:5601
104+
"@)

0 commit comments

Comments
 (0)