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