]> git.openstreetmap.org Git - chef.git/blob - cookbooks/kibana/recipes/default.rb
30ee757aa78f78a35b9a3baad39372aef6a5bb17
[chef.git] / cookbooks / kibana / recipes / default.rb
1 # coding: utf-8
2 #
3 # Cookbook Name:: kibana
4 # Recipe:: default
5 #
6 # Copyright 2015, OpenStreetMap Foundation
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License");
9 # you may not use this file except in compliance with the License.
10 # You may obtain a copy of the License at
11 #
12 #     http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS,
16 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # See the License for the specific language governing permissions and
18 # limitations under the License.
19 #
20
21 require "yaml"
22
23 include_recipe "apache::ssl"
24
25 apache_module "proxy_http"
26
27 version = node[:kibana][:version]
28
29 remote_file "#{Chef::Config[:file_cache_path]}/kibana-#{version}.tar.gz" do
30   source "https://download.elastic.co/kibana/kibana/kibana-4.1.1-linux-x64.tar.gz"
31   not_if { File.exist?("/opt/kibana-#{version}/bin/kibana") }
32 end
33
34 directory "/opt/kibana-#{version}" do
35   owner "root"
36   group "root"
37   mode 0755
38 end
39
40 execute "unzip-kibana-#{version}" do
41   command "tar --gunzip --extract --strip-components=1 --file=#{Chef::Config[:file_cache_path]}/kibana-#{version}.tar.gz"
42   cwd "/opt/kibana-#{version}"
43   user "root"
44   group "root"
45   not_if { File.exist?("/opt/kibana-#{version}/bin/kibana") }
46 end
47
48 directory "/etc/kibana" do
49   owner "root"
50   group "root"
51   mode 0755
52 end
53
54 directory "/var/run/kibana" do
55   owner "kibana"
56   group "kibana"
57   mode 0755
58 end
59
60 directory "/var/log/kibana" do
61   owner "kibana"
62   group "kibana"
63   mode 0755
64 end
65
66 node[:kibana][:sites].each do |name, details|
67   file "/etc/kibana/#{name}.yml" do
68     content YAML.dump(YAML.load(File.read("/opt/kibana-#{version}/config/kibana.yml")).merge(
69                         "port" => details[:port],
70                         "host" => "127.0.0.1",
71                         "elasticsearch_url" => details[:elasticsearch_url],
72                         "pid_file" => "/var/run/kibana/#{name}.pid",
73                         "log_file" => "/var/log/kibana/#{name}.log"
74     ))
75     owner "root"
76     group "root"
77     mode 0644
78     notifies :restart, "service[kibana-#{name}]"
79   end
80
81   template "/etc/init/kibana-#{name}.conf" do
82     source "kibana.conf.erb"
83     owner "root"
84     group "root"
85     mode 0644
86     variables :config => "/etc/kibana/#{name}.yml"
87     notifies :restart, "service[kibana-#{name}]"
88   end
89
90   service "kibana-#{name}" do
91     action [:enable, :start]
92     supports :status => true, :restart => true, :reload => false
93   end
94
95   apache_site details[:site] do
96     template "apache.erb"
97     variables details.merge(:passwd => "/etc/kibana/#{name}.passwd")
98   end
99 end