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