Refactor to use mysql::globals.
This initial round of work focuses on adding the concept of mysql::globals to the module. This is a shared place to provide all the data the module needs, and then clients, servers, and providers can all rely on this information to set things up. This is being primarily used at first to allow a default_options hash that contains all the previous parameters and takes a overrides_options that allows you to then further customize any of the options in my.cnf.
This commit is contained in:
parent
52fb70ebde
commit
e3843ceb6f
24 changed files with 584 additions and 772 deletions
|
@ -43,7 +43,7 @@ class mysql::backup (
|
|||
ensure => $ensure,
|
||||
password_hash => mysql_password($backuppassword),
|
||||
provider => 'mysql',
|
||||
require => Class['mysql::config'],
|
||||
require => Class['mysql::server::config'],
|
||||
}
|
||||
|
||||
mysql_grant { "${backupuser}@localhost/*.*":
|
||||
|
|
|
@ -39,17 +39,17 @@ class mysql::bindings (
|
|||
$python_enable = false,
|
||||
$ruby_enable = false,
|
||||
# Settings for the various classes.
|
||||
$java_package_ensure = $mysql::params::java_package_ensure,
|
||||
$java_package_name = $mysql::params::java_package_name,
|
||||
$perl_package_ensure = $mysql::params::perl_package_ensure,
|
||||
$perl_package_name = $mysql::params::perl_package_name,
|
||||
$perl_package_provider = $mysql::params::perl_package_provider,
|
||||
$python_package_ensure = $mysql::params::python_package_ensure,
|
||||
$python_package_name = $mysql::params::python_package_name,
|
||||
$ruby_package_ensure = $mysql::params::ruby_package_ensure,
|
||||
$ruby_package_name = $mysql::params::ruby_package_name,
|
||||
$ruby_package_provider = $mysql::params::ruby_package_provider
|
||||
) inherits mysql::params {
|
||||
$java_package_ensure = $mysql::globals::java_package_ensure,
|
||||
$java_package_name = $mysql::globals::java_package_name,
|
||||
$perl_package_ensure = $mysql::globals::perl_package_ensure,
|
||||
$perl_package_name = $mysql::globals::perl_package_name,
|
||||
$perl_package_provider = $mysql::globals::perl_package_provider,
|
||||
$python_package_ensure = $mysql::globals::python_package_ensure,
|
||||
$python_package_name = $mysql::globals::python_package_name,
|
||||
$ruby_package_ensure = $mysql::globals::ruby_package_ensure,
|
||||
$ruby_package_name = $mysql::globals::ruby_package_name,
|
||||
$ruby_package_provider = $mysql::globals::ruby_package_provider
|
||||
) inherits mysql::globals {
|
||||
|
||||
if $java_enable { include '::mysql::bindings::java' }
|
||||
if $perl_enable { include '::mysql::bindings::perl' }
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
class mysql::bindings::java (
|
||||
$package_ensure = $mysql::bindings::java_package_ensure,
|
||||
$package_name = $mysql::bindings::java_package_name
|
||||
) inherits mysql {
|
||||
) inherits mysql::globals {
|
||||
|
||||
package { 'mysql-connector-java':
|
||||
ensure => $package_ensure,
|
||||
|
|
|
@ -17,7 +17,7 @@ class mysql::bindings::perl (
|
|||
$package_ensure = $mysql::bindings::perl_package_ensure,
|
||||
$package_name = $mysql::bindings::perl_package_name,
|
||||
$package_provider = $mysql::bindings::perl_package_provider
|
||||
) inherits mysql {
|
||||
) inherits mysql::globals {
|
||||
|
||||
package{ 'perl_mysql':
|
||||
ensure => $package_ensure,
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
class mysql::bindings::python(
|
||||
$package_ensure = $mysql::bindings::python_package_ensure,
|
||||
$package_name = $mysql::bindings::python_package_name
|
||||
) inherits mysql {
|
||||
) inherits mysql::globals {
|
||||
|
||||
package { 'python-mysqldb':
|
||||
ensure => $package_ensure,
|
||||
|
|
|
@ -17,7 +17,7 @@ class mysql::bindings::ruby (
|
|||
$package_ensure = $mysql::bindings::ruby_package_ensure,
|
||||
$package_name = $mysql::bindings::ruby_package_name,
|
||||
$package_provider = $mysql::bindings::ruby_package_provider
|
||||
) inherits mysql {
|
||||
) inherits mysql::globals {
|
||||
|
||||
package{ 'ruby_mysql':
|
||||
ensure => $package_ensure,
|
||||
|
|
12
manifests/client.pp
Normal file
12
manifests/client.pp
Normal file
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
class mysql::client (
|
||||
$bindings_enable = false,
|
||||
) inherits mysql::globals {
|
||||
|
||||
include '::mysql::client::install'
|
||||
|
||||
if $bindings_enable {
|
||||
include '::mysql::bindings'
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
class mysql::client::install(
|
||||
$package_name = $mysql::client_package_name,
|
||||
$package_ensure = $mysql::client_package_ensure
|
||||
$package_name = $mysql::globals::client_package_name,
|
||||
$package_ensure = $mysql::globals::client_package_ensure
|
||||
) {
|
||||
|
||||
package { 'mysql_client':
|
||||
|
|
|
@ -1,223 +0,0 @@
|
|||
# Class: mysql::config
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# [*root_password*] - root user password.
|
||||
# [*old_root_password*] - previous root user password,
|
||||
# [*bind_address*] - address to bind service.
|
||||
# [*port*] - port to bind service.
|
||||
# [*etc_root_password*] - whether to save /etc/my.cnf.
|
||||
# [*service_name*] - mysql service name.
|
||||
# [*config_file*] - my.cnf configuration file path.
|
||||
# [*socket*] - mysql socket.
|
||||
# [*datadir*] - path to datadir.
|
||||
# [*ssl] - enable ssl
|
||||
# [*ssl_ca] - path to ssl-ca
|
||||
# [*ssl_cert] - path to ssl-cert
|
||||
# [*ssl_key] - path to ssl-key
|
||||
# [*log_error] - path to mysql error log
|
||||
# [*default_engine] - configure a default table engine
|
||||
# [*root_group] - use specified group for root-owned files
|
||||
# [*restart] - whether to restart mysqld (true/false)
|
||||
# [*character_set] - You can change the default server and
|
||||
# client character set
|
||||
# [*key_buffer] - Index blocks for MyISAM tables are buffered and
|
||||
# are shared by all threads. key_buffer_size is the size of the buffer used
|
||||
# for index blocks.
|
||||
# [*max_allowed_packet] - The maximum size of one packet or any
|
||||
# generated/intermediate string, or any parameter sent by the
|
||||
# mysql_stmt_send_long_data() C API function.
|
||||
# [*thread_stack] - The stack size for each thread.
|
||||
# [*thread_cache_size] - How many threads server should cache for reuse.
|
||||
# [*myisam-recover] - Set the MyISAM storage engine recovery mode.
|
||||
# [*query_cache_limit] - Do not cache results that are larger than this
|
||||
# number of bytes.
|
||||
# [*query_cache_size] - The amount of memory allocated for caching query
|
||||
# results.
|
||||
# [*max_connections] - The maximum permitted number of simultaneous
|
||||
# client connections.
|
||||
# [*tmp_table_size] - The maximum size of internal in-memory temporary
|
||||
# tables.
|
||||
# [*max_heap_table_size] - This variable sets the maximum size to which
|
||||
# user-created MEMORY tables are permitted to grow.
|
||||
# [*table_open_cache] - The number of open tables for all threads.
|
||||
# [*long_query_time] - If a query takes longer than this many seconds,
|
||||
# the server increments the Slow_queries status variable.
|
||||
# [*server_id] - The server ID, used in replication to give each
|
||||
# master and slave a unique identity.
|
||||
# [*sql_log_bin] - This variable controls whether logging to the
|
||||
# binary log is done. The default value is 1.
|
||||
# [*log_bin] - Enable binary logging. The server logs all
|
||||
# statements that change data to the binary log, which is used for backup
|
||||
# and replication.
|
||||
# [*max_binlog_size] - If a write to the binary log causes the current
|
||||
# log file size to exceed the value of this variable, the server rotates
|
||||
# the binary logs (closes the current file and opens the next one).
|
||||
# [*binlog_do_db] - This option affects binary logging in a manner
|
||||
# similar to the way that --replicate-do-db affects replication.
|
||||
# [*expire_logs_days] - The number of days for automatic binary log file
|
||||
# removal.
|
||||
# [*log_bin_trust_function_creators] - It controls whether stored function
|
||||
# creators can be trusted not to create stored functions that will cause
|
||||
# unsafe events to be written to the binary log.
|
||||
# [*replicate_ignore_table] - Tells the slave SQL thread not to
|
||||
# replicate any statement that updates the specified table, even if any
|
||||
# other tables might be updated by the same statement.
|
||||
# [*replicate_wild_do_table] - Tells the slave thread to restrict
|
||||
# replication to statements where any of the updated tables match the
|
||||
# specified database and table name patterns.
|
||||
# [*replicate_wild_ignore_table] - Tells the slave thread not to
|
||||
# replicate a statement where any table matches the given wildcard pattern.
|
||||
# [*ft_min_word_len*] - minimum length of words to be indexed by mysql
|
||||
# [*ft_max_word_len*] - maximum length of words to be indexed by mysql
|
||||
#
|
||||
# Actions:
|
||||
#
|
||||
# Requires:
|
||||
#
|
||||
# class mysql::server
|
||||
#
|
||||
# Usage:
|
||||
#
|
||||
# class { 'mysql::config':
|
||||
# root_password => 'changeme',
|
||||
# bind_address => $::ipaddress,
|
||||
# }
|
||||
#
|
||||
class mysql::config(
|
||||
$root_password = $mysql::root_password,
|
||||
$old_root_password = $mysql::old_root_password,
|
||||
$bind_address = $mysql::bind_address,
|
||||
$port = $mysql::port,
|
||||
$etc_root_password = $mysql::etc_root_password,
|
||||
$manage_config_file = $mysql::manage_config_file,
|
||||
$service_name = $mysql::service_name,
|
||||
$config_file = $mysql::config_file,
|
||||
$socket = $mysql::socket,
|
||||
$pidfile = $mysql::pidfile,
|
||||
$datadir = $mysql::datadir,
|
||||
$ssl = $mysql::ssl,
|
||||
$ssl_ca = $mysql::ssl_ca,
|
||||
$ssl_cert = $mysql::ssl_cert,
|
||||
$ssl_key = $mysql::ssl_key,
|
||||
$log_error = $mysql::log_error,
|
||||
$default_engine = $mysql::default_engine,
|
||||
$root_group = $mysql::root_group,
|
||||
$restart = $mysql::restart,
|
||||
$purge_conf_dir = $mysql::purge_conf_dir,
|
||||
$key_buffer = $mysql::key_buffer,
|
||||
$max_allowed_packet = $mysql::max_allowed_packet,
|
||||
$thread_stack = $mysql::thread_stack,
|
||||
$thread_cache_size = $mysql::thread_cache_size,
|
||||
$myisam_recover = $mysql::myisam_recover,
|
||||
$query_cache_limit = $mysql::query_cache_limit,
|
||||
$query_cache_size = $mysql::query_cache_size,
|
||||
$max_binlog_size = $mysql::max_binlog_size,
|
||||
$expire_logs_days = $mysql::expire_logs_days,
|
||||
$max_connections = $mysql::max_connections,
|
||||
$tmp_table_size = 'UNSET',
|
||||
$max_heap_table_size = 'UNSET',
|
||||
$table_open_cache = 'UNSET',
|
||||
$long_query_time = 'UNSET',
|
||||
$character_set = 'UNSET',
|
||||
$server_id = 'UNSET',
|
||||
$sql_log_bin = 'UNSET',
|
||||
$log_bin = 'UNSET',
|
||||
$binlog_do_db = 'UNSET',
|
||||
$log_bin_trust_function_creators = 'UNSET',
|
||||
$replicate_ignore_table = 'UNSET',
|
||||
$replicate_wild_do_table = 'UNSET',
|
||||
$replicate_wild_ignore_table = 'UNSET',
|
||||
$ft_min_word_len = 'UNSET',
|
||||
$ft_max_word_len = 'UNSET'
|
||||
) inherits mysql {
|
||||
|
||||
File {
|
||||
owner => 'root',
|
||||
group => $root_group,
|
||||
mode => '0400',
|
||||
notify => $restart ? {
|
||||
true => Exec['mysqld-restart'],
|
||||
false => undef,
|
||||
},
|
||||
}
|
||||
|
||||
if $ssl and $ssl_ca == undef {
|
||||
fail('The ssl_ca parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
if $ssl and $ssl_cert == undef {
|
||||
fail('The ssl_cert parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
if $ssl and $ssl_key == undef {
|
||||
fail('The ssl_key parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
# This kind of sucks, that I have to specify a difference resource for
|
||||
# restart. the reason is that I need the service to be started before mods
|
||||
# to the config file which can cause a refresh
|
||||
exec { 'mysqld-restart':
|
||||
command => "service ${service_name} restart",
|
||||
logoutput => on_failure,
|
||||
refreshonly => true,
|
||||
path => '/sbin/:/usr/sbin/:/usr/bin/:/bin/',
|
||||
}
|
||||
|
||||
# manage root password if it is set
|
||||
if $root_password != 'UNSET' {
|
||||
case $old_root_password {
|
||||
'': { $old_pw='' }
|
||||
default: { $old_pw="-p'${old_root_password}'" }
|
||||
}
|
||||
|
||||
exec { 'set_mysql_rootpw':
|
||||
command => "mysqladmin -u root ${old_pw} password '${root_password}'",
|
||||
logoutput => true,
|
||||
environment => "HOME=${root_home}",
|
||||
unless => "mysqladmin -u root -p'${root_password}' status > /dev/null",
|
||||
path => '/usr/local/sbin:/usr/bin:/usr/local/bin',
|
||||
notify => $restart ? {
|
||||
true => Exec['mysqld-restart'],
|
||||
false => undef,
|
||||
},
|
||||
require => File['/etc/mysql/conf.d'],
|
||||
}
|
||||
|
||||
file { "${root_home}/.my.cnf":
|
||||
content => template('mysql/my.cnf.pass.erb'),
|
||||
require => Exec['set_mysql_rootpw'],
|
||||
notify => undef,
|
||||
}
|
||||
|
||||
if $etc_root_password {
|
||||
file{ '/etc/my.cnf':
|
||||
content => template('mysql/my.cnf.pass.erb'),
|
||||
require => Exec['set_mysql_rootpw'],
|
||||
}
|
||||
}
|
||||
} else {
|
||||
file { "${root_home}/.my.cnf":
|
||||
ensure => present,
|
||||
}
|
||||
}
|
||||
|
||||
file { '/etc/mysql':
|
||||
ensure => directory,
|
||||
mode => '0755',
|
||||
}
|
||||
|
||||
file { '/etc/mysql/conf.d':
|
||||
ensure => directory,
|
||||
mode => '0755',
|
||||
recurse => $purge_conf_dir,
|
||||
purge => $purge_conf_dir,
|
||||
}
|
||||
|
||||
if $manage_config_file {
|
||||
file { $config_file:
|
||||
content => template('mysql/my.cnf.erb'),
|
||||
mode => '0644',
|
||||
}
|
||||
}
|
||||
}
|
|
@ -50,19 +50,22 @@ define mysql::db (
|
|||
"${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.")
|
||||
$table = "${name}.*"
|
||||
|
||||
include '::mysql::client'
|
||||
|
||||
mysql_database { $name:
|
||||
ensure => $ensure,
|
||||
charset => $charset,
|
||||
collate => $collate,
|
||||
provider => 'mysql',
|
||||
require => [Class['mysql::server'],Package['mysql_client']],
|
||||
require => [ Class['mysql::server'], Class['mysql::client'] ],
|
||||
before => Mysql_user["${user}@${host}"],
|
||||
}
|
||||
|
||||
$user_resource = {
|
||||
ensure => $ensure,
|
||||
password_hash => mysql_password($password),
|
||||
provider => 'mysql'
|
||||
provider => 'mysql',
|
||||
require => Class['mysql::server'],
|
||||
}
|
||||
ensure_resource('mysql_user', "${user}@${host}", $user_resource)
|
||||
|
||||
|
@ -72,7 +75,7 @@ define mysql::db (
|
|||
provider => 'mysql',
|
||||
user => "${user}@${host}",
|
||||
table => $table,
|
||||
require => Mysql_user["${user}@${host}"],
|
||||
require => [ Mysql_user["${user}@${host}"], Class['mysql::server'] ],
|
||||
}
|
||||
|
||||
$refresh = ! $enforce_sql
|
||||
|
|
223
manifests/globals.pp
Normal file
223
manifests/globals.pp
Normal file
|
@ -0,0 +1,223 @@
|
|||
# PRIVATE CLASS: See README.md for more details.
|
||||
class mysql::globals (
|
||||
$override_options = {}
|
||||
) {
|
||||
|
||||
$default_options = {
|
||||
'bind_address' => '127.0.0.1',
|
||||
'binlog_do_db' => 'UNSET',
|
||||
'character_set' => 'UNSET',
|
||||
'default_engine' => 'UNSET',
|
||||
'etc_root_password' => false,
|
||||
'expire_logs_days' => '10',
|
||||
'ft_max_word_len' => 'UNSET',
|
||||
'ft_min_word_len' => 'UNSET',
|
||||
'key_buffer' => '16M',
|
||||
'log_bin' => 'UNSET',
|
||||
'log_bin_trust_function_creators' => 'UNSET',
|
||||
'long_query_time' => 'UNSET',
|
||||
'manage_config_file' => true,
|
||||
'max_allowed_packet' => '16M',
|
||||
'max_binlog_size' => '100M',
|
||||
'max_connections' => '151',
|
||||
'max_heap_table_size' => 'UNSET',
|
||||
'myisam_recover' => 'BACKUP',
|
||||
'old_root_password' => '',
|
||||
'port' => '3306',
|
||||
'purge_conf_dir' => false,
|
||||
'query_cache_limit' => '1M',
|
||||
'query_cache_size' => '16M',
|
||||
'replicate_ignore_table' => 'UNSET',
|
||||
'replicate_wild_do_table' => 'UNSET',
|
||||
'replicate_wild_ignore_table' => 'UNSET',
|
||||
'restart' => true,
|
||||
'root_password' => 'UNSET',
|
||||
'server_id' => 'UNSET',
|
||||
'sql_log_bin' => 'UNSET',
|
||||
'ssl' => false,
|
||||
'table_open_cache' => 'UNSET',
|
||||
'thread_cache_size' => '8',
|
||||
'thread_stack' => '256K',
|
||||
'tmp_table_size' => 'UNSET',
|
||||
}
|
||||
|
||||
# mysql::bindings
|
||||
$java_package_ensure = 'present'
|
||||
$perl_package_ensure = 'present'
|
||||
$python_package_ensure = 'present'
|
||||
$ruby_package_ensure = 'present'
|
||||
|
||||
case $::operatingsystem {
|
||||
'Ubuntu': {
|
||||
$service_provider = upstart
|
||||
}
|
||||
default: {
|
||||
$service_provider = undef
|
||||
}
|
||||
}
|
||||
|
||||
case $::osfamily {
|
||||
'RedHat': {
|
||||
if $::operatingsystem == 'Fedora' and $::operatingsystemrelease >= 19 {
|
||||
$client_package_name = 'mariadb'
|
||||
$server_package_name = 'mariadb-server'
|
||||
} else {
|
||||
$client_package_name = 'mysql'
|
||||
$server_package_name = 'mysql-server'
|
||||
}
|
||||
$distro_options = {
|
||||
'basedir' => '/usr',
|
||||
'config_file' => '/etc/my.cnf',
|
||||
'datadir' => '/var/lib/mysql',
|
||||
'log_error' => '/var/log/mysqld.log',
|
||||
'pidfile' => '/var/run/mysqld/mysqld.pid',
|
||||
'root_group' => 'root',
|
||||
'service_name' => 'mysqld',
|
||||
'socket' => '/var/lib/mysql/mysql.sock',
|
||||
'ssl_ca' => '/etc/mysql/cacert.pem',
|
||||
'ssl_cert' => '/etc/mysql/server-cert.pem',
|
||||
'ssl_key' => '/etc/mysql/server-key.pem',
|
||||
'tmpdir' => '/tmp',
|
||||
}
|
||||
# mysql::bindings
|
||||
$java_package_name = 'mysql-connector-java'
|
||||
$perl_package_name = 'perl-DBD-MySQL'
|
||||
$php_package_name = 'php-mysql'
|
||||
$python_package_name = 'MySQL-python'
|
||||
$ruby_package_name = 'ruby-mysql'
|
||||
$ruby_package_provider = 'gem'
|
||||
}
|
||||
|
||||
'Suse': {
|
||||
$client_package_name = $::operatingsystem ? {
|
||||
/OpenSuSE/ => 'mysql-community-server-client',
|
||||
/(SLES|SLED)/ => 'mysql-client',
|
||||
}
|
||||
$server_package_name = $::operatingsystem ? {
|
||||
/OpenSuSE/ => 'mysql-community-server',
|
||||
/(SLES|SLED)/ => 'mysql',
|
||||
}
|
||||
$distro_options = {
|
||||
'basedir' => $basedir,
|
||||
'config_file' => '/etc/my.cnf',
|
||||
'datadir' => '/var/lib/mysql',
|
||||
'log_error' => $::operatingsystem ? {
|
||||
/OpenSuSE/ => '/var/log/mysql/mysqld.log',
|
||||
/(SLES|SLED)/ => '/var/log/mysqld.log',
|
||||
},
|
||||
'pidfile' => $::operatingsystem ? {
|
||||
/OpenSuSE/ => '/var/run/mysql/mysqld.pid',
|
||||
/(SLES|SLED)/ => '/var/lib/mysql/mysqld.pid',
|
||||
},
|
||||
'root_group' => 'root',
|
||||
'service_name' => 'mysql',
|
||||
'socket' => $::operatingsystem ? {
|
||||
/OpenSuSE/ => '/var/run/mysql/mysql.sock',
|
||||
/(SLES|SLED)/ => '/var/lib/mysql/mysql.sock',
|
||||
},
|
||||
'ssl_ca' => '/etc/mysql/cacert.pem',
|
||||
'ssl_cert' => '/etc/mysql/server-cert.pem',
|
||||
'ssl_key' => '/etc/mysql/server-key.pem',
|
||||
'tmpdir' => '/tmp',
|
||||
}
|
||||
# mysql::bindings
|
||||
$java_package_name = 'mysql-connector-java'
|
||||
$perl_package_name = 'perl-DBD-mysql'
|
||||
$python_package_name = 'python-mysql'
|
||||
$ruby_package_name = $::operatingsystem ? {
|
||||
/OpenSuSE/ => 'rubygem-mysql',
|
||||
/(SLES|SLED)/ => 'ruby-mysql',
|
||||
}
|
||||
}
|
||||
|
||||
'Debian': {
|
||||
$client_package_name = 'mysql-client'
|
||||
$server_package_name = 'mysql-server'
|
||||
|
||||
$distro_options = {
|
||||
'basedir' => '/usr',
|
||||
'config_file' => '/etc/mysql/my.cnf',
|
||||
'datadir' => '/var/lib/mysql',
|
||||
'log_error' => '/var/log/mysql/error.log',
|
||||
'pidfile' => '/var/run/mysqld/mysqld.pid',
|
||||
'root_group' => 'root',
|
||||
'service_name' => 'mysql',
|
||||
'socket' => '/var/run/mysqld/mysqld.sock',
|
||||
'ssl_ca' => '/etc/mysql/cacert.pem',
|
||||
'ssl_cert' => '/etc/mysql/server-cert.pem',
|
||||
'ssl_key' => '/etc/mysql/server-key.pem',
|
||||
'tmpdir' => '/tmp',
|
||||
}
|
||||
# mysql::bindings
|
||||
$java_package_name = 'libmysql-java'
|
||||
$perl_package_name = 'libdbd-mysql-perl'
|
||||
$php_package_name = 'php5-mysql'
|
||||
$python_package_name = 'python-mysqldb'
|
||||
$ruby_package_name = 'libmysql-ruby'
|
||||
}
|
||||
|
||||
'FreeBSD': {
|
||||
$client_package_name = 'databases/mysql55-client'
|
||||
$server_package_name = 'databases/mysql55-server'
|
||||
$distro_options = {
|
||||
'basedir' => '/usr/local',
|
||||
'config_file' => '/var/db/mysql/my.cnf',
|
||||
'datadir' => '/var/db/mysql',
|
||||
'log_error' => "/var/db/mysql/${::hostname}.err",
|
||||
'pidfile' => '/var/db/mysql/mysql.pid',
|
||||
'root_group' => 'wheel',
|
||||
'service_name' => 'mysql-server',
|
||||
'socket' => '/tmp/mysql.sock',
|
||||
'ssl_ca' => undef,
|
||||
'ssl_cert' => undef,
|
||||
'ssl_key' => undef,
|
||||
'tmpdir' => '/tmp',
|
||||
}
|
||||
# mysql::bindings
|
||||
$java_package_name = 'databases/mysql-connector-java'
|
||||
$perl_package_name = 'p5-DBD-mysql'
|
||||
$php_package_name = 'php5-mysql'
|
||||
$python_package_name = 'databases/py-MySQLdb'
|
||||
$ruby_package_name = 'ruby-mysql'
|
||||
$ruby_package_provider = 'gem'
|
||||
}
|
||||
|
||||
default: {
|
||||
case $::operatingsystem {
|
||||
'Amazon': {
|
||||
$client_package_name = 'mysql'
|
||||
$server_package_name = 'mysql-server'
|
||||
$distro_options = {
|
||||
'basedir' => '/usr',
|
||||
'config_file' => '/etc/my.cnf',
|
||||
'datadir' => '/var/lib/mysql',
|
||||
'log_error' => '/var/log/mysqld.log',
|
||||
'pidfile' => '/var/run/mysqld/mysqld.pid',
|
||||
'root_group' => 'root',
|
||||
'service_name' => 'mysqld',
|
||||
'socket' => '/var/lib/mysql/mysql.sock',
|
||||
'ssl_ca' => '/etc/mysql/cacert.pem',
|
||||
'ssl_cert' => '/etc/mysql/server-cert.pem',
|
||||
'ssl_key' => '/etc/mysql/server-key.pem',
|
||||
'tmpdir' => '/tmp',
|
||||
}
|
||||
# mysql::bindings
|
||||
$java_package_name = 'mysql-connector-java'
|
||||
$perl_package_name = 'perl-DBD-MySQL'
|
||||
$php_package_name = 'php-mysql'
|
||||
$python_package_name = 'MySQL-python'
|
||||
$ruby_package_name = 'ruby-mysql'
|
||||
$ruby_package_provider = 'gem'
|
||||
}
|
||||
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} only support osfamily RedHat, Debian, and FreeBSD, or operatingsystem Amazon")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Create a merged together set of options. Rightmost hashes win over left.
|
||||
$options = merge($default_options, $distro_options, $override_options)
|
||||
|
||||
}
|
|
@ -1,119 +1,7 @@
|
|||
# Class: mysql
|
||||
#
|
||||
# This class installs mysql client software.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# [*basedir*] - The base directory mysql uses
|
||||
#
|
||||
# [*bind_address*] - The IP mysql binds to.
|
||||
#
|
||||
# [*client_package_name*] - The name of the mysql client package.
|
||||
#
|
||||
# [*client_package_ensure*] - State of the client package.
|
||||
#
|
||||
# [*config_file*] - The location of the server config file
|
||||
#
|
||||
# [*config_template*] - The template to use to generate my.cnf.
|
||||
#
|
||||
# [*datadir*] - The directory MySQL's datafiles are stored
|
||||
#
|
||||
# [*tmpdir*] - The directory MySQL's tmpfiles are stored
|
||||
#
|
||||
# [*default_engine*] - The default engine to use for tables
|
||||
#
|
||||
# [*etc_root_password*] - Whether or not to add the mysql root password to /etc/my.cnf
|
||||
#
|
||||
# [*log_error*] - Where to log errors
|
||||
#
|
||||
# [*manage_config_file*] - if the config file should be managed (default: true)
|
||||
#
|
||||
# [*manage_service*] - Boolean dictating if mysql::server should manage the service
|
||||
#
|
||||
# [*max_allowed_packet*] - Maximum network packet size mysqld will accept
|
||||
#
|
||||
# [*old_root_password*] - Previous root user password,
|
||||
#
|
||||
# [*package_ensure*] - ensure value for packages.
|
||||
#
|
||||
# [*package_name*] - legacy parameter used to specify the client package. Should not be used going forward
|
||||
#
|
||||
# [*php_package_name*] - The name of the phpmysql package to install
|
||||
#
|
||||
# [*pidfile*] - The location mysql will expect the pidfile to be, and will put it when starting the service.
|
||||
#
|
||||
# [*port*] - The port mysql listens on
|
||||
#
|
||||
# [*purge_conf_dir*] - Value fed to recurse and purge parameters of the /etc/mysql/conf.d resource
|
||||
#
|
||||
# [*restart*] - Whether to restart mysqld (true/false)
|
||||
#
|
||||
# [*root_group*] - Use specified group for root-owned files
|
||||
#
|
||||
# [*root_password*] - The root MySQL password to use
|
||||
#
|
||||
# [*server_package_ensure*] - ensure value for server packages.
|
||||
#
|
||||
# [*server_package_name*] - The name of the server package to install
|
||||
#
|
||||
# [*service_provider*] - Sets the service provider to upstart on Ubuntu systems for mysql::server.
|
||||
#
|
||||
# [*service_name*] - The name of the service to start
|
||||
#
|
||||
# [*socket*] - The location of the MySQL server socket file
|
||||
#
|
||||
# [*ssl*] - Whether or not to enable ssl
|
||||
#
|
||||
# [*ssl_ca*] - The location of the SSL CA Cert
|
||||
#
|
||||
# [*ssl_cert*] - The location of the SSL Certificate to use
|
||||
#
|
||||
# [*ssl_key*] - The SSL key to use
|
||||
#
|
||||
# Actions:
|
||||
#
|
||||
# Requires:
|
||||
#
|
||||
# Sample Usage:
|
||||
#
|
||||
class mysql(
|
||||
$basedir = $mysql::params::basedir,
|
||||
$bind_address = $mysql::params::bind_address,
|
||||
$client_package_name = $mysql::params::client_package_name,
|
||||
$client_package_ensure = $mysql::params::client_package_ensure,
|
||||
$config_file = $mysql::params::config_file,
|
||||
$config_template = $mysql::params::config_template,
|
||||
$datadir = $mysql::params::datadir,
|
||||
$tmpdir = $mysql::params::tmpdir,
|
||||
$default_engine = $mysql::params::default_engine,
|
||||
$etc_root_password = $mysql::params::etc_root_password,
|
||||
$log_error = $mysql::params::log_error,
|
||||
$manage_config_file = true,
|
||||
$manage_service = $mysql::params::manage_service,
|
||||
$max_allowed_packet = $mysql::params::max_allowed_packet,
|
||||
$old_root_password = $mysql::params::old_root_password,
|
||||
$package_ensure = $mysql::params::package_ensure,
|
||||
$php_package_name = $mysql::params::php_package_name,
|
||||
$pidfile = $mysql::params::pidfile,
|
||||
$port = $mysql::params::port,
|
||||
$purge_conf_dir = $mysql::params::purge_conf_dir,
|
||||
$max_connections = $mysql::params::max_connections,
|
||||
$restart = $mysql::params::restart,
|
||||
$root_group = $mysql::params::root_group,
|
||||
$root_password = $mysql::params::root_password,
|
||||
$server_package_name = $mysql::params::server_package_name,
|
||||
$service_name = $mysql::params::service_name,
|
||||
$service_provider = $mysql::params::service_provider,
|
||||
$socket = $mysql::params::socket,
|
||||
$ssl = $mysql::params::ssl,
|
||||
$ssl_ca = $mysql::params::ssl_ca,
|
||||
$ssl_cert = $mysql::params::ssl_cert,
|
||||
$ssl_key = $mysql::params::ssl_key
|
||||
) inherits mysql::params{
|
||||
class mysql {
|
||||
|
||||
include '::mysql::client::install'
|
||||
include '::mysql::bindings'
|
||||
|
||||
Class['mysql::config'] -> Mysql::Db <| |>
|
||||
notify { "This class has been deprecated and the functionality moved into a
|
||||
combination of mysql::client, mysql::server, and mysql::globals": }
|
||||
|
||||
}
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
# Class: mysql::params
|
||||
#
|
||||
# The mysql configuration settings.
|
||||
#
|
||||
# Parameters:
|
||||
#
|
||||
# Actions:
|
||||
#
|
||||
# Requires:
|
||||
#
|
||||
# Sample Usage:
|
||||
#
|
||||
class mysql::params {
|
||||
|
||||
$bind_address = '127.0.0.1'
|
||||
$client_package_ensure = 'present'
|
||||
$config_template = 'mysql/my.cnf.erb'
|
||||
$default_engine = 'UNSET'
|
||||
$etc_root_password = false
|
||||
$expire_logs_days = 10
|
||||
$key_buffer = '16M'
|
||||
$manage_service = true
|
||||
$max_allowed_packet = '16M'
|
||||
$max_binlog_size = '100M'
|
||||
$max_connections = 151
|
||||
$myisam_recover = 'BACKUP'
|
||||
$old_root_password = ''
|
||||
$package_ensure = 'present'
|
||||
$port = 3306
|
||||
$purge_conf_dir = false
|
||||
$query_cache_limit = '1M'
|
||||
$query_cache_size = '16M'
|
||||
$restart = true
|
||||
$root_password = 'UNSET'
|
||||
$ssl = false
|
||||
$thread_cache_size = 8
|
||||
$thread_stack = '256K'
|
||||
|
||||
# mysql::bindings
|
||||
$java_package_ensure = 'present'
|
||||
$perl_package_ensure = 'present'
|
||||
$python_package_ensure = 'present'
|
||||
$ruby_package_ensure = 'present'
|
||||
|
||||
case $::operatingsystem {
|
||||
'Ubuntu': {
|
||||
$service_provider = upstart
|
||||
}
|
||||
default: {
|
||||
$service_provider = undef
|
||||
}
|
||||
}
|
||||
|
||||
case $::osfamily {
|
||||
'RedHat': {
|
||||
if $::operatingsystem == 'Fedora' and $::operatingsystemrelease >= 19 {
|
||||
$client_package_name = 'mariadb'
|
||||
$server_package_name = 'mariadb-server'
|
||||
} else {
|
||||
$client_package_name = 'mysql'
|
||||
$server_package_name = 'mysql-server'
|
||||
}
|
||||
$basedir = '/usr'
|
||||
$config_file = '/etc/my.cnf'
|
||||
$datadir = '/var/lib/mysql'
|
||||
$log_error = '/var/log/mysqld.log'
|
||||
$php_package_name = 'php-mysql'
|
||||
$pidfile = '/var/run/mysqld/mysqld.pid'
|
||||
$root_group = 'root'
|
||||
$service_name = 'mysqld'
|
||||
$socket = '/var/lib/mysql/mysql.sock'
|
||||
$ssl_ca = '/etc/mysql/cacert.pem'
|
||||
$ssl_cert = '/etc/mysql/server-cert.pem'
|
||||
$ssl_key = '/etc/mysql/server-key.pem'
|
||||
$tmpdir = '/tmp'
|
||||
# mysql::bindings
|
||||
$java_package_name = 'mysql-connector-java'
|
||||
$perl_package_name = 'perl-DBD-MySQL'
|
||||
$python_package_name = 'MySQL-python'
|
||||
$ruby_package_name = 'ruby-mysql'
|
||||
$ruby_package_provider = 'gem'
|
||||
}
|
||||
|
||||
'Suse': {
|
||||
$basedir = '/usr'
|
||||
$config_file = '/etc/my.cnf'
|
||||
$client_package_name = $::operatingsystem ? {
|
||||
/OpenSuSE/ => 'mysql-community-server-client',
|
||||
/(SLES|SLED)/ => 'mysql-client',
|
||||
}
|
||||
$datadir = '/var/lib/mysql'
|
||||
$log_error = $::operatingsystem ? {
|
||||
/OpenSuSE/ => '/var/log/mysql/mysqld.log',
|
||||
/(SLES|SLED)/ => '/var/log/mysqld.log',
|
||||
}
|
||||
$pidfile = $::operatingsystem ? {
|
||||
/OpenSuSE/ => '/var/run/mysql/mysqld.pid',
|
||||
/(SLES|SLED)/ => '/var/lib/mysql/mysqld.pid',
|
||||
}
|
||||
$root_group = 'root'
|
||||
$server_package_name = $::operatingsystem ? {
|
||||
/OpenSuSE/ => 'mysql-community-server',
|
||||
/(SLES|SLED)/ => 'mysql',
|
||||
}
|
||||
$service_name = 'mysql'
|
||||
$socket = $::operatingsystem ? {
|
||||
/OpenSuSE/ => '/var/run/mysql/mysql.sock',
|
||||
/(SLES|SLED)/ => '/var/lib/mysql/mysql.sock',
|
||||
}
|
||||
$ssl_ca = '/etc/mysql/cacert.pem'
|
||||
$ssl_cert = '/etc/mysql/server-cert.pem'
|
||||
$ssl_key = '/etc/mysql/server-key.pem'
|
||||
$tmpdir = '/tmp'
|
||||
# mysql::bindings
|
||||
$java_package_name = 'mysql-connector-java'
|
||||
$perl_package_name = 'perl-DBD-mysql'
|
||||
$python_package_name = 'python-mysql'
|
||||
$ruby_package_name = $::operatingsystem ? {
|
||||
/OpenSuSE/ => 'rubygem-mysql',
|
||||
/(SLES|SLED)/ => 'ruby-mysql',
|
||||
}
|
||||
}
|
||||
|
||||
'Debian': {
|
||||
$basedir = '/usr'
|
||||
$client_package_name = 'mysql-client'
|
||||
$config_file = '/etc/mysql/my.cnf'
|
||||
$datadir = '/var/lib/mysql'
|
||||
$log_error = '/var/log/mysql/error.log'
|
||||
$php_package_name = 'php5-mysql'
|
||||
$pidfile = '/var/run/mysqld/mysqld.pid'
|
||||
$root_group = 'root'
|
||||
$server_package_name = 'mysql-server'
|
||||
$service_name = 'mysql'
|
||||
$socket = '/var/run/mysqld/mysqld.sock'
|
||||
$ssl_ca = '/etc/mysql/cacert.pem'
|
||||
$ssl_cert = '/etc/mysql/server-cert.pem'
|
||||
$ssl_key = '/etc/mysql/server-key.pem'
|
||||
$tmpdir = '/tmp'
|
||||
# mysql::bindings
|
||||
$java_package_name = 'libmysql-java'
|
||||
$perl_package_name = 'libdbd-mysql-perl'
|
||||
$python_package_name = 'python-mysqldb'
|
||||
$ruby_package_name = 'libmysql-ruby'
|
||||
}
|
||||
|
||||
'FreeBSD': {
|
||||
$basedir = '/usr/local'
|
||||
$datadir = '/var/db/mysql'
|
||||
$tmpdir = '/tmp'
|
||||
$service_name = 'mysql-server'
|
||||
$client_package_name = 'databases/mysql55-client'
|
||||
$server_package_name = 'databases/mysql55-server'
|
||||
$socket = '/tmp/mysql.sock'
|
||||
$pidfile = '/var/db/mysql/mysql.pid'
|
||||
$config_file = '/var/db/mysql/my.cnf'
|
||||
$log_error = "/var/db/mysql/${::hostname}.err"
|
||||
$php_package_name = 'php5-mysql'
|
||||
$root_group = 'wheel'
|
||||
$ssl_ca = undef
|
||||
$ssl_cert = undef
|
||||
$ssl_key = undef
|
||||
# mysql::bindings
|
||||
$java_package_name = 'databases/mysql-connector-java'
|
||||
$perl_package_name = 'p5-DBD-mysql'
|
||||
$python_package_name = 'databases/py-MySQLdb'
|
||||
$ruby_package_name = 'ruby-mysql'
|
||||
$ruby_package_provider = 'gem'
|
||||
}
|
||||
|
||||
default: {
|
||||
case $::operatingsystem {
|
||||
'Amazon': {
|
||||
$basedir = '/usr'
|
||||
$client_package_name = 'mysql'
|
||||
$config_file = '/etc/my.cnf'
|
||||
$datadir = '/var/lib/mysql'
|
||||
$log_error = '/var/log/mysqld.log'
|
||||
$php_package_name = 'php-mysql'
|
||||
$root_group = 'root'
|
||||
$server_package_name = 'mysql-server'
|
||||
$service_name = 'mysqld'
|
||||
$socket = '/var/lib/mysql/mysql.sock'
|
||||
$ssl_ca = '/etc/mysql/cacert.pem'
|
||||
$ssl_cert = '/etc/mysql/server-cert.pem'
|
||||
$ssl_key = '/etc/mysql/server-key.pem'
|
||||
$tmpdir = '/tmp'
|
||||
# mysql::bindings
|
||||
$java_package_name = 'mysql-connector-java'
|
||||
$perl_package_name = 'perl-DBD-MySQL'
|
||||
$python_package_name = 'MySQL-python'
|
||||
$ruby_package_name = 'ruby-mysql'
|
||||
$ruby_package_provider = 'gem'
|
||||
}
|
||||
|
||||
default: {
|
||||
fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} only support osfamily RedHat, Debian, and FreeBSD, or operatingsystem Amazon")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -4,7 +4,6 @@
|
|||
# my.cnf
|
||||
#
|
||||
# Parameters:
|
||||
# [*config_hash*] - hash of config parameters that need to be set.
|
||||
# [*enabled*] - Defaults to true, boolean to set service ensure.
|
||||
# [*manage_service*] - Boolean dictating if mysql::server should manage the service
|
||||
# [*package_ensure*] - Ensure state for package. Can be specified as version.
|
||||
|
@ -20,39 +19,24 @@
|
|||
# Sample Usage:
|
||||
#
|
||||
class mysql::server (
|
||||
$config_hash = {},
|
||||
$enabled = true,
|
||||
$manage_service = true,
|
||||
$package_ensure = $mysql::package_ensure,
|
||||
$package_name = $mysql::server_package_name,
|
||||
$service_name = $mysql::service_name,
|
||||
$service_provider = $mysql::service_provider
|
||||
) inherits mysql {
|
||||
$package_ensure = $mysql::globals::package_ensure,
|
||||
$package_name = $mysql::globals::server_package_name,
|
||||
$service_name = $mysql::globals::service_name,
|
||||
$service_provider = $mysql::globals::service_provider
|
||||
) inherits mysql::globals {
|
||||
|
||||
Class['mysql::server'] -> Class['mysql::config']
|
||||
Class['mysql::server::root_password'] -> Mysql::Db <| |>
|
||||
|
||||
$config_class = { 'mysql::config' => $config_hash }
|
||||
include '::mysql::server::install'
|
||||
include '::mysql::server::config'
|
||||
include '::mysql::server::service'
|
||||
include '::mysql::server::root_password'
|
||||
|
||||
create_resources( 'class', $config_class )
|
||||
Class['mysql::server::install'] ->
|
||||
Class['mysql::server::config'] ->
|
||||
Class['mysql::server::service'] ->
|
||||
Class['mysql::server::root_password']
|
||||
|
||||
package { 'mysql-server':
|
||||
ensure => $package_ensure,
|
||||
name => $package_name,
|
||||
}
|
||||
|
||||
if $enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
}
|
||||
|
||||
if $manage_service {
|
||||
service { 'mysqld':
|
||||
ensure => $service_ensure,
|
||||
name => $service_name,
|
||||
enable => $enabled,
|
||||
require => Package['mysql-server'],
|
||||
provider => $service_provider,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,16 +9,16 @@ class mysql::server::account_security {
|
|||
'@localhost',
|
||||
'@%']:
|
||||
ensure => 'absent',
|
||||
require => Class['mysql::config'],
|
||||
require => Class['mysql::server::config'],
|
||||
}
|
||||
if ($::fqdn != $::hostname) {
|
||||
mysql_user { ["root@${::hostname}", "@${::hostname}"]:
|
||||
ensure => 'absent',
|
||||
require => Class['mysql::config'],
|
||||
require => Class['mysql::server::config'],
|
||||
}
|
||||
}
|
||||
mysql_database { 'test':
|
||||
ensure => 'absent',
|
||||
require => Class['mysql::config'],
|
||||
require => Class['mysql::server::config'],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,111 +1,43 @@
|
|||
# Creates a my.cnf like config file in the conf.d/ directory.
|
||||
#
|
||||
# IMPORTANT: this should be used AFTER the inclusion of
|
||||
# mysql::server because it needs some variables
|
||||
# out of the mysql::config class which will be
|
||||
# included!
|
||||
#
|
||||
# == Parameters:
|
||||
#
|
||||
# - name: is the name of the file
|
||||
# - notify_service: whether to notify the mysql daemon or not (default: true)
|
||||
# - settings: either a string which should be the content of the file
|
||||
# or a hash with the following structure
|
||||
#
|
||||
# section => {
|
||||
# <key> => <value>,
|
||||
# ...
|
||||
# },
|
||||
# ...
|
||||
#
|
||||
# +section+ means all these sections you can set in
|
||||
# an configuration file like +mysqld+, +client+,
|
||||
# +mysqldump+ and so on
|
||||
# +key+ has to be a valid property which you can set like
|
||||
# +datadir+, +socket+ or even flags like +read-only+
|
||||
#
|
||||
# +value+ can be
|
||||
# a) a string as the value
|
||||
# b) +true+ or +false+ to set a flag like 'read-only' or leave
|
||||
# it out (+false+ means, nothing will be done)
|
||||
# c) an array of values which can be of type a) and/or b)
|
||||
#
|
||||
#
|
||||
# == Examples:
|
||||
#
|
||||
# Easy one:
|
||||
#
|
||||
# mysql::server::config { 'basic_config':
|
||||
# settings => "[mysqld]\nskip-external-locking\n"
|
||||
# }
|
||||
#
|
||||
# This will create the file /etc/mysql/conf.d/basic_config.cnf with
|
||||
# the following content:
|
||||
#
|
||||
# [mysqld]
|
||||
# skip-external-locking
|
||||
#
|
||||
#
|
||||
# More complex example:
|
||||
#
|
||||
# mysql::server::config { 'basic_config':
|
||||
# settings => {
|
||||
# 'mysqld' => {
|
||||
# 'query_cache_limit' => '5M',
|
||||
# 'query_cache_size' => '128M',
|
||||
# 'port' => 3300,
|
||||
# 'skip-external-locking' => true,
|
||||
# 'replicate-ignore-db' => [
|
||||
# 'tmp_table',
|
||||
# 'whateveryouwant'
|
||||
# ]
|
||||
# },
|
||||
#
|
||||
# 'client' => {
|
||||
# 'port' => 3300
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# This will create the file /etc/mysql/conf.d/basic_config.cnf with
|
||||
# the following content:
|
||||
#
|
||||
# [mysqld]
|
||||
# query_cache_limit = 5M
|
||||
# query_cache_size = 128M
|
||||
# port = 3300
|
||||
# skip-external-locking
|
||||
# replicate-ignore-db = tmp_table
|
||||
# replicate-ignore-db = whateveryouwant
|
||||
#
|
||||
# [client]
|
||||
# port = 3300
|
||||
#
|
||||
define mysql::server::config (
|
||||
$settings,
|
||||
$notify_service = true
|
||||
) {
|
||||
include mysql::config
|
||||
# See README.me for options.
|
||||
class mysql::server::config {
|
||||
|
||||
if is_hash($settings) {
|
||||
$content = template('mysql/my.conf.cnf.erb')
|
||||
} else {
|
||||
$content = $settings
|
||||
$options = $mysql::globals::options
|
||||
|
||||
File {
|
||||
owner => 'root',
|
||||
group => $options['root_group'],
|
||||
mode => '0400',
|
||||
notify => Class['mysql::server::service'],
|
||||
}
|
||||
|
||||
file { "/etc/mysql/conf.d/${name}.cnf":
|
||||
ensure => file,
|
||||
content => $content,
|
||||
owner => 'root',
|
||||
group => $mysql::config::root_group,
|
||||
mode => '0644',
|
||||
require => Package['mysql-server'],
|
||||
if ( $options['ssl'] ) and ( $options['ssl_ca'] == undef ) {
|
||||
fail('The ssl_ca parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
if $notify_service {
|
||||
File["/etc/mysql/conf.d/${name}.cnf"] {
|
||||
# XXX notifying the Service gives us a dependency circle but I don't understand why
|
||||
notify => Exec['mysqld-restart']
|
||||
if ( $options['ssl'] ) and ( $options['ssl_cert'] == undef ) {
|
||||
fail('The ssl_cert parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
if ( $options['ssl'] ) and ( $options['ssl_key'] ) == undef {
|
||||
fail('The ssl_key parameter is required when ssl is true')
|
||||
}
|
||||
|
||||
file { '/etc/mysql':
|
||||
ensure => directory,
|
||||
mode => '0755',
|
||||
}
|
||||
|
||||
file { '/etc/mysql/conf.d':
|
||||
ensure => directory,
|
||||
mode => '0755',
|
||||
recurse => $options['purge_conf_dir'],
|
||||
purge => $options['purge_conf_dir'],
|
||||
}
|
||||
|
||||
if $options['manage_config_file'] {
|
||||
file { $options['config_file']:
|
||||
content => template('mysql/my.cnf.erb'),
|
||||
mode => '0644',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
9
manifests/server/install.pp
Normal file
9
manifests/server/install.pp
Normal file
|
@ -0,0 +1,9 @@
|
|||
#
|
||||
class mysql::server::install {
|
||||
|
||||
package { 'mysql-server':
|
||||
ensure => $mysql::server::package_ensure,
|
||||
name => $mysql::server::package_name,
|
||||
}
|
||||
|
||||
}
|
111
manifests/server/old_config.pp
Normal file
111
manifests/server/old_config.pp
Normal file
|
@ -0,0 +1,111 @@
|
|||
# Creates a my.cnf like config file in the conf.d/ directory.
|
||||
#
|
||||
# IMPORTANT: this should be used AFTER the inclusion of
|
||||
# mysql::server because it needs some variables
|
||||
# out of the mysql::config class which will be
|
||||
# included!
|
||||
#
|
||||
# == Parameters:
|
||||
#
|
||||
# - name: is the name of the file
|
||||
# - notify_service: whether to notify the mysql daemon or not (default: true)
|
||||
# - settings: either a string which should be the content of the file
|
||||
# or a hash with the following structure
|
||||
#
|
||||
# section => {
|
||||
# <key> => <value>,
|
||||
# ...
|
||||
# },
|
||||
# ...
|
||||
#
|
||||
# +section+ means all these sections you can set in
|
||||
# an configuration file like +mysqld+, +client+,
|
||||
# +mysqldump+ and so on
|
||||
# +key+ has to be a valid property which you can set like
|
||||
# +datadir+, +socket+ or even flags like +read-only+
|
||||
#
|
||||
# +value+ can be
|
||||
# a) a string as the value
|
||||
# b) +true+ or +false+ to set a flag like 'read-only' or leave
|
||||
# it out (+false+ means, nothing will be done)
|
||||
# c) an array of values which can be of type a) and/or b)
|
||||
#
|
||||
#
|
||||
# == Examples:
|
||||
#
|
||||
# Easy one:
|
||||
#
|
||||
# mysql::server::config { 'basic_config':
|
||||
# settings => "[mysqld]\nskip-external-locking\n"
|
||||
# }
|
||||
#
|
||||
# This will create the file /etc/mysql/conf.d/basic_config.cnf with
|
||||
# the following content:
|
||||
#
|
||||
# [mysqld]
|
||||
# skip-external-locking
|
||||
#
|
||||
#
|
||||
# More complex example:
|
||||
#
|
||||
# mysql::server::config { 'basic_config':
|
||||
# settings => {
|
||||
# 'mysqld' => {
|
||||
# 'query_cache_limit' => '5M',
|
||||
# 'query_cache_size' => '128M',
|
||||
# 'port' => 3300,
|
||||
# 'skip-external-locking' => true,
|
||||
# 'replicate-ignore-db' => [
|
||||
# 'tmp_table',
|
||||
# 'whateveryouwant'
|
||||
# ]
|
||||
# },
|
||||
#
|
||||
# 'client' => {
|
||||
# 'port' => 3300
|
||||
# }
|
||||
# }
|
||||
# }
|
||||
#
|
||||
# This will create the file /etc/mysql/conf.d/basic_config.cnf with
|
||||
# the following content:
|
||||
#
|
||||
# [mysqld]
|
||||
# query_cache_limit = 5M
|
||||
# query_cache_size = 128M
|
||||
# port = 3300
|
||||
# skip-external-locking
|
||||
# replicate-ignore-db = tmp_table
|
||||
# replicate-ignore-db = whateveryouwant
|
||||
#
|
||||
# [client]
|
||||
# port = 3300
|
||||
#
|
||||
define mysql::server::config (
|
||||
$settings,
|
||||
$notify_service = true
|
||||
) {
|
||||
include mysql::config
|
||||
|
||||
if is_hash($settings) {
|
||||
$content = template('mysql/my.conf.cnf.erb')
|
||||
} else {
|
||||
$content = $settings
|
||||
}
|
||||
|
||||
file { "/etc/mysql/conf.d/${name}.cnf":
|
||||
ensure => file,
|
||||
content => $content,
|
||||
owner => 'root',
|
||||
group => $mysql::config::root_group,
|
||||
mode => '0644',
|
||||
require => Package['mysql-server'],
|
||||
}
|
||||
|
||||
if $notify_service {
|
||||
File["/etc/mysql/conf.d/${name}.cnf"] {
|
||||
# XXX notifying the Service gives us a dependency circle but I don't understand why
|
||||
notify => Exec['mysqld-restart']
|
||||
}
|
||||
}
|
||||
}
|
55
manifests/server/root_password.pp
Normal file
55
manifests/server/root_password.pp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#
|
||||
class mysql::server::root_password {
|
||||
|
||||
$options = $mysql::globals::options
|
||||
$service_restart = $options['restart'] ? {
|
||||
true => Exec['mysqld-restart'],
|
||||
false => undef,
|
||||
}
|
||||
|
||||
# This kind of sucks, that I have to specify a difference resource for
|
||||
# restart. the reason is that I need the service to be started before mods
|
||||
# to the config file which can cause a refresh
|
||||
exec { 'mysqld-restart':
|
||||
command => "service ${options['service_name']} restart",
|
||||
logoutput => on_failure,
|
||||
refreshonly => true,
|
||||
path => '/sbin/:/usr/sbin/:/usr/bin/:/bin/',
|
||||
}
|
||||
|
||||
# manage root password if it is set
|
||||
if $options['root_password'] != 'UNSET' {
|
||||
case $options['old_root_password'] {
|
||||
'': { $old_pw='' }
|
||||
default: { $old_pw="-p'${options[old_root_password]}'" }
|
||||
}
|
||||
|
||||
exec { 'set_mysql_rootpw':
|
||||
command => "mysqladmin -u root ${old_pw} password '${options[root_password]}'",
|
||||
logoutput => true,
|
||||
environment => "HOME=${::root_home}",
|
||||
unless => "mysqladmin -u root -p'${options[root_password]}' status > /dev/null",
|
||||
path => '/usr/local/sbin:/usr/bin:/usr/local/bin',
|
||||
notify => $service_restart,
|
||||
require => File['/etc/mysql/conf.d'],
|
||||
}
|
||||
|
||||
file { "${::root_home}/.my.cnf":
|
||||
content => template('mysql/my.cnf.pass.erb'),
|
||||
require => Exec['set_mysql_rootpw'],
|
||||
notify => undef,
|
||||
}
|
||||
|
||||
if $options['etc_root_password'] {
|
||||
file{ '/etc/my.cnf':
|
||||
content => template('mysql/my.cnf.pass.erb'),
|
||||
require => Exec['set_mysql_rootpw'],
|
||||
}
|
||||
}
|
||||
} else {
|
||||
file { "${::root_home}/.my.cnf":
|
||||
ensure => present,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
19
manifests/server/service.pp
Normal file
19
manifests/server/service.pp
Normal file
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
class mysql::server::service {
|
||||
|
||||
if $mysql::server::enabled {
|
||||
$service_ensure = 'running'
|
||||
} else {
|
||||
$service_ensure = 'stopped'
|
||||
}
|
||||
|
||||
if $mysql::server::manage_service {
|
||||
service { 'mysqld':
|
||||
ensure => $service_ensure,
|
||||
name => $mysql::server::service_name,
|
||||
enable => $mysql::server::enabled,
|
||||
provider => $mysql::server::service_provider,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,8 @@ require 'spec_helper_system'
|
|||
describe 'mysql::backup class' do
|
||||
context 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': config_hash => { 'root_password' => 'foo' } }
|
||||
class { 'mysql::globals': override_options => { 'root_password' => 'password' } }
|
||||
class { 'mysql::server': }
|
||||
mysql::db { 'backup1':
|
||||
user => 'backup',
|
||||
password => 'secret',
|
||||
|
@ -30,7 +31,7 @@ describe 'mysql::backup class' do
|
|||
its(:exit_code) { should be_zero }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context 'should dump all databases to single file' do
|
||||
describe command('ls /tmp/backups/ | grep -c "mysql_backup_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"') do
|
||||
it { should return_stdout /1/ }
|
||||
|
@ -42,7 +43,8 @@ describe 'mysql::backup class' do
|
|||
|
||||
context 'should create one file per database' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql::server': config_hash => { 'root_password' => 'foo' } }
|
||||
class { 'mysql::globals': override_options => { 'root_password' => 'password' } }
|
||||
class { 'mysql::server': }
|
||||
mysql::db { 'backup1':
|
||||
user => 'backup',
|
||||
password => 'secret',
|
||||
|
@ -68,7 +70,7 @@ describe 'mysql::backup class' do
|
|||
context shell("/usr/local/sbin/mysqlbackup.sh") do
|
||||
its(:exit_code) { should be_zero }
|
||||
end
|
||||
|
||||
|
||||
describe command('ls /tmp/backups/ | grep -c "mysql_backup_backup1_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"') do
|
||||
it { should return_stdout /1/ }
|
||||
it { should return_exit_status 0 }
|
||||
|
|
|
@ -5,7 +5,7 @@ describe 'mysql::db define' do
|
|||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql': root_password => 'password', }
|
||||
class { 'mysql::globals': override_options => { 'root_password' => 'password' } }
|
||||
class { 'mysql::server': }
|
||||
mysql::db { 'spec1':
|
||||
user => 'root',
|
||||
|
@ -32,7 +32,7 @@ describe 'mysql::db define' do
|
|||
# Using puppet_apply as a helper
|
||||
it 'should work with no errors' do
|
||||
pp = <<-EOS
|
||||
class { 'mysql': root_password => 'password', }
|
||||
class { 'mysql::globals': override_options => { 'root_password' => 'password' } }
|
||||
class { 'mysql::server': }
|
||||
file { '/tmp/spec.sql':
|
||||
ensure => file,
|
||||
|
|
|
@ -1,105 +1,105 @@
|
|||
[client]
|
||||
port = <%= @port %>
|
||||
socket = <%= @socket %>
|
||||
<% if @character_set != 'UNSET' -%>
|
||||
default-character-set = <%= @character_set %>
|
||||
port = <%= @options['port'] %>
|
||||
socket = <%= @options['socket'] %>
|
||||
<% if @options['character_set'] != 'UNSET' -%>
|
||||
default-character-set = <%= @options['character_set'] %>
|
||||
<% end -%>
|
||||
|
||||
[mysqld_safe]
|
||||
socket = <%= @socket %>
|
||||
socket = <%= @options['socket'] %>
|
||||
nice = 0
|
||||
<% if @log_error == 'syslog' -%>
|
||||
<% if @options['log_error'] == 'syslog' -%>
|
||||
syslog
|
||||
<% end -%>
|
||||
[mysqld]
|
||||
user = mysql
|
||||
pid-file = <%= @pidfile %>
|
||||
socket = <%= @socket %>
|
||||
port = <%= @port %>
|
||||
basedir = <%= @basedir %>
|
||||
datadir = <%= @datadir %>
|
||||
tmpdir = <%= @tmpdir %>
|
||||
max_connections = <%= @max_connections %>
|
||||
pid-file = <%= @options['pidfile'] %>
|
||||
socket = <%= @options['socket'] %>
|
||||
port = <%= @options['port'] %>
|
||||
basedir = <%= @options['basedir'] %>
|
||||
datadir = <%= @options['datadir'] %>
|
||||
tmpdir = <%= @options['tmpdir'] %>
|
||||
max_connections = <%= @options['max_connections'] %>
|
||||
skip-external-locking
|
||||
|
||||
<% if @bind_address -%>
|
||||
bind-address = <%= @bind_address %>
|
||||
<% if @options['bind_address'] -%>
|
||||
bind-address = <%= @options['bind_address'] %>
|
||||
<% end -%>
|
||||
key_buffer = <%= @key_buffer %>
|
||||
max_allowed_packet = <%= @max_allowed_packet %>
|
||||
thread_stack = <%= @thread_stack %>
|
||||
thread_cache_size = <%= @thread_cache_size %>
|
||||
myisam-recover = <%= @myisam_recover %>
|
||||
query_cache_limit = <%= @query_cache_limit %>
|
||||
query_cache_size = <%= @query_cache_size %>
|
||||
expire_logs_days = <%= @expire_logs_days %>
|
||||
max_binlog_size = <%= @max_binlog_size %>
|
||||
key_buffer = <%= @options['key_buffer'] %>
|
||||
max_allowed_packet = <%= @options['max_allowed_packet'] %>
|
||||
thread_stack = <%= @options['thread_stack'] %>
|
||||
thread_cache_size = <%= @options['thread_cache_size'] %>
|
||||
myisam-recover = <%= @options['myisam_recover'] %>
|
||||
query_cache_limit = <%= @options['query_cache_limit'] %>
|
||||
query_cache_size = <%= @options['query_cache_size'] %>
|
||||
expire_logs_days = <%= @options['expire_logs_days'] %>
|
||||
max_binlog_size = <%= @options['max_binlog_size'] %>
|
||||
|
||||
<% if @max_connections != 'UNSET' -%>
|
||||
max_connections = <%= @max_connections %>
|
||||
<% if @options['max_connections'] != 'UNSET' -%>
|
||||
max_connections = <%= @options['max_connections'] %>
|
||||
<% end -%>
|
||||
<% if @tmp_table_size != 'UNSET' -%>
|
||||
tmp_table_size = <%= @tmp_table_size %>
|
||||
<% if @options['tmp_table_size'] != 'UNSET' -%>
|
||||
tmp_table_size = <%= @options['tmp_table_size'] %>
|
||||
<% end -%>
|
||||
<% if @max_heap_table_size != 'UNSET' -%>
|
||||
max_heap_table_size = <%= @max_heap_table_size %>
|
||||
<% if @options['max_heap_table_size'] != 'UNSET' -%>
|
||||
max_heap_table_size = <%= @options['max_heap_table_size'] %>
|
||||
<% end -%>
|
||||
<% if @table_open_cache != 'UNSET' -%>
|
||||
table_open_cache = <%= @table_open_cache %>
|
||||
<% if @options['table_open_cache'] != 'UNSET' -%>
|
||||
table_open_cache = <%= @options['table_open_cache'] %>
|
||||
<% end -%>
|
||||
<% if @long_query_time != 'UNSET' -%>
|
||||
long_query_time = <%= @long_query_time %>
|
||||
<% if @options['long_query_time'] != 'UNSET' -%>
|
||||
long_query_time = <%= @options['long_query_time'] %>
|
||||
<% end -%>
|
||||
<% if @server_id != 'UNSET' -%>
|
||||
server-id = <%= @server_id %>
|
||||
<% if @options['server_id'] != 'UNSET' -%>
|
||||
server-id = <%= @options['server_id'] %>
|
||||
<% end -%>
|
||||
<% if @sql_log_bin != 'UNSET' -%>
|
||||
sql_log_bin = <%= @sql_log_bin %>
|
||||
<% if @options['sql_log_bin'] != 'UNSET' -%>
|
||||
sql_log_bin = <%= @options['sql_log_bin'] %>
|
||||
<% end -%>
|
||||
<% if @log_bin != 'UNSET' -%>
|
||||
log-bin = <%= @log_bin %>
|
||||
<% if @options['log_bin'] != 'UNSET' -%>
|
||||
log-bin = <%= @options['log_bin'] %>
|
||||
<% end -%>
|
||||
<% if @binlog_do_db != 'UNSET' -%>
|
||||
binlog-do-db = <%= @binlog_do_db %>
|
||||
<% if @options['binlog_do_db'] != 'UNSET' -%>
|
||||
binlog-do-db = <%= @options['binlog_do_db'] %>
|
||||
<% end -%>
|
||||
<% if @log_bin_trust_function_creators != 'UNSET' -%>
|
||||
log_bin_trust_function_creators = <%= @log_bin_trust_function_creators %>
|
||||
<% if @options['log_bin_trust_function_creators'] != 'UNSET' -%>
|
||||
log_bin_trust_function_creators = <%= @options['log_bin_trust_function_creators'] %>
|
||||
<% end -%>
|
||||
<% if @replicate_ignore_table != 'UNSET' -%>
|
||||
replicate-ignore-table = <%= @replicate_ignore_table %>
|
||||
<% if @options['replicate_ignore_table'] != 'UNSET' -%>
|
||||
replicate-ignore-table = <%= @options['replicate_ignore_table'] %>
|
||||
<% end -%>
|
||||
<% if @replicate_wild_do_table != 'UNSET' -%>
|
||||
replicate-wild-do-table = <%= @replicate_wild_do_table %>
|
||||
<% if @options['replicate_wild_do_table'] != 'UNSET' -%>
|
||||
replicate-wild-do-table = <%= @options['replicate_wild_do_table'] %>
|
||||
<% end -%>
|
||||
<% if @replicate_wild_ignore_table != 'UNSET' -%>
|
||||
replicate-wild-ignore-table = <%= @replicate_wild_ignore_table %>
|
||||
<% if @options['replicate_wild_ignore_table'] != 'UNSET' -%>
|
||||
replicate-wild-ignore-table = <%= @options['replicate_wild_ignore_table'] %>
|
||||
<% end -%>
|
||||
<% if @ft_min_word_len != 'UNSET' -%>
|
||||
ft_min_word_len = <%= @ft_min_word_len %>
|
||||
<% if @options['ft_min_word_len'] != 'UNSET' -%>
|
||||
ft_min_word_len = <%= @options['ft_min_word_len'] %>
|
||||
<% end -%>
|
||||
<% if @ft_max_word_len != 'UNSET' -%>
|
||||
ft_max_word_len = <%= @ft_max_word_len %>
|
||||
<% if @options['ft_max_word_len'] != 'UNSET' -%>
|
||||
ft_max_word_len = <%= @options['ft_max_word_len'] %>
|
||||
<% end -%>
|
||||
|
||||
<% if @log_error != 'syslog' -%>
|
||||
log_error = <%= @log_error %>
|
||||
<% if @options['log_error'] != 'syslog' -%>
|
||||
log_error = <%= @options['log_error'] %>
|
||||
<% end -%>
|
||||
<% if @default_engine != 'UNSET' %>
|
||||
default-storage-engine = <%= @default_engine %>
|
||||
<% if @options['default_engine'] != 'UNSET' %>
|
||||
default-storage-engine = <%= @options['default_engine'] %>
|
||||
<% end -%>
|
||||
<% if @character_set != 'UNSET' -%>
|
||||
character-set-server = <%= @character_set %>
|
||||
<% if @options['character_set'] != 'UNSET' -%>
|
||||
character-set-server = <%= @options['character_set'] %>
|
||||
<% end -%>
|
||||
<% if @ssl %>
|
||||
ssl-ca = <%= @ssl_ca %>
|
||||
ssl-cert = <%= @ssl_cert %>
|
||||
ssl-key = <%= @ssl_key %>
|
||||
<% if @options['ssl'] %>
|
||||
ssl-ca = <%= @options['ssl_ca'] %>
|
||||
ssl-cert = <%= @options['ssl_cert'] %>
|
||||
ssl-key = <%= @options['ssl_key'] %>
|
||||
<% end -%>
|
||||
|
||||
[mysqldump]
|
||||
quick
|
||||
quote-names
|
||||
max_allowed_packet = <%= @max_allowed_packet %>
|
||||
max_allowed_packet = <%= @options['max_allowed_packet'] %>
|
||||
[mysql]
|
||||
[isamchk]
|
||||
key_buffer = 16M
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
[client]
|
||||
user=root
|
||||
host=localhost
|
||||
<% unless @root_password == 'UNSET' -%>
|
||||
password='<%= @root_password %>'
|
||||
<% unless @options['root_password'] == 'UNSET' -%>
|
||||
password='<%= @options['root_password'] %>'
|
||||
<% end -%>
|
||||
socket=<%= @socket -%>
|
||||
socket=<%= @options['socket'] -%>
|
||||
|
|
Loading…
Reference in a new issue