Initial Chef repository

This commit is contained in:
Greg Karékinian
2015-07-21 19:45:23 +02:00
parent 7e5401fc71
commit ee4079fa85
1151 changed files with 185163 additions and 0 deletions

View File

@@ -0,0 +1,120 @@
mariadb CHANGELOG
=================
This file is used to list changes made in each version of the mariadb cookbook.
0.3.0
------
- [ENH] - Add support for using operating system shipped mariadb packages
0.2.12
------
- [BUG #39] - Push gpg key adds through http/80 - Helps with firewalled installs
- [ENH #46] - Add cookbook attribute on configuration lwrp
- [ENH #47] - Allow to pass true for unary options
- [BUG #48] - Load the needed plugins at startup
0.2.11
------
- [ENH #38] - Add CentOS support
- [ENH #40] - Add sensitive flag to resource that deal with passwords
- [BUG #43] - Fix convert TypeError in the replication provider
0.2.10
------
- [BUG] - Audit Plugin test and installation - Correct bad notifies, and stdout test
0.2.9
-----
- [BUG #36] - Audit plugin installation can crash mariadb server
0.2.8
-----
- [BUG #30] - When using galera, nodes were not sorted, applying configuration change too often
- [BUG #31] - ChefSpec coverage was not 100%
- [BUG #28] - Remove the only_if to mysql service
- [BUG #29] - Add a switch to not launch audit plugin install, when already installed
- [ENH] - Add a switch to separate server install and audit install when needed
- [ENH] - Add a rule to authorize line length to be 120 characters long
0.2.7
-----
- [BUG #24] - Fix convert TypeError in the replication provider
- [BUG #25] - Data are now moved when default datadir is changed
- [ENH #21] - Add audit_plugin management
0.2.6
-----
- [BUG #18] - Fix provider mariadb_replication compilation error
- [DOCS] - Complete Changelog, and correct README
0.2.5
-----
- [ENH #16] - Add a LWRP to manage replication slave
- [ENH #17] - Be able to not install development files within client recipe
- [ENH #11] - Fix the galera root password preseed
- [BUG #12] - Fix the debian-sys-maint user creation/password change
- [BUG #6] - Can change the apt repository base_url when the default one fail
- [TEST] - Add new tests for the new features (galera,development files install,replication LWRP)
- [DOCS] - Complete Changelog, and add new features explanations into README
0.2.4
-----
- [BUG #10] - Correct a FC004 broken rule
- [BUG #9] - Correct foodcritic tests (add --epic-fail any to be sure it fails when a broken rule is detected)
0.2.3
-----
- [BUG #4] - Add a real management of mysql root password
- [ENH #5] - Now restart mysql service when port is changed
- [ENH #7] - Remove or add root remote access via attribute
- [DOCS] - Complete documentations
- [TEST] - Add a lot of chefspec and kitchen/serverspec tests
0.2.2
-----
- [sinfomicien] - Correct repository install under debian family
- [sinfomicien] - Correct client install to add dev files
- [sinfomicien] - Correct and add multiples tests
0.2.1
-----
- [sinfomicien] - Use stove to package (remove PaxHeaders.*)
0.2.0
-----
- [sinfomicien] - Add rpm/yum management
- [sinfomicien] - Refactor the whole recipes list and management to ease it
- [sinfomicien] - Correct the Documentation
- [sinfomicien] - Rename the provider (from extraconf to configuration), and add matchers to it
- [sinfomicien] - Add a recipe to manage client only installation
- [sinfomicien] - Refactor all tests to manage new platform (centos/redhat/fedora)
0.1.8
-----
- [sinfomicien] - Add ignore-failure to debian grants correct, as it can break on initial setup
0.1.7
-----
- [sinfomicien] - Correct a typo (unnecessary call to run_command)
0.1.6
-----
- [sinfomicien] - improve Galera configuration management
- [sinfomicien] - Add new rspec tests
- [sinfomicien] - Create Kitchen test suite
0.1.5
-----
- [sinfomicien] - improve attributes management
0.1.4
-----
- [sinfomicien] - adapt galera55 recipe to use a generic galera recipe
- [sinfomicien] - use a generic galera recipe to create the galera10 recipe
- [sinfomicien] - Improve documentation
0.1.0
-----
- [sinfomicien] - Initial release of mariadb

207
cookbooks/mariadb/README.md Normal file
View File

@@ -0,0 +1,207 @@
MariaDB Cookbook
================
[![Build Status](https://travis-ci.org/sinfomicien/mariadb.png)](https://travis-ci.org/sinfomicien/mariadb)
Description
-----------
This cookbook contains all the stuffs to install and configure a mariadb server on a dpkg/apt compliant system (typically debian), or a rpm/yum compliant system (typically centos)
Requirements
------------
#### repository
- `mariadb` - This cookbook need that you have a valid apt repository installed with the mariadb official packages
#### packages
- `percona-xtrabackup` - if you want to use the xtrabckup SST Auth for galera cluster.
- `socat` - if you want to use the xtrabckup SST Auth for galera cluster.
- `rsync` - if you want to use the rsync SST Auth for galera cluster.
- `debconf-utils` - if you use debian platform family.
#### operating system
- `debian` - this cookbook is fully tested on debian
- `ubuntu` - not fully tested on ubuntu, but should work
- `centos` - not fully tested on centos, but should work
Attributes
----------
#### mariadb::default
<table>
<tr>
<th>Key</th>
<th>Type</th>
<th>Description</th>
<th>Default</th>
</tr>
<tr>
<td><tt>['mariadb']['install']['version']</tt></td>
<td>String</td>
<td>Version to install (currently 10.0 et 5.5)</td>
<td><tt>10.0</tt></td>
</tr>
<tr>
<td><tt>['mariadb']['use_default_repository']</tt></td>
<td>Boolean</td>
<td>Wether to install MariaDB default repository or not. If you don't have a local repo containing packages, put it to true</td>
<td><tt>false</tt></td>
</tr>
<tr>
<td><tt>['mariadb']['server_root_password']</tt></td>
<td>String</td>
<td>local root password</td>
<td><tt></tt></td>
</tr>
<tr>
<td><tt>['mariadb']['forbid_remote_root']</tt></td>
<td>Boolean</td>
<td>Wether to activate root remote access</td>
<td><tt>true</tt></td>
</tr>
<tr>
<td><tt>['mariadb']['allow_root_pass_change']</tt></td>
<td>Boolean</td>
<td>Wether to allow the recipe to change root password after the first install</td>
<td><tt>false</tt></td>
</tr>
<tr>
<td><tt>['mariadb']['client']['development_files']</tt></td>
<td>Boolean</td>
<td>Wether to install development files in client recipe</td>
<td><tt>true</tt></td>
</tr>
<tr>
<td><tt>['mariadb']['apt_repository']['base_url']</tt></td>
<td>String</td>
<td>The http base url to use when installing from default repository</td>
<td><tt>'ftp.igh.cnrs.fr/pub/mariadb/repo'</tt></td>
</tr>
<tr>
<td><tt>['mariadb']['install']['prefer_os_package']</tt></td>
<td>Boolean</td>
<td>Indicator for preferring use packages shipped by running os</td>
<td><tt>false</tt></td>
</tr>
</table>
Usage
-----
To install a default server for mariadb choose the version you want (MariaDB 5.5 or 10, galera or not), then call the recipe accordingly.
List of availables recipes:
- mariadb::default (just call server recipe with default options)
- mariadb::server
- mariadb::galera
- mariadb::client
Please be ware that by default, the root password is empty! If you want have changed it use the `node['mariadb']['server_root_password']` attribute to put a correct value. And by default the remote root access is not activated. Use `node['mariadb']['forbid_remote_root']` attribute to change it.
Sometimes, the default apt repository used for apt does not work (see issue #6). In this case, you need to choose another mirror which worki (pick it from mariadb website), and put the http base url in the attribute `node['mariadb']['apt_repository']['base_url']`.
#### mariadb::galera
When installing the mariadb::galera on debian recipe, You have to take care of one specific attribute:
`node['mariadb']['debian']['password']` which default to 'please-change-me'
As wee need to have the same password for this user on the whole cluster nodes... We will change the default install one by the content of this attribute.
#### mariadb::client
By default this recipe install the client, and all needed packages to develop client application. If you do not want to install development files when installing client package,
set the attribute `node['mariadb']['client']['development_files']` to false.
Providers
----------
This recipe define 2 providers:
- `Chef::Provider::Mariadb::Configuration` shortcut resource `mariadb_configuration`
- `Chef::Provider::Mariadb::Replication` shortcut resource `mariadb_replication`
#### mariadb_configuration
Mainly use for internal purpose. You can use it to create a new configuration file into configuration dir. You have to define 2 variables `section` and `option`.
Where `section` is the configuration section, and `option` is a hash of key/value. The name of the resource is used as base for the filename.
Example:
```ruby
mariadb_configuration 'fake' do
section 'mysqld'
option {foo: 'bar'}
end
```
will become the file fake.cnf in the include dir (depend on your platform), which contain:
```
[mysqld]
foo=bar
```
If the value start with a '#', then it's considered as a comment, and the value is printed as is (without the key)
Example:
```ruby
mariadb_configuration 'fake' do
section 'mysqld'
option {comment1: '# Here i am', foo: bar}
end
```
will become the file fake.cnf in the include dir (depend on your platform), which contain:
```
[mysqld]
# Here i am
foo=bar
```
#### mariadb_replication
This LWRP is used to manage replication setup on a host. To use this LWRP, the node need to have the mysql binary installed (via the mariadb::client or mariadb::server or mariadb::galera recipe).
It have 4 actions:
- add - to add a new replication setup (become a slave)
- stop - to stop the slave replication
- start - to start the slave replication
- remove - to remove the slave replication configuration
The resource name need to be 'default' if your don't want to use a named connection (multi source replication in MariaDB 10).
So by default the provider try to use the local instance of mysql, with the current user and no password. If you want to change, you have to define `host`, `port`, `user` or `password`
```ruby
mariadb_replication 'default' do
user 'root'
password 'fakepass'
host 'fakehost'
action :stop
end
```
will stop the replication on the host `fakehost` using the user `root` and password `fakepass` to connect to.
When you add a replication configuration, you have to define at least 4 values `master_host`, `master_user`, `master_password` and `master_use_gtid`. And if you don't want the GTID support, you have to define also `master_log_file` and `master_log_pos`
Example:
```ruby
mariadb_replication 'usefull_conn_name' do
master_host 'server1'
master_user 'slave_user'
master_password 'slave_password'
master_use_gtid 'current_pos'
action :add
end
```
Contributing
------------
1. Fork the repository on Github
2. Create a named feature branch (like `add_component_x`)
3. Write your change
4. Write tests for your change (if applicable)
5. Run the tests, ensuring they all pass
6. Submit a Pull Request using Github
License and Authors
-------------------
Authors:
Nicolas Blanc <sinfomicien@gmail.com>

View File

@@ -0,0 +1,156 @@
# platform dependent attributes
case node['platform']
when 'redhat', 'centos', 'fedora', 'scientific', 'amazon'
default['mariadb']['configuration']['path'] = '/etc'
default['mariadb']['configuration']['includedir'] = '/etc/my.cnf.d'
default['mariadb']['mysqld']['socket'] = '/var/lib/mysql/mysql.sock'
default['mariadb']['client']['socket'] = '/var/lib/mysql/mysql.sock'
default['mariadb']['mysqld_safe']['socket'] = '/var/lib/mysql/mysql.sock'
else
default['mariadb']['configuration']['path'] = '/etc/mysql'
default['mariadb']['configuration']['includedir'] = '/etc/mysql/conf.d'
default['mariadb']['mysqld']['socket'] = '/var/run/mysqld/mysqld.sock'
default['mariadb']['mysqld']['pid_file'] = '/var/run/mysqld/mysqld.pid'
default['mariadb']['client']['socket'] = '/var/run/mysqld/mysqld.sock'
default['mariadb']['mysqld_safe']['socket'] = '/var/run/mysqld/mysqld.sock'
end
#
# mysqld default configuration
#
default['mariadb']['forbid_remote_root'] = true
default['mariadb']['server_root_password'] = ''
default['mariadb']['allow_root_pass_change'] = false
default['mariadb']['mysqld']['service_name'] = 'mysql'
default['mariadb']['mysqld']['user'] = 'mysql'
default['mariadb']['mysqld']['port'] = '3306'
default['mariadb']['mysqld']['basedir'] = '/usr'
default['mariadb']['mysqld']['default_datadir'] = '/var/lib/mysql'
# if different from previous value, datadir will be moved after install
default['mariadb']['mysqld']['datadir'] = '/var/lib/mysql'
default['mariadb']['mysqld']['tmpdir'] = '/var/tmp'
default['mariadb']['mysqld']['lc_messages_dir'] = '/usr/share/mysql'
default['mariadb']['mysqld']['lc_messages'] = 'en_US'
default['mariadb']['mysqld']['skip_external_locking'] = 'true'
default['mariadb']['mysqld']['bind_address'] = '127.0.0.1'
default['mariadb']['mysqld']['max_connections'] = '100'
default['mariadb']['mysqld']['connect_timeout'] = '5'
default['mariadb']['mysqld']['wait_timeout'] = '600'
default['mariadb']['mysqld']['max_allowed_packet'] = '16M'
default['mariadb']['mysqld']['thread_cache_size'] = '128'
default['mariadb']['mysqld']['sort_buffer_size'] = '4M'
default['mariadb']['mysqld']['bulk_insert_buffer_size'] = '16M'
default['mariadb']['mysqld']['tmp_table_size'] = '32M'
default['mariadb']['mysqld']['max_heap_table_size'] = '32M'
default['mariadb']['mysqld']['myisam_recover'] = 'BACKUP'
default['mariadb']['mysqld']['key_buffer_size'] = '128M'
# if not defined default is 2000
default['mariadb']['mysqld']['open_files_limit'] = ''
default['mariadb']['mysqld']['table_open_cache'] = '400'
default['mariadb']['mysqld']['myisam_sort_buffer_size'] = '512M'
default['mariadb']['mysqld']['concurrent_insert'] = '2'
default['mariadb']['mysqld']['read_buffer_size'] = '2M'
default['mariadb']['mysqld']['read_rnd_buffer_size'] = '1M'
default['mariadb']['mysqld']['query_cache_limit'] = '128K'
default['mariadb']['mysqld']['query_cache_size'] = '64M'
# if not defined default is ON
default['mariadb']['mysqld']['query_cache_type'] = ''
default['mariadb']['mysqld']['default_storage_engine'] = 'InnoDB'
default['mariadb']['mysqld']['options'] = {}
#
# InnoDB default configuration
#
# if not defined default is 50M
default['mariadb']['innodb']['log_file_size'] = ''
default['mariadb']['innodb']['bps_percentage_memory'] = false
default['mariadb']['innodb']['buffer_pool_size'] = '256M'
default['mariadb']['innodb']['log_buffer_size'] = '8M'
default['mariadb']['innodb']['file_per_table'] = '1'
default['mariadb']['innodb']['open_files'] = '400'
default['mariadb']['innodb']['io_capacity'] = '400'
default['mariadb']['innodb']['flush_method'] = 'O_DIRECT'
default['mariadb']['innodb']['options'] = {}
#
# Galera default configuration
#
default['mariadb']['galera']['cluster_name'] = 'galera_cluster'
default['mariadb']['galera']['cluster_search_query'] = ''
default['mariadb']['galera']['wsrep_sst_method'] = 'rsync'
default['mariadb']['galera']['wsrep_provider'] = \
'/usr/lib/galera/libgalera_smm.so'
default['mariadb']['galera']['options'] = {}
#
# Replication default configuration
#
default['mariadb']['replication']['server_id'] = ''
default['mariadb']['replication']['log_bin'] = \
'/var/log/mysql/mariadb-bin'
default['mariadb']['replication']['log_bin_index'] = \
'/var/log/mysql/mariadb-bin.index'
default['mariadb']['replication']['expire_logs_days'] = '10'
default['mariadb']['replication']['max_binlog_size'] = '100M'
#
# mysqldump default configuration
#
default['mariadb']['mysqldump']['quick'] = 'true'
default['mariadb']['mysqldump']['quote_names'] = 'true'
default['mariadb']['mysqldump']['max_allowed_packet'] = '16M'
#
# isamchk default configuration
default['mariadb']['isamchk']['key_buffer'] = '16M'
#
# mysqld_safe default configuration
#
default['mariadb']['mysqld_safe']['options'] = {}
#
# client default configuration
#
default['mariadb']['client']['port'] = 3306
default['mariadb']['client']['options'] = {}
default['mariadb']['client']['development_files'] = true
#
# debian specific configuration
#
default['mariadb']['debian']['user'] = 'debian-sys-maint'
default['mariadb']['debian']['password'] = 'please-change-me'
default['mariadb']['debian']['host'] = 'localhost'
#
# mariadb default install configuration
#
# install valid value is 'package',
# hope to have 'from_source' in the near future
default['mariadb']['install']['type'] = 'package'
default['mariadb']['install']['version'] = '10.0'
default['mariadb']['install']['prefer_os_package'] = false
#
# package(apt or yum) default configuration
#
default['mariadb']['use_default_repository'] = false
default['mariadb']['apt_repository']['base_url'] = \
'ftp.igh.cnrs.fr/pub/mariadb/repo'
#
# MariaDB Plugins enabling
#
default['mariadb']['plugins_options']['auto_install'] = true
# Enabling Plugin Installation
default['mariadb']['plugins']['audit'] = false
# Load Plugins in .cnf (plugin-loadi variable)
default['mariadb']['plugins_loading']['audit'] = 'server_audit=server_audit.so'
# Default Configuration
default['mariadb']['audit_plugin']['server_audit_events'] = ''
default['mariadb']['audit_plugin']['server_audit_output_type'] = 'file'
# Syslog (require server_audit_output_type = syslog)
default['mariadb']['audit_plugin']['server_audit_syslog_facility'] = 'LOG_USER'
default['mariadb']['audit_plugin']['server_audit_syslog_priority'] = 'LOG_INFO'

View File

@@ -0,0 +1,78 @@
# MariaDB is a module containing mariadb cookbook helper
module MariaDB
# Helper module for mariadb cookbook
module Helper
require 'socket'
require 'timeout'
def do_port_connect(ip, port)
s = TCPSocket.new(ip, port)
s.close
true
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
false
end
def port_open?(ip, port)
begin
Timeout.timeout(5) do
return do_port_connect(ip, port)
end
rescue Timeout::Error
false
end
false
end
# Trying to determine if we need to restart the mysql service
def mariadb_service_restart_required?(ip, port, _socket)
restart = false
restart = true unless port_open?(ip, port)
restart
end
# Helper to determine if running operating system shipped a package for
# mariadb server & client. No galera shipped in any os yet.
# @param [String] os_platform Indicate operating system type, e.g. centos
# @param [String] os_version Indicate operating system version, e.g. 7.0
def os_package_provided?(os_platform, os_version)
package_provided = false
case os_platform
when 'centos', 'redhat'
package_provided = true if os_version.to_i == 7
when 'fedora'
package_provided = true if os_version.to_i >= 19
end
package_provided
end
# Helper to determine mariadb server service name shipped by native package
# If no native package available on this platform, return nil
# @param [String] os_platform Indicate operating system type, e.g. centos
# @param [String] os_version Indicate operating system version, e.g. 7.0
def os_service_name(os_platform, os_version)
return nil unless os_package_provided?(os_platform, os_version)
service_name = 'mariadb'
if os_platform == 'fedora' && os_version.to_i == 19
service_name = 'mysqld'
end
service_name
end
# Helper to determine whether to use os native package
# @param [Boolean] prefer_os Indicate whether to prefer os native package
# @param [String] os_platform Indicate operating system type, e.g. centos
# @param [String] os_version Indicate operating system version, e.g. 7.0
def use_os_native_package?(prefer_os, os_platform, os_version)
return false unless prefer_os
if os_package_provided?(os_platform, os_version)
true
else
Chef::Log.warn 'prefer_os_package detected, but no native mariadb'\
" package available on #{os_platform}-#{os_version}."\
' Fall back to use community package.'
false
end
end
end
end

View File

@@ -0,0 +1,21 @@
if defined?(ChefSpec)
def add_mariadb_configuration(resource_name)
ChefSpec::Matchers::ResourceMatcher
.new(:mariadb_configuration, :add, resource_name)
end
def remove_mariadb_configuration(resource_name)
ChefSpec::Matchers::ResourceMatcher
.new(:mariadb_configuration, :remove, resource_name)
end
def add_mariadb_replication(resource_name)
ChefSpec::Matchers::ResourceMatcher
.new(:mariadb_replication, :add, resource_name)
end
def remove_mariadb_replication(resource_name)
ChefSpec::Matchers::ResourceMatcher
.new(:mariadb_replication, :remove, resource_name)
end
end

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,38 @@
#
# Cookbook Name:: mariadb
# Provider:: configuration
#
use_inline_resources if defined?(use_inline_resources)
def whyrun_supported?
true
end
action :add do
variables_hash = {
section: new_resource.section,
options: new_resource.option
}
template node['mariadb']['configuration']['includedir'] + \
'/' + new_resource.name + '.cnf' do
source 'conf.d.generic.erb'
owner 'root'
group 'mysql'
mode '0640'
cookbook new_resource.cookbook
variables variables_hash
end
end
action :remove do
if ::File.exist?(node['mariadb']['configuration']['includedir'] + \
'/' + new_resource.name + '.cnf')
Chef::Log.info "Removing #{new_resource.name} repository from " + \
node['mariadb']['configuration']['includedir']
file node['mariadb']['configuration']['includedir'] + \
'/' + new_resource.name + '.cnf' do
action :delete
end
end
end

View File

@@ -0,0 +1,105 @@
#
# Cookbook Name:: mariadb
# Provider:: replication
#
use_inline_resources if defined?(use_inline_resources)
def whyrun_supported?
true
end
def get_mysql_command(host, port, user, password)
mysql_command = '/usr/bin/mysql'
mysql_command += ' -h ' + host unless host.nil?
mysql_command += ' -P ' + port unless port.nil?
mysql_command += ' -u ' + user unless user.nil?
mysql_command += ' -p' + password unless password.nil?
mysql_command
end
action :add do
if new_resource.master_host.nil? || new_resource.master_user.nil? ||
new_resource.master_password.nil?
fail '[ERROR] When adding a slave, you have to define master_host' \
' master_user and master_password !'
end
sql_string = 'CHANGE MASTER '
sql_string += '\'' + new_resource.name + \
'\' ' if new_resource.name != 'default'
sql_string += 'TO '
sql_string += 'MASTER_HOST=\'' + new_resource.master_host + '\', '
sql_string += 'MASTER_PORT=' + new_resource.master_port.to_s + \
', ' unless new_resource.master_port.nil?
sql_string += 'MASTER_USER=\'' + new_resource.master_user + '\', '
sql_string += 'MASTER_PASSWORD=\'' + new_resource.master_password + '\''
if new_resource.master_use_gtid == 'no'
# Use non GTID replication setup
if new_resource.master_log_file.nil? || new_resource.master_log_pos.nil?
fail '[ERROR] When adding a slave without GTID, you have to' \
'define master_log_file and master_log_pos !'
end
unless new_resource.master_log_file.nil?
sql_string += ', MASTER_LOG_FILE=\'' + \
new_resource.master_log_file + '\''
sql_string += ', MASTER_LOG_POS=' + new_resource.master_log_pos.to_s
end
else
# Use GTID replication
sql_string += ', MASTER_USE_GTID=' + new_resource.master_use_gtid + ';'
end
execute 'add_replication_from_master_' + new_resource.name do
# Add sensitive true when foodcritic #233 fixed
command '/bin/echo "' + sql_string + '" | ' + get_mysql_command(
new_resource.host,
new_resource.port,
new_resource.user,
new_resource.password
)
action :run
end
end
action :remove do
execute 'remove_replication_from_master_' + new_resource.name do
# Add sensitive true when foodcritic #233 fixed
command '/bin/echo "STOP SLAVE \'' + new_resource.name + '\'; ' \
'RESET SLAVE \'' + new_resource.name + '\' ALL' \
';" | ' + get_mysql_command(
new_resource.host,
new_resource.port,
new_resource.user,
new_resource.password
)
end
end
action :start do
command_master_connection = ' \'' + new_resource.name + \
'\'' unless new_resource.name == 'default'
execute 'start_replication_from_master_' + new_resource.name do
# Add sensitive true when foodcritic #233 fixed
command '/bin/echo "START SLAVE' + command_master_connection + ';' \
'" | ' + get_mysql_command(
new_resource.host,
new_resource.port,
new_resource.user,
new_resource.password
)
end
end
action :stop do
command_master_connection = ' \'' + new_resource.name + \
'\'' unless new_resource.name == 'default'
execute 'start_replication_from_master_' + new_resource.name do
# Add sensitive true when foodcritic #233 fixed
command '/bin/echo "STOP SLAVE' + command_master_connection + ';' \
'" | ' + get_mysql_command(
new_resource.host,
new_resource.port,
new_resource.user,
new_resource.password
)
end
end

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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

View 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"

View 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

View File

@@ -0,0 +1,3 @@
node['mariadb']['plugins'].each do |plugin, enable|
include_recipe "#{cookbook_name}::_" + plugin + '_plugin' if enable
end

View 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

View 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']

View File

@@ -0,0 +1,13 @@
#
# Cookbook Name:: mariadb
# Resource:: configuration
#
actions :add, :remove
default_action :add
# name of the extra conf file, used for .cnf filename
attribute :conf_name, kind_of: String, name_attribute: true
attribute :section, kind_of: String
attribute :option, kind_of: Hash, default: {}
attribute :cookbook, kind_of: String, default: nil

View File

@@ -0,0 +1,22 @@
#
# Cookbook Name:: mariadb
# Resource:: replication
#
actions :add, :remove, :start, :stop
default_action :add
# name of the extra conf file, used for .cnf filename
attribute :connection_name, kind_of: String, name_attribute: true
attribute :host, kind_of: [String, NilClass], default: nil
attribute :port, kind_of: [String, NilClass], default: nil
attribute :user, kind_of: [String, NilClass], default: nil
attribute :password, kind_of: [String, NilClass], default: nil
attribute :master_host, kind_of: [String, NilClass], default: nil
attribute :master_user, kind_of: [String, NilClass], default: nil
attribute :master_password, kind_of: [String, NilClass], default: nil
attribute :master_connect_retry, kind_of: [String, NilClass], default: nil
attribute :master_port, kind_of: [Integer, NilClass], default: nil
attribute :master_log_pos, kind_of: [Integer, NilClass], default: nil
attribute :master_log_file, kind_of: [String, NilClass], default: nil
attribute :master_use_gtid, kind_of: String, default: 'no'

View File

@@ -0,0 +1,19 @@
# DEPLOYED BY CHEF
[<%= @section -%>]
<% @options.each do | option_name, option_value |-%>
<% if option_value.to_s == 'true' -%>
<%= option_name %>
<% else -%>
<% if option_value.kind_of?(String) && option_value.start_with?('#') -%>
<%= option_value %>
<% else -%>
<% if option_value.kind_of?(Array) -%>
<% option_value.each do | option_value_array_value | -%>
<%= option_name -%> = <%= option_value_array_value %>
<% end -%>
<% else -%>
<%= option_name -%> = <%= option_value %>
<% end -%>
<% end -%>
<% end -%>
<% end -%>

View File

@@ -0,0 +1,12 @@
# Automatically generated for Debian scripts (Managed by CHEF). DO NOT TOUCH!
[client]
host = <%= node['mariadb']['debian']['host'] %>
user = <%= node['mariadb']['debian']['user'] %>
password = <%= node['mariadb']['debian']['password'] %>
socket = <%= node['mariadb']['client']['socket'] %>
[mysql_upgrade]
host = <%= node['mariadb']['debian']['host'] %>
user = <%= node['mariadb']['debian']['user'] %>
password = <%= node['mariadb']['debian']['password'] %>
socket = <%= node['mariadb']['mysqld_safe']['socket'] %>
basedir = <%= node['mariadb']['mysqld']['basedir'] %>

View File

@@ -0,0 +1,13 @@
<%
# Value obtained via the debconf-get-selections tool on debian wheezy
pack_w_version = @package_name + '-' + node['mariadb']['install']['version']
-%>
<%= pack_w_version %> mysql-server/root_password_again select <%= node['mariadb']['server_root_password'] %>
<%= pack_w_version %> mysql-server/root_password select <%= node['mariadb']['server_root_password'] %>
<%= pack_w_version %> mysql-server/error_setting_password boolean false
<%= pack_w_version %> mysql-server-5.1/nis_warning note
<%= pack_w_version %> mysql-server-5.1/start_on_boot boolean true
<%= pack_w_version %> <%= pack_w_version %>/really_downgrade boolean false
<%= pack_w_version %> mysql-server-5.1/postrm_remove_databases boolean false
<%= pack_w_version %> mysql-server/password_mismatch boolean false
<%= pack_w_version %> mysql-server/no_upgrade_when_using_ndb boolean true

View File

@@ -0,0 +1,25 @@
#!/bin/bash
# Generated by CHEF
# Local modification will be overriden
<% if node['mariadb']['allow_root_pass_change'] -%>
<% if node['mariadb']['server_root_password'].empty? -%>
/usr/bin/mysqladmin -u root password "$1"
<% else -%>
/usr/bin/mysqladmin -u root -p'<%= node['mariadb']['server_root_password'] %>' password "$1"
<% end -%>
<% end -%>
password_flag=""
if [ "$1" ]; then
password_flag="-p$1"
fi
<% if node['mariadb']['forbid_remote_root'] -%>
user_exist=`/usr/bin/mysql -u root ${password_flag} -D mysql -r -B -N -e "SELECT user from user where user = 'root' and host = '%'"`
if [ $user_exist == 'root' ]; then
/bin/echo "DROP USER 'root'@'%';" | /usr/bin/mysql -u root ${password_flag}
fi
<% else -%>
/bin/echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '<%= node['mariadb']['server_root_password'] %>' WITH GRANT OPTION;" | /usr/bin/mysql -u root ${password_flag}
<% end -%>

View File

@@ -0,0 +1,191 @@
# DEPLOYED BY CHEF
# MariaDB database server configuration file.
#
# You can copy this file to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# This will be passed to all mysql clients
# It has been reported that passwords should be enclosed with ticks/quotes
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = <%= node['mariadb']['client']['port'] %>
socket = <%= node['mariadb']['client']['socket'] %>
<% if node['mariadb']['client'].attribute?('host') && !node['mariadb']['client']['host'].nil? %>
host = <%= node['mariadb']['client']['host'] %>
<% end %>
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = <%= node['mariadb']['mysqld_safe']['socket'] %>
nice = 0
[mysqld]
#
# * Basic Settings
#
user = <%= node['mariadb']['mysqld']['user'] %>
<% if node['mariadb']['mysqld'].attribute?('pid_file') %>
pid-file = <%= node['mariadb']['mysqld']['pid_file'] %>
<% end %>
socket = <%= node['mariadb']['mysqld']['socket'] %>
port = <%= node['mariadb']['mysqld']['port'] %>
basedir = <%= node['mariadb']['mysqld']['basedir'] %>
datadir = <%= node['mariadb']['mysqld']['default_datadir'] %>
tmpdir = <%= node['mariadb']['mysqld']['tmpdir'] %>
lc_messages_dir = <%= node['mariadb']['mysqld']['lc_messages_dir'] %>
lc_messages = <%= node['mariadb']['mysqld']['lc_messages'] %>
<% if node['mariadb']['mysqld']['skip_external_locking'] == 'true' -%>
skip-external-locking
<% end -%>
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
<% unless node['mariadb']['mysqld']['bind_address'].nil? or node['mariadb']['mysqld']['bind_address'].empty? -%>
bind-address = <%= node['mariadb']['mysqld']['bind_address'] %>
<% end -%>
#
# * Fine Tuning
#
max_connections = <%= node['mariadb']['mysqld']['max_connections'] %>
connect_timeout = <%= node['mariadb']['mysqld']['connect_timeout'] %>
wait_timeout = <%= node['mariadb']['mysqld']['wait_timeout'] %>
max_allowed_packet = <%= node['mariadb']['mysqld']['max_allowed_packet'] %>
thread_cache_size = <%= node['mariadb']['mysqld']['thread_cache_size'] %>
sort_buffer_size = <%= node['mariadb']['mysqld']['sort_buffer_size'] %>
bulk_insert_buffer_size = <%= node['mariadb']['mysqld']['bulk_insert_buffer_size'] %>
tmp_table_size = <%= node['mariadb']['mysqld']['tmp_table_size'] %>
max_heap_table_size = <%= node['mariadb']['mysqld']['max_heap_table_size'] %>
#
# * MyISAM
#
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched. On error, make copy and try a repair.
myisam_recover = <%= node['mariadb']['mysqld']['myisam_recover'] %>
key_buffer_size = <%= node['mariadb']['mysqld']['key_buffer_size'] %>
<% if node['mariadb']['mysqld']['open_files_limit'].empty? -%>
#open-files-limit = 2000
<% else -%>
open-files-limit = <%= node['mariadb']['mysqld']['open_files_limit'] %>
<% end -%>
table_open_cache = <%= node['mariadb']['mysqld']['table_open_cache'] %>
myisam_sort_buffer_size = <%= node['mariadb']['mysqld']['myisam_sort_buffer_size'] %>
concurrent_insert = <%= node['mariadb']['mysqld']['concurrent_insert'] %>
read_buffer_size = <%= node['mariadb']['mysqld']['read_buffer_size'] %>
read_rnd_buffer_size = <%= node['mariadb']['mysqld']['read_rnd_buffer_size'] %>
#
# * Query Cache Configuration
#
# Cache only tiny result sets, so we can fit more in the query cache.
query_cache_limit = <%= node['mariadb']['mysqld']['query_cache_limit'] %>
query_cache_size = <%= node['mariadb']['mysqld']['query_cache_size'] %>
# for more write intensive setups, set to DEMAND or OFF
<% if node['mariadb']['mysqld']['query_cache_type'].empty? -%>
#query_cache_type = DEMAND
<% else -%>
query_cache_type = <%= node['mariadb']['mysqld']['query_cache_type'] %>
<% end -%>
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
# Be aware that this log type is a performance killer.
# As of 5.1 you can enable the log at runtime!
#general_log_file = /var/log/mysql/mysql.log
#general_log = 1
#
# Error logging goes to syslog due to /etc/mysql/conf.d/mysqld_safe_syslog.cnf.
#
# we do want to know about network errors and such
log_warnings = 2
#
# Enable the slow query log to see queries with especially long duration
#slow_query_log[={0|1}]
slow_query_log_file = /var/log/mysql/mariadb-slow.log
long_query_time = 10
#log_slow_rate_limit = 1000
log_slow_verbosity = query_plan
#log-queries-not-using-indexes
#log_slow_admin_statements
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#report_host = master1
#auto_increment_increment = 2
#auto_increment_offset = 1
# not fab for performance, but safer
#sync_binlog = 1
# slaves
#relay_log = /var/log/mysql/relay-bin
#relay_log_index = /var/log/mysql/relay-bin.index
#relay_log_info_file = /var/log/mysql/relay-bin.info
#log_slave_updates
#read_only
#
# If applications support it, this stricter sql_mode prevents some
# mistakes like inserting invalid dates etc.
#sql_mode = NO_ENGINE_SUBSTITUTION,TRADITIONAL
default_storage_engine = <%= node['mariadb']['mysqld']['default_storage_engine'] %>
#
# * Security Features
#
# Read the manual, too, if you want chroot!
# chroot = /var/lib/mysql/
#
# For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
#
# ssl-ca=/etc/mysql/cacert.pem
# ssl-cert=/etc/mysql/server-cert.pem
# ssl-key=/etc/mysql/server-key.pem
<% if node['mariadb']['mysqld'].key?('options') -%>
<% node['mariadb']['mysqld']['options'].each { |key, value| -%>
<%= key %> = <%= value %>
<% } -%>
<% end -%>
#
# * Plugins Options
#
<% plugin_load = [] -%>
<% node['mariadb']['plugins_loading'].each { |plugin, loading| -%>
<% plugin_load.push(loading) if node['mariadb']['plugins'][plugin] %>
<% } -%>
plugin-load = <%= plugin_load.join(';') %>
[mysqldump]
<% if node['mariadb']['mysqldump']['quick'].empty? -%>
quick
<% end -%>
<% if node['mariadb']['mysqldump']['quote_names'].empty? -%>
quote-names
<% end -%>
max_allowed_packet = <%= node['mariadb']['mysqldump']['max_allowed_packet'] %>
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = <%= node['mariadb']['isamchk']['key_buffer'] %>
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir <%= node['mariadb']['configuration']['includedir'] %>/