]> git.openstreetmap.org Git - chef.git/blob - cookbooks/mysql/recipes/default.rb
Remove munin
[chef.git] / cookbooks / mysql / recipes / default.rb
1 #
2 # Cookbook:: mysql
3 # Recipe:: default
4 #
5 # Copyright:: 2013, 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 #     https://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 include_recipe "munin"
21 include_recipe "prometheus"
22
23 mysql_variant = if platform?("ubuntu")
24                   "mysql"
25                 else
26                   "mariadb"
27                 end
28
29 package "#{mysql_variant}-server"
30 package "#{mysql_variant}-client"
31
32 service "#{mysql_variant}" do
33   action [:enable, :start]
34   supports :status => true, :restart => true
35 end
36
37 template "/etc/mysql/#{mysql_variant}.conf.d/zzz-chef.cnf" do
38   source "my.cnf.erb"
39   owner "root"
40   group "root"
41   mode "644"
42   notifies :restart, "service[#{mysql_variant}]"
43 end
44
45 service "apparmor" do
46   action :nothing
47 end
48
49 template "/etc/apparmor.d/local/usr.sbin.mysqld" do
50   source "apparmor.erb"
51   owner "root"
52   group "root"
53   mode "644"
54   notifies :restart, "service[apparmor]"
55   only_if { ::Dir.exist?("/sys/kernel/security/apparmor") }
56 end
57
58 # FIXME: Remove purge post munin removal
59 package "libdbd-mysql-perl" do
60   action :purge
61 end
62
63 package "libcache-cache-perl" do
64   action :purge
65 end
66
67 mysql_password = persistent_token("mysql", "prometheus", "password")
68
69 mysql_user "prometheus" do
70   password mysql_password
71   process true
72   repl_client true
73 end
74
75 prometheus_exporter "mysqld" do
76   port 9104
77   options "--mysqld.username=prometheus"
78   environment "MYSQLD_EXPORTER_PASSWORD" => mysql_password
79 end