Initial Chef repository
This commit is contained in:
53
cookbooks/mariadb/recipes/_audit_plugin.rb
Normal file
53
cookbooks/mariadb/recipes/_audit_plugin.rb
Normal file
@@ -0,0 +1,53 @@
|
||||
# Prepare Configuration File
|
||||
audit_plugin_options = {}
|
||||
|
||||
audit_plugin_options['comment1'] = '#'
|
||||
audit_plugin_options['comment2'] = '# * MariaDB Audit Plugin'
|
||||
audit_plugin_options['comment3'] = '#'
|
||||
|
||||
audit_plugin_options['server_audit_events'] = \
|
||||
node['mariadb']['audit_plugin']['server_audit_events']
|
||||
audit_plugin_options['server_audit_output_type'] = \
|
||||
node['mariadb']['audit_plugin']['server_audit_output_type']
|
||||
audit_plugin_options['server_audit_syslog_facility'] = \
|
||||
node['mariadb']['audit_plugin']['server_audit_syslog_facility']
|
||||
audit_plugin_options['server_audit_syslog_priority'] = \
|
||||
node['mariadb']['audit_plugin']['server_audit_syslog_priority']
|
||||
|
||||
audit_plugin_options['enable'] = '#server_audit_logging = ON'
|
||||
|
||||
# Install the MariaDB Audit Plugin
|
||||
execute 'install_mariadb_audit_plugin' do
|
||||
command '/usr/bin/mysql -e "INSTALL PLUGIN server_audit '\
|
||||
'SONAME \'server_audit\';"'
|
||||
notifies :run, 'execute[configure_mariadb_audit_plugin]', :immediately
|
||||
not_if do
|
||||
cmd = Mixlib::ShellOut.new('/usr/bin/mysql -u root -B -N -e "SELECT 1 '\
|
||||
'FROM information_schema.plugins '\
|
||||
'WHERE PLUGIN_NAME = \'SERVER_AUDIT\''\
|
||||
'AND PLUGIN_STATUS = \'ACTIVE\';"')
|
||||
cmd.run_command
|
||||
cmd.stdout.to_i == 1
|
||||
end
|
||||
end
|
||||
|
||||
# Configure (Dynamic)
|
||||
execute 'configure_mariadb_audit_plugin' do
|
||||
command 'echo "SET GLOBAL server_audit_events=\'' + \
|
||||
node['mariadb']['audit_plugin']['server_audit_events'] + '\';' \
|
||||
'SET GLOBAL server_audit_output_type=\'' + \
|
||||
node['mariadb']['audit_plugin']['server_audit_output_type'] + '\';' \
|
||||
'SET GLOBAL server_audit_syslog_facility=\'' + \
|
||||
node['mariadb']['audit_plugin']['server_audit_syslog_facility'] + '\';' \
|
||||
'SET GLOBAL server_audit_syslog_priority=\'' + \
|
||||
node['mariadb']['audit_plugin']['server_audit_syslog_priority'] + '\';"' \
|
||||
'| /usr/bin/mysql'
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# Create Configuration File
|
||||
mariadb_configuration 'audit_plugin' do
|
||||
section 'mysqld'
|
||||
option audit_plugin_options
|
||||
action :add
|
||||
end
|
||||
55
cookbooks/mariadb/recipes/_debian_galera.rb
Normal file
55
cookbooks/mariadb/recipes/_debian_galera.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: _debian_galera
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# To be sure that debconf is installed
|
||||
package 'debconf-utils' do
|
||||
action :install
|
||||
end
|
||||
|
||||
# Preseed Debian Package
|
||||
# (but test for resource, as it can be declared by apt recipe)
|
||||
begin
|
||||
resources(directory: '/var/cache/local/preseeding')
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
directory '/var/cache/local/preseeding' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
end
|
||||
|
||||
template '/var/cache/local/preseeding/mariadb-galera-server.seed' do
|
||||
source 'mariadb-server.seed.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0600'
|
||||
variables(package_name: 'mariadb-galera-server')
|
||||
notifies :run, 'execute[preseed mariadb-galera-server]', :immediately
|
||||
end
|
||||
|
||||
execute 'preseed mariadb-galera-server' do
|
||||
command '/usr/bin/debconf-set-selections ' \
|
||||
'/var/cache/local/preseeding/mariadb-galera-server.seed'
|
||||
action :nothing
|
||||
end
|
||||
|
||||
package "mariadb-galera-server-#{node['mariadb']['install']['version']}" do
|
||||
action :install
|
||||
end
|
||||
55
cookbooks/mariadb/recipes/_debian_server.rb
Normal file
55
cookbooks/mariadb/recipes/_debian_server.rb
Normal file
@@ -0,0 +1,55 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: _debian_server
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# To be sure that debconf is installed
|
||||
package 'debconf-utils' do
|
||||
action :install
|
||||
end
|
||||
|
||||
# Preseed Debian Package
|
||||
# (but test for resource, as it can be declared by apt recipe)
|
||||
begin
|
||||
resources(directory: '/var/cache/local/preseeding')
|
||||
rescue Chef::Exceptions::ResourceNotFound
|
||||
directory '/var/cache/local/preseeding' do
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0755'
|
||||
recursive true
|
||||
end
|
||||
end
|
||||
|
||||
template '/var/cache/local/preseeding/mariadb-server.seed' do
|
||||
source 'mariadb-server.seed.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0600'
|
||||
variables(package_name: 'mariadb-server')
|
||||
notifies :run, 'execute[preseed mariadb-server]', :immediately
|
||||
end
|
||||
|
||||
execute 'preseed mariadb-server' do
|
||||
command '/usr/bin/debconf-set-selections ' \
|
||||
'/var/cache/local/preseeding/mariadb-server.seed'
|
||||
action :nothing
|
||||
end
|
||||
|
||||
package "mariadb-server-#{node['mariadb']['install']['version']}" do
|
||||
action :install
|
||||
end
|
||||
49
cookbooks/mariadb/recipes/_redhat_galera.rb
Normal file
49
cookbooks/mariadb/recipes/_redhat_galera.rb
Normal file
@@ -0,0 +1,49 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: _redhat_galera
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# To force removing of mariadb-libs on CentOS >= 7
|
||||
package 'MariaDB-shared' do
|
||||
action :install
|
||||
end
|
||||
|
||||
package 'MariaDB-Galera-server' do
|
||||
action :install
|
||||
notifies :create, 'directory[/var/log/mysql]', :immediately
|
||||
notifies :start, 'service[mysql]', :immediately
|
||||
notifies :run, 'execute[change first install root password]', :immediately
|
||||
end
|
||||
|
||||
directory '/var/log/mysql' do
|
||||
action :nothing
|
||||
user 'mysql'
|
||||
group 'mysql'
|
||||
mode '0755'
|
||||
end
|
||||
|
||||
service 'mysql' do
|
||||
action :nothing
|
||||
end
|
||||
|
||||
execute 'change first install root password' do
|
||||
# Add sensitive true when foodcritic #233 fixed
|
||||
command '/usr/bin/mysqladmin -u root password \'' + \
|
||||
node['mariadb']['server_root_password'] + '\''
|
||||
action :nothing
|
||||
not_if { node['mariadb']['server_root_password'].empty? }
|
||||
end
|
||||
45
cookbooks/mariadb/recipes/_redhat_server.rb
Normal file
45
cookbooks/mariadb/recipes/_redhat_server.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: _redhat_server
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
# To force removing of mariadb-libs on CentOS >= 7
|
||||
package 'MariaDB-shared' do
|
||||
action :install
|
||||
end
|
||||
|
||||
package 'MariaDB-server' do
|
||||
action :install
|
||||
notifies :create, 'directory[/var/log/mysql]', :immediately
|
||||
notifies :start, 'service[mysql]', :immediately
|
||||
notifies :run, 'execute[change first install root password]', :immediately
|
||||
end
|
||||
|
||||
directory '/var/log/mysql' do
|
||||
action :nothing
|
||||
user 'mysql'
|
||||
group 'mysql'
|
||||
mode '0755'
|
||||
end
|
||||
|
||||
execute 'change first install root password' do
|
||||
# Add sensitive true when foodcritic #233 fixed
|
||||
command '/usr/bin/mysqladmin -u root password \'' + \
|
||||
node['mariadb']['server_root_password'] + '\''
|
||||
action :nothing
|
||||
not_if { node['mariadb']['server_root_password'].empty? }
|
||||
end
|
||||
45
cookbooks/mariadb/recipes/_redhat_server_native.rb
Normal file
45
cookbooks/mariadb/recipes/_redhat_server_native.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: _redhat_server_native
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
# This recipe is for install and configure os shipped mariadb package
|
||||
|
||||
Chef::Recipe.send(:include, MariaDB::Helper)
|
||||
|
||||
service_name = os_service_name(node['platform'], node['platform_version'])
|
||||
node.set['mariadb']['mysqld']['service_name'] = service_name\
|
||||
unless service_name.nil?
|
||||
|
||||
directory '/var/log/mysql' do
|
||||
action :create
|
||||
user 'mysql'
|
||||
group 'mysql'
|
||||
mode '0755'
|
||||
end
|
||||
|
||||
package 'mariadb-server' do
|
||||
action :install
|
||||
notifies :enable, 'service[mysql]'
|
||||
notifies :start, 'service[mysql]', :immediately
|
||||
notifies :run, 'execute[change first install root password]', :immediately
|
||||
end
|
||||
|
||||
execute 'change first install root password' do
|
||||
# Add sensitive true when foodcritic #233 fixed
|
||||
command '/usr/bin/mysqladmin -u root password \'' + \
|
||||
node['mariadb']['server_root_password'] + '\''
|
||||
action :nothing
|
||||
not_if { node['mariadb']['server_root_password'].empty? }
|
||||
end
|
||||
89
cookbooks/mariadb/recipes/client.rb
Normal file
89
cookbooks/mariadb/recipes/client.rb
Normal file
@@ -0,0 +1,89 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: client
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
Chef::Recipe.send(:include, MariaDB::Helper)
|
||||
case node['mariadb']['install']['type']
|
||||
when 'package'
|
||||
use_os_package = use_os_native_package?(
|
||||
node['mariadb']['install']['prefer_os_package'],
|
||||
node['platform'],
|
||||
node['platform_version'])
|
||||
|
||||
include_recipe "#{cookbook_name}::repository" unless use_os_package
|
||||
|
||||
case node['platform_family']
|
||||
when 'rhel'
|
||||
# On CentOS at least, there's a conflict between MariaDB and mysql-libs
|
||||
package 'mysql-libs' do
|
||||
action :remove
|
||||
not_if { use_os_package }
|
||||
end
|
||||
|
||||
# rubocop:disable BlockNesting
|
||||
if use_os_package
|
||||
if node['mariadb']['client']['development_files']
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(mariadb mariadb-devel)
|
||||
else
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(mariadb)
|
||||
end
|
||||
else
|
||||
if node['mariadb']['client']['development_files']
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(MariaDB-client MariaDB-devel)
|
||||
else
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(MariaDB-client)
|
||||
end
|
||||
end
|
||||
# rubocop:enable BlockNesting
|
||||
when 'fedora'
|
||||
if node['mariadb']['client']['development_files']
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(mariadb mariadb-devel)
|
||||
else
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(mariadb)
|
||||
end
|
||||
when 'suse'
|
||||
if node['mariadb']['client']['development_files']
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(mariadb-community-server-client libmariadbclient-devel)
|
||||
else
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%w(mariadb-community-server-client)
|
||||
end
|
||||
when 'debian'
|
||||
if node['mariadb']['client']['development_files']
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%W(mariadb-client-#{node['mariadb']['install']['version']}
|
||||
libmariadbclient-dev)
|
||||
else
|
||||
node.default['mariadb']['client']['packages'] = \
|
||||
%W(mariadb-client-#{node['mariadb']['install']['version']})
|
||||
end
|
||||
end
|
||||
|
||||
node['mariadb']['client']['packages'].each do |name|
|
||||
package name
|
||||
end
|
||||
when 'from_source'
|
||||
# To be filled as soon as possible
|
||||
end
|
||||
96
cookbooks/mariadb/recipes/config.rb
Normal file
96
cookbooks/mariadb/recipes/config.rb
Normal file
@@ -0,0 +1,96 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: config
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
template node['mariadb']['configuration']['path'] + '/my.cnf' do
|
||||
source 'my.cnf.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0644'
|
||||
end
|
||||
|
||||
innodb_options = {}
|
||||
|
||||
innodb_options['comment1'] = '#'
|
||||
innodb_options['comment2'] = '# * InnoDB'
|
||||
innodb_options['comment3'] = '#'
|
||||
innodb_options['comment4'] = '# InnoDB is enabled by default with a 10MB ' \
|
||||
'datafile in /var/lib/mysql/.'
|
||||
innodb_options['comment5'] = '# Read the manual for more InnoDB ' \
|
||||
'related options. There are many!'
|
||||
|
||||
innodb_options['innodb_log_file_size_comment1'] = '# you can\'t just ' \
|
||||
'change log file size, ' \
|
||||
'requires special procedure'
|
||||
if node['mariadb']['innodb']['log_file_size'].empty?
|
||||
innodb_options['innodb_log_file_size'] = '#innodb_log_file_size = 50M'
|
||||
else
|
||||
innodb_options['innodb_log_file_size'] = \
|
||||
node['mariadb']['innodb']['log_file_size']
|
||||
end
|
||||
if node['mariadb']['innodb']['bps_percentage_memory']
|
||||
innodb_options['innodb_buffer_pool_size'] = (
|
||||
(
|
||||
node['mariadb']['innodb']['buffer_pool_size'].to_f *
|
||||
(node['memory']['total'][0..-3].to_i / 1024)
|
||||
).round).to_s + 'M'
|
||||
else
|
||||
innodb_options['innodb_buffer_pool_size'] = \
|
||||
node['mariadb']['innodb']['buffer_pool_size']
|
||||
end
|
||||
innodb_options['innodb_log_buffer_size'] = \
|
||||
node['mariadb']['innodb']['log_buffer_size']
|
||||
innodb_options['innodb_file_per_table'] = \
|
||||
node['mariadb']['innodb']['file_per_table']
|
||||
innodb_options['innodb_open_files'] = node['mariadb']['innodb']['open_files']
|
||||
innodb_options['innodb_io_capacity'] = \
|
||||
node['mariadb']['innodb']['io_capacity']
|
||||
innodb_options['innodb_flush_method'] = \
|
||||
node['mariadb']['innodb']['flush_method']
|
||||
node['mariadb']['innodb']['options'].each do |key, value|
|
||||
innodb_options[key] = value
|
||||
end
|
||||
|
||||
mariadb_configuration 'innodb' do
|
||||
section 'mysqld'
|
||||
option innodb_options
|
||||
action :add
|
||||
end
|
||||
|
||||
replication_opts = {}
|
||||
replication_opts['log_bin'] = node['mariadb']['replication']['log_bin']
|
||||
replication_opts['log_bin_index'] = \
|
||||
node['mariadb']['replication']['log_bin_index']
|
||||
replication_opts['expire_logs_days'] = \
|
||||
node['mariadb']['replication']['expire_logs_days']
|
||||
replication_opts['max_binlog_size'] = \
|
||||
node['mariadb']['replication']['max_binlog_size']
|
||||
unless node['mariadb']['replication']['server_id'].empty?
|
||||
replication_opts['server-id'] = node['mariadb']['replication']['server_id']
|
||||
end
|
||||
if node['mariadb']['replication'].key?('options')
|
||||
node['mariadb']['replication']['options'].each do |key, value|
|
||||
replication_opts[key] = value
|
||||
end
|
||||
end
|
||||
|
||||
mariadb_configuration 'replication' do
|
||||
section 'mysqld'
|
||||
option replication_opts
|
||||
action :add
|
||||
end
|
||||
20
cookbooks/mariadb/recipes/default.rb
Normal file
20
cookbooks/mariadb/recipes/default.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: default
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
include_recipe "#{cookbook_name}::server"
|
||||
141
cookbooks/mariadb/recipes/galera.rb
Normal file
141
cookbooks/mariadb/recipes/galera.rb
Normal file
@@ -0,0 +1,141 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: galera
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
case node['mariadb']['install']['type']
|
||||
when 'package'
|
||||
# include MariaDB repositories
|
||||
include_recipe "#{cookbook_name}::repository"
|
||||
|
||||
case node['platform']
|
||||
when 'debian', 'ubuntu'
|
||||
include_recipe "#{cookbook_name}::_debian_galera"
|
||||
when 'redhat', 'centos', 'fedora', 'scientific', 'amazon'
|
||||
include_recipe "#{cookbook_name}::_redhat_galera"
|
||||
end
|
||||
when 'from_source'
|
||||
# To be filled as soon as possible
|
||||
end
|
||||
|
||||
if node['mariadb']['galera']['wsrep_sst_method'] == 'rsync'
|
||||
package 'rsync' do
|
||||
action :install
|
||||
end
|
||||
else
|
||||
if node['mariadb']['galera']['wsrep_sst_method'] == 'xtrabackup'
|
||||
package 'percona-xtrabackup' do
|
||||
action :install
|
||||
end
|
||||
|
||||
package 'socat' do
|
||||
action :install
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
include_recipe "#{cookbook_name}::config"
|
||||
|
||||
galera_cluster_nodes = []
|
||||
if !node['mariadb'].attribute?('rspec') && Chef::Config[:solo]
|
||||
Chef::Log.warn('This recipe uses search. Chef Solo does not support search.')
|
||||
else
|
||||
if node['mariadb']['galera']['cluster_search_query'].empty?
|
||||
galera_cluster_nodes = search(
|
||||
:node, \
|
||||
"mariadb_galera_cluster_name:#{node['mariadb']['galera']['cluster_name']}"
|
||||
)
|
||||
else
|
||||
galera_cluster_nodes = search 'node', node['mariadb']['galera']['cluster_search_query']
|
||||
log 'Chef search results' do
|
||||
message "Searching for \"#{node['mariadb']['galera']['cluster_search_query']}\" \
|
||||
resulted in \"#{galera_cluster_nodes}\" ..."
|
||||
end
|
||||
end
|
||||
# Sort Nodes by fqdn
|
||||
galera_cluster_nodes.sort! { |x, y| x[:fqdn] <=> y[:fqdn] }
|
||||
end
|
||||
|
||||
first = true
|
||||
gcomm = 'gcomm://'
|
||||
galera_cluster_nodes.each do |lnode|
|
||||
next unless lnode.name != node.name
|
||||
gcomm += ',' unless first
|
||||
gcomm += lnode['fqdn']
|
||||
first = false
|
||||
end
|
||||
|
||||
galera_options = {}
|
||||
|
||||
galera_options['wsrep_cluster_address'] = gcomm
|
||||
galera_options['wsrep_cluster_name'] = \
|
||||
node['mariadb']['galera']['cluster_name']
|
||||
galera_options['wsrep_sst_method'] = \
|
||||
node['mariadb']['galera']['wsrep_sst_method']
|
||||
if node['mariadb']['galera'].attribute?('wsrep_sst_auth')
|
||||
galera_options['wsrep_sst_auth'] = \
|
||||
node['mariadb']['galera']['wsrep_sst_auth']
|
||||
end
|
||||
galera_options['wsrep_provider'] = \
|
||||
node['mariadb']['galera']['wsrep_provider']
|
||||
galera_options['wsrep_slave_threads'] = node['cpu']['total'] * 4
|
||||
node['mariadb']['galera']['options'].each do |key, value|
|
||||
galera_options[key] = value
|
||||
end
|
||||
|
||||
mariadb_configuration 'galera' do
|
||||
section 'mysqld'
|
||||
option galera_options
|
||||
action :add
|
||||
end
|
||||
|
||||
#
|
||||
# Under debian system we have to change the debian-sys-maint default password.
|
||||
# This password is the same for the overall cluster.
|
||||
#
|
||||
if platform?('debian', 'ubuntu')
|
||||
template '/etc/mysql/debian.cnf' do
|
||||
sensitive true
|
||||
source 'debian.cnf.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0600'
|
||||
end
|
||||
|
||||
execute 'correct-debian-grants' do
|
||||
# Add sensitive true when foodcritic #233 fixed
|
||||
command 'mysql -r -B -N -e "GRANT SELECT, INSERT, UPDATE, DELETE, '\
|
||||
'CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, '\
|
||||
'ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, '\
|
||||
'LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, '\
|
||||
'CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, '\
|
||||
"CREATE USER, EVENT, TRIGGER ON *.* TO '" + \
|
||||
node['mariadb']['debian']['user'] + \
|
||||
"'@'" + node['mariadb']['debian']['host'] + "' IDENTIFIED BY '" + \
|
||||
node['mariadb']['debian']['password'] + "' WITH GRANT OPTION\""
|
||||
action :run
|
||||
only_if do
|
||||
cmd = Mixlib::ShellOut.new("/usr/bin/mysql --user=\"" + \
|
||||
node['mariadb']['debian']['user'] + \
|
||||
"\" --password=\"" + node['mariadb']['debian']['password'] + \
|
||||
"\" -r -B -N -e \"SELECT 1\"")
|
||||
cmd.run_command
|
||||
cmd.error?
|
||||
end
|
||||
ignore_failure true
|
||||
end
|
||||
end
|
||||
3
cookbooks/mariadb/recipes/plugins.rb
Normal file
3
cookbooks/mariadb/recipes/plugins.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
node['mariadb']['plugins'].each do |plugin, enable|
|
||||
include_recipe "#{cookbook_name}::_" + plugin + '_plugin' if enable
|
||||
end
|
||||
42
cookbooks/mariadb/recipes/repository.rb
Normal file
42
cookbooks/mariadb/recipes/repository.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
case node['platform']
|
||||
when 'debian', 'ubuntu'
|
||||
install_method = 'apt'
|
||||
when 'redhat', 'centos', 'fedora', 'scientific', 'amazon'
|
||||
install_method = 'yum'
|
||||
end
|
||||
|
||||
if node['mariadb']['use_default_repository']
|
||||
case install_method
|
||||
when 'apt'
|
||||
include_recipe 'apt::default'
|
||||
|
||||
apt_repository "mariadb-#{node['mariadb']['install']['version']}" do
|
||||
uri 'http://' + node['mariadb']['apt_repository']['base_url'] + '/' + \
|
||||
node['mariadb']['install']['version'] + '/' + node['platform']
|
||||
distribution node['lsb']['codename']
|
||||
components ['main']
|
||||
keyserver 'hkp://keyserver.ubuntu.com:80'
|
||||
key '0xcbcb082a1bb943db'
|
||||
end
|
||||
when 'yum'
|
||||
include_recipe 'yum::default'
|
||||
|
||||
if node['platform'] == 'redhat'
|
||||
target_platform = "rhel#{node['platform_version'].to_i}"
|
||||
else
|
||||
target_platform = "#{node['platform']}#{node['platform_version'].to_i}"
|
||||
end
|
||||
yum_repository "mariadb-#{node['mariadb']['install']['version']}" do
|
||||
description 'MariaDB Official Repository'
|
||||
baseurl 'http://yum.mariadb.org/' + \
|
||||
node['mariadb']['install']['version'] + "/#{target_platform}-amd64"
|
||||
gpgkey 'https://yum.mariadb.org/RPM-GPG-KEY-MariaDB'
|
||||
action :create
|
||||
end
|
||||
|
||||
case node['platform']
|
||||
when 'redhat', 'centos'
|
||||
include_recipe 'yum-epel::default'
|
||||
end
|
||||
end
|
||||
end
|
||||
130
cookbooks/mariadb/recipes/server.rb
Normal file
130
cookbooks/mariadb/recipes/server.rb
Normal file
@@ -0,0 +1,130 @@
|
||||
#
|
||||
# Cookbook Name:: mariadb
|
||||
# Recipe:: server
|
||||
#
|
||||
# Copyright 2014, blablacar.com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
Chef::Recipe.send(:include, MariaDB::Helper)
|
||||
case node['mariadb']['install']['type']
|
||||
when 'package'
|
||||
if use_os_native_package?(node['mariadb']['install']['prefer_os_package'],
|
||||
node['platform'], node['platform_version'])
|
||||
# currently, no releases with apt (e.g. ubuntu) ship mariadb
|
||||
# only provide one type of server here (with yum support)
|
||||
include_recipe "#{cookbook_name}::_redhat_server_native"
|
||||
else
|
||||
include_recipe "#{cookbook_name}::repository"
|
||||
|
||||
case node['platform']
|
||||
when 'debian', 'ubuntu'
|
||||
include_recipe "#{cookbook_name}::_debian_server"
|
||||
when 'redhat', 'centos', 'fedora', 'scientific', 'amazon'
|
||||
include_recipe "#{cookbook_name}::_redhat_server"
|
||||
end
|
||||
end
|
||||
when 'from_source'
|
||||
# To be filled as soon as possible
|
||||
end
|
||||
|
||||
include_recipe "#{cookbook_name}::config"
|
||||
|
||||
service 'mysql' do
|
||||
service_name node['mariadb']['mysqld']['service_name']
|
||||
supports restart: true
|
||||
action :nothing
|
||||
end
|
||||
|
||||
# move the datadir if needed
|
||||
if node['mariadb']['mysqld']['datadir'] !=
|
||||
node['mariadb']['mysqld']['default_datadir']
|
||||
|
||||
bash 'move-datadir' do
|
||||
user 'root'
|
||||
code <<-EOH
|
||||
/bin/cp -a #{node['mariadb']['mysqld']['default_datadir']}/* \
|
||||
#{node['mariadb']['mysqld']['datadir']} &&
|
||||
/bin/rm -r #{node['mariadb']['mysqld']['default_datadir']} &&
|
||||
/bin/ln -s #{node['mariadb']['mysqld']['datadir']} \
|
||||
#{node['mariadb']['mysqld']['default_datadir']}
|
||||
EOH
|
||||
action :nothing
|
||||
end
|
||||
|
||||
directory node['mariadb']['mysqld']['datadir'] do
|
||||
owner 'mysql'
|
||||
group 'mysql'
|
||||
mode 00750
|
||||
action :create
|
||||
notifies :stop, 'service[mysql]', :immediately
|
||||
notifies :run, 'bash[move-datadir]', :immediately
|
||||
notifies :start, 'service[mysql]', :immediately
|
||||
only_if { !File.symlink?(node['mariadb']['mysqld']['default_datadir']) }
|
||||
end
|
||||
end
|
||||
|
||||
# restart the service if needed
|
||||
# workaround idea from https://github.com/stissot
|
||||
Chef::Resource::Execute.send(:include, MariaDB::Helper)
|
||||
execute 'mariadb-service-restart-needed' do
|
||||
command 'true'
|
||||
only_if do
|
||||
mariadb_service_restart_required?(
|
||||
'127.0.0.1',
|
||||
node['mariadb']['mysqld']['port'],
|
||||
node['mariadb']['mysqld']['socket']
|
||||
)
|
||||
end
|
||||
notifies :restart, 'service[mysql]', :immediately
|
||||
end
|
||||
|
||||
if node['mariadb']['allow_root_pass_change']
|
||||
# Used to change root password after first install
|
||||
# Still experimental
|
||||
if node['mariadb']['server_root_password'].empty?
|
||||
md5 = Digest::MD5.hexdigest('empty')
|
||||
else
|
||||
md5 = Digest::MD5.hexdigest(node['mariadb']['server_root_password'])
|
||||
end
|
||||
|
||||
file '/etc/mysql_root_change' do
|
||||
content md5
|
||||
action :create
|
||||
notifies :run, 'execute[install-grants]', :immediately
|
||||
end
|
||||
end
|
||||
|
||||
if node['mariadb']['allow_root_pass_change'] ||
|
||||
node['mariadb']['forbid_remote_root']
|
||||
execute 'install-grants' do
|
||||
# Add sensitive true when foodcritic #233 fixed
|
||||
command '/bin/bash /etc/mariadb_grants \'' + \
|
||||
node['mariadb']['server_root_password'] + '\''
|
||||
only_if { File.exist?('/etc/mariadb_grants') }
|
||||
action :nothing
|
||||
end
|
||||
|
||||
template '/etc/mariadb_grants' do
|
||||
sensitive true
|
||||
source 'mariadb_grants.erb'
|
||||
owner 'root'
|
||||
group 'root'
|
||||
mode '0600'
|
||||
notifies :run, 'execute[install-grants]', :immediately
|
||||
end
|
||||
end
|
||||
|
||||
# MariaDB Plugins
|
||||
include_recipe "#{cookbook_name}::plugins" if node['mariadb']['plugins_options']['auto_install']
|
||||
Reference in New Issue
Block a user