]> git.openstreetmap.org Git - chef.git/blob - cookbooks/kibana/recipes/default.rb
Remove legacy certificate support
[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 0o755
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 0o755
52 end
53
54 directory "/var/run/kibana" do
55   owner "kibana"
56   group "kibana"
57   mode 0o755
58 end
59
60 directory "/var/log/kibana" do
61   owner "kibana"
62   group "kibana"
63   mode 0o755
64 end
65
66 systemd_service "kibana@" do
67   description "Kibana server"
68   after "network.target"
69   user "kibana"
70   exec_start "/opt/kibana-#{version}/bin/kibana -c /etc/kibana/%i.yml"
71   restart "on-failure"
72 end
73
74 node[:kibana][:sites].each do |name, details|
75   file "/etc/kibana/#{name}.yml" do
76     content YAML.dump(YAML.safe_load(File.read("/opt/kibana-#{version}/config/kibana.yml")).merge(
77                         "port" => details[:port],
78                         "host" => "127.0.0.1",
79                         "elasticsearch_url" => details[:elasticsearch_url],
80                         "pid_file" => "/var/run/kibana/#{name}.pid",
81                         "log_file" => "/var/log/kibana/#{name}.log"
82     ))
83     owner "root"
84     group "root"
85     mode 0o644
86     notifies :restart, "service[kibana@#{name}]"
87   end
88
89   service "kibana@#{name}" do
90     action [:enable, :start]
91     supports :status => true, :restart => true, :reload => false
92   end
93
94   ssl_certificate details[:site] do
95     domains details[:site]
96     notifies :reload, "service[apache2]"
97   end
98
99   apache_site details[:site] do
100     template "apache.erb"
101     variables details.merge(:passwd => "/etc/kibana/#{name}.passwd")
102   end
103 end