Skip to content

Commit

Permalink
install kibana
Browse files Browse the repository at this point in the history
  • Loading branch information
rgl committed Feb 15, 2018
1 parent 5588d44 commit 0d5fa35
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ Vagrant.configure(2) do |config|
config.vm.provision "shell", inline: "$env:chocolateyVersion='0.10.8'; iwr https://chocolatey.org/install.ps1 -UseBasicParsing | iex", name: "Install Chocolatey"
config.vm.provision "shell", path: "Vagrantfile-locale.ps1"
config.vm.provision "shell", path: "Vagrantfile-provision.ps1"
config.vm.provision "shell", path: "Vagrantfile-provision-kibana.ps1"
end
104 changes: 104 additions & 0 deletions Vagrantfile-provision-kibana.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Set-StrictMode -Version Latest
$ProgressPreference = 'SilentlyContinue'
$ErrorActionPreference = 'Stop'
trap {
Write-Output "ERROR: $_"
Write-Output (($_.ScriptStackTrace -split '\r?\n') -replace '^(.*)$','ERROR: $1')
Write-Output (($_.Exception.ToString() -split '\r?\n') -replace '^(.*)$','ERROR EXCEPTION: $1')
Exit 1
}

# wrap the choco command (to make sure this script aborts when it fails).
function Start-Choco([string[]]$Arguments, [int[]]$SuccessExitCodes=@(0)) {
$command, $commandArguments = $Arguments
if ($command -eq 'install') {
$Arguments = @($command, '--no-progress') + $commandArguments
}
for ($n = 0; $n -lt 10; ++$n) {
if ($n) {
# NB sometimes choco fails with "The package was not found with the source(s) listed."
# but normally its just really a transient "network" error.
Write-Host "Retrying choco install..."
Start-Sleep -Seconds 3
}
&C:\ProgramData\chocolatey\bin\choco.exe @Arguments
if ($SuccessExitCodes -Contains $LASTEXITCODE) {
return
}
}
throw "$(@('choco')+$Arguments | ConvertTo-Json -Compress) failed with exit code $LASTEXITCODE"
}
function choco {
Start-Choco $Args
}

Import-Module C:\ProgramData\chocolatey\helpers\chocolateyInstaller.psm1

Write-Output "Installing Kibana..."
Push-Location $env:TEMP
$p = Start-Process git clone,https://github.com/rgl/kibana-chocolatey-package -PassThru -Wait
if ($p.ExitCode) {
throw "git failed with exit code $($p.ExitCode)"
}
cd kibana-chocolatey-package
choco pack
choco install -y nssm
choco install -y kibana -Source $PWD
Pop-Location

$kibanaHome = "$env:ChocolateyInstall\lib\kibana\kibana"
$serviceName = 'kibana'
$serviceUsername = "NT SERVICE\$serviceName"
Write-Output "Modifying the $serviceName service to use the $serviceUsername managed service account instead of LocalSystem..."
$result = sc.exe sidtype $serviceName unrestricted
if ($result -ne '[SC] ChangeServiceConfig2 SUCCESS') {
throw "sc.exe sidtype failed with $result"
}
$result = sc.exe config $serviceName obj= $serviceUsername
if ($result -ne '[SC] ChangeServiceConfig SUCCESS') {
throw "sc.exe config failed with $result"
}
$result = sc.exe failure $serviceName reset= 0 actions= restart/1000
if ($result -ne '[SC] ChangeServiceConfig2 SUCCESS') {
throw "sc.exe failure failed with $result"
}
$result = sc.exe config $serviceName start= auto
if ($result -ne '[SC] ChangeServiceConfig SUCCESS') {
throw "sc.exe config failed with $result"
}

Write-Output "Modifying the $serviceName service to write the kibana output into a log file..."
nssm set $serviceName AppRotateFiles 1
nssm set $serviceName AppRotateOnline 1
nssm set $serviceName AppRotateSeconds 86400
nssm set $serviceName AppRotateBytes (10*1024*1024)
nssm set $serviceName AppStdout $kibanaHome\logs\service.log
nssm set $serviceName AppStderr $kibanaHome\logs\service.log

choco install -y carbon
Update-SessionEnvironment

Write-Output "Granting write permissions to selected directories...."
@('optimize', 'data', 'logs') | ForEach-Object {
$path = "$kibanaHome\$_"
mkdir -Force $path | Out-Null
Disable-AclInheritance $path
'Administrators',$serviceUsername | ForEach-Object {
Write-Host "Granting $_ FullControl to $path..."
Grant-Permission `
-Identity $_ `
-Permission FullControl `
-Path $path
}
}

Write-Output "Starting the $serviceName service..."
Start-Service $serviceName

# add Local Kibana shortcut to the Desktop.
[IO.File]::WriteAllText(
"$env:USERPROFILE\Desktop\Kibana.url",
@"
[InternetShortcut]
URL=http://localhost:5601
"@)

0 comments on commit 0d5fa35

Please sign in to comment.