Revert "Merge pull request #90 from emonty/master"

This reverts commit 063d72493c, reversing
changes made to 9c10b3a6c3.
This commit is contained in:
Dan Bode 2012-08-15 18:03:37 -07:00
parent 063d72493c
commit 211da13545
9 changed files with 78 additions and 392 deletions

View file

@ -6,5 +6,3 @@ license 'Apache 2.0'
summary 'Mysql module'
description 'Mysql module'
project_page 'http://github.com/puppetlabs/puppetlabs-mysql'
dependency 'openstackci/apparmor', '>= 0.0.1'

View file

@ -7,40 +7,31 @@ Puppet::Type.type(:database).provide(:mysql) do
optional_commands :mysql => 'mysql'
optional_commands :mysqladmin => 'mysqladmin'
def defaults_file
case Facter.value(:operatingsystem)
when "Debian", "Ubuntu"
return "--defaults-file=/etc/mysql/debian.cnf"
else
return ""
end
end
def self.instances
mysql(defaults_file, '-NBe', "show databases").split("\n").collect do |name|
mysql('-NBe', "show databases").split("\n").collect do |name|
new(:name => name)
end
end
def create
mysql(defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{resource[:charset]}")
mysql('-NBe', "create database `#{@resource[:name]}` character set #{resource[:charset]}")
end
def destroy
mysqladmin(defaults_file, '-f', 'drop', @resource[:name])
mysqladmin('-f', 'drop', @resource[:name])
end
def charset
mysql(defaults_file, '-NBe', "show create database `#{resource[:name]}`").match(/.*?(\S+)\s\*\//)[1]
mysql('-NBe', "show create database `#{resource[:name]}`").match(/.*?(\S+)\s\*\//)[1]
end
def charset=(value)
mysql(defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}")
mysql('-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}")
end
def exists?
begin
mysql(defaults_file, '-NBe', "show databases").match(/^#{@resource[:name]}$/)
mysql('-NBe', "show databases").match(/^#{@resource[:name]}$/)
rescue => e
debug(e.message)
return nil

View file

@ -12,15 +12,6 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
optional_commands :mysql => 'mysql'
optional_commands :mysqladmin => 'mysqladmin'
def defaults_file
case Facter.value(:operatingsystem)
when "Debian", "Ubuntu"
return "--defaults-file=/etc/mysql/debian.cnf"
else
return ""
end
end
def self.prefetch(resources)
@user_privs = query_user_privs
@db_privs = query_db_privs
@ -43,19 +34,19 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
end
def self.query_user_privs
results = mysql(defaults_file, "-Be", "describe user")
results = mysql("mysql", "-Be", "describe user")
column_names = results.split(/\n/).map { |l| l.chomp.split(/\t/)[0] }
@user_privs = column_names.delete_if { |e| !( e =~/_priv$/) }
end
def self.query_db_privs
results = mysql(defaults_file, "-Be", "describe db")
results = mysql("mysql", "-Be", "describe db")
column_names = results.split(/\n/).map { |l| l.chomp.split(/\t/)[0] }
@db_privs = column_names.delete_if { |e| !(e =~/_priv$/) }
end
def mysql_flush
mysqladmin defaults_file, "flush-privileges"
mysqladmin "flush-privileges"
end
# this parses the
@ -83,11 +74,11 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
name = split_name(@resource[:name])
case name[:type]
when :user
mysql defaults_file, "-e", "INSERT INTO user (host, user) VALUES ('%s', '%s')" % [
mysql "mysql", "-e", "INSERT INTO user (host, user) VALUES ('%s', '%s')" % [
name[:host], name[:user],
]
when :db
mysql defaults_file, "-e", "INSERT INTO db (host, user, db) VALUES ('%s', '%s', '%s')" % [
mysql "mysql", "-e", "INSERT INTO db (host, user, db) VALUES ('%s', '%s', '%s')" % [
name[:host], name[:user], name[:db],
]
end
@ -96,7 +87,7 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
end
def destroy
mysql defaults_file, "-e", "REVOKE ALL ON '%s'.* FROM '%s@%s'" % [ @resource[:privileges], @resource[:database], @resource[:name], @resource[:host] ]
mysql "mysql", "-e", "REVOKE ALL ON '%s'.* FROM '%s@%s'" % [ @resource[:privileges], @resource[:database], @resource[:name], @resource[:host] ]
end
def row_exists?
@ -105,7 +96,7 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
if name[:type] == :db
fields << :db
end
not mysql( defaults_file, "-NBe", 'SELECT "1" FROM %s WHERE %s' % [ name[:type], fields.map do |f| "%s = '%s'" % [f, name[f]] end.join(' AND ')]).empty?
not mysql( "mysql", "-NBe", 'SELECT "1" FROM %s WHERE %s' % [ name[:type], fields.map do |f| "%s = '%s'" % [f, name[f]] end.join(' AND ')]).empty?
end
def all_privs_set?
@ -127,9 +118,9 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
case name[:type]
when :user
privs = mysql defaults_file, "-Be", 'select * from user where user="%s" and host="%s"' % [ name[:user], name[:host] ]
privs = mysql "mysql", "-Be", 'select * from user where user="%s" and host="%s"' % [ name[:user], name[:host] ]
when :db
privs = mysql defaults_file, "-Be", 'select * from db where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]
privs = mysql "mysql", "-Be", 'select * from db where user="%s" and host="%s" and db="%s"' % [ name[:user], name[:host], name[:db] ]
end
if privs.match(/^$/)
@ -180,7 +171,7 @@ Puppet::Type.type(:database_grant).provide(:mysql) do
# puts "set:", set
stmt = stmt << set << where
mysql defaults_file, "-Be", stmt
mysql "mysql", "-Be", stmt
mysql_flush
end
end

View file

@ -7,45 +7,36 @@ Puppet::Type.type(:database_user).provide(:mysql) do
optional_commands :mysql => 'mysql'
optional_commands :mysqladmin => 'mysqladmin'
def defaults_file
case Facter.value(:operatingsystem)
when "Debian", "Ubuntu"
return "--defaults-file=/etc/mysql/debian.cnf"
else
return ""
end
end
def self.instances
users = mysql(defaults_file, '-BNe' "select concat(User, '@',Host) as User from mysql.user").split("\n")
users = mysql("mysql", '-BNe' "select concat(User, '@',Host) as User from mysql.user").split("\n")
users.select{ |user| user =~ /.+@/ }.collect do |name|
new(:name => name)
end
end
def create
mysql(defaults_file, "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.value(:password_hash) ])
mysql("mysql", "-e", "create user '%s' identified by PASSWORD '%s'" % [ @resource[:name].sub("@", "'@'"), @resource.value(:password_hash) ])
end
def destroy
mysql(defaults_file, "-e", "drop user '%s'" % @resource.value(:name).sub("@", "'@'") )
mysql("mysql", "-e", "drop user '%s'" % @resource.value(:name).sub("@", "'@'") )
end
def password_hash
mysql(defaults_file, "-NBe", "select password from user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).chomp
mysql("mysql", "-NBe", "select password from user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).chomp
end
def password_hash=(string)
mysql(defaults_file, "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ] )
mysql("mysql", "-e", "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub("@", "'@'"), string ] )
end
def exists?
not mysql(defaults_file, "-NBe", "select '1' from user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).empty?
not mysql("mysql", "-NBe", "select '1' from user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)).empty?
end
def flush
@property_hash.clear
mysqladmin(defaults_file, "flush-privileges")
mysqladmin "flush-privileges"
end
end

View file

@ -30,70 +30,22 @@
# }
#
class mysql::config(
$root_password = 'UNSET',
$old_root_password = '',
$bind_address = $mysql::params::bind_address,
$port = $mysql::params::port,
$etc_root_password = $mysql::params::etc_root_password,
$service_name = $mysql::params::service_name,
$config_file = $mysql::params::config_file,
$socket = $mysql::params::socket,
$datadir = $mysql::params::datadir,
$ssl = $mysql::params::ssl,
$ssl_ca = $mysql::params::ssl_ca,
$ssl_cert = $mysql::params::ssl_cert,
$ssl_key = $mysql::params::ssl_key,
$log_error = $mysql::params::log_error,
$slow_query_log_file = $mysql::params::slow_query_log_file,
$long_query_time = $mysql::params::long_query_time,
$character_set_server = $mysql::params::character_set_server,
$collation_server = $mysql::params::collation_server,
$tmp_table_size = $mysql::params::tmp_table_size,
$max_heap_table_size = $mysql::params::max_heap_table_size,
$max_tmp_tables = $mysql::params::max_tmp_tables,
$join_buffer_size = $mysql::params::join_buffer_size,
$read_buffer_size = $mysql::params::read_buffer_size,
$sort_buffer_size = $mysql::params::sort_buffer_size,
$table_cache = $mysql::params::table_cache,
$table_definition_cache = $mysql::params::table_definition_cache,
$open_files_limit = $mysql::params::open_files_limit,
$thread_stack = $mysql::params::thread_stack,
$thread_cache_size = $mysql::params::thread_cache_size,
$thread_concurrency = $mysql::params::thread_concurrency,
$query_cache_size = $mysql::params::query_cache_size,
$query_cache_limit = $mysql::params::query_cache_limit,
$tmp_table_size = $mysql::params::tmp_table_size,
$read_rnd_buffer_size = $mysql::params::read_rnd_buffer_size,
$max_allowed_packet = $mysql::params::max_allowed_packet,
$max_connections = $mysql::params::max_connections,
$wait_timeout = $mysql::params::wait_timeout,
$connect_timeout = $mysql::params::connect_timeout,
$innodb_file_per_table = $mysql::params::innodb_file_per_table,
$innodb_status_file = $mysql::params::innodb_status_file,
$innodb_support_xa = $mysql::params::innodb_support_xa,
$read_only = $mysql::params::read_only,
$replication_enabled = $mysql::params::replication_enabled,
$expire_logs_days = $mysql::params::expire_logs_days,
$max_binlog_size = $mysql::params::max_binlog_size,
$replicate_ignore_table = $mysql::params::replicate_ignore_table,
$replicate_ignore_db = $mysql::params::replicate_ignore_db,
$replicate_do_table = $mysql::params::replicate_do_table,
$replicate_do_db = $mysql::params::replicate_do_db,
$extra_configs = $mysql::params::extra_configs,
$default_engine = 'UNSET',
$root_group = $mysql::params::root_group,
$key_buffer_size = $mysql::params::key_buffer_size,
$myisam_sort_buffer_size = $mysql::params::myisam_sort_buffer_size,
$myisam_max_sort_file_size = $mysql::params::myisam_max_sort_file_size,
$myisam_recover = $mysql::params::myisam_recover,
$innodb_flush_log_at_trx_commit = $mysql::params::innodb_flush_log_at_trx_commit,
$innodb_buffer_pool_size = $mysql::params::innodb_buffer_pool_size,
$innodb_log_file_size = $mysql::params::innodb_log_file_size,
$innodb_flush_method = $mysql::params::innodb_flush_method,
$innodb_thread_concurrency = $mysql::params::innodb_thread_concurrency,
$innodb_concurrency_tickets = $mysql::params::innodb_concurrency_tickets,
$innodb_doublewrite = $mysql::params::innodb_doublewrite,
$root_password = 'UNSET',
$old_root_password = '',
$bind_address = $mysql::params::bind_address,
$port = $mysql::params::port,
$etc_root_password = $mysql::params::etc_root_password,
$service_name = $mysql::params::service_name,
$config_file = $mysql::params::config_file,
$socket = $mysql::params::socket,
$datadir = $mysql::params::datadir,
$ssl = $mysql::params::ssl,
$ssl_ca = $mysql::params::ssl_ca,
$ssl_cert = $mysql::params::ssl_cert,
$ssl_key = $mysql::params::ssl_key,
$log_error = $mysql::params::log_error,
$default_engine = 'UNSET',
$root_group = $mysql::params::root_group
) inherits mysql::params {
File {

View file

@ -12,67 +12,17 @@
#
class mysql::params {
$bind_address = '127.0.0.1'
$port = 3306
$etc_root_password = false
$ssl = false
$slow_query_log_file = false
$long_query_time = 10
$character_set_server = 'utf8'
$collation_server = 'utf8_general_ci'
$ft_min_word_len = 3
$tmp_table_size = '16M'
$max_heap_table_size = '16M'
$max_tmp_tables = '32'
$join_buffer_size = '3M'
$read_buffer_size = '4M'
$sort_buffer_size = '4M'
$table_cache = '64'
$table_definition_cache = '256'
$open_files_limit = '1024'
$thread_stack = '192K'
$thread_cache_size = '8'
$thread_concurrency = '10'
$query_cache_size = '16M'
$query_cache_limit = '1M'
$tmp_table_size = '16M'
$read_rnd_buffer_size = '256K'
$key_buffer_size = '16M'
$myisam_sort_buffer_size = '8M'
$myisam_max_sort_file_size = '512M'
$myisam_recover = 'BACKUP'
$max_allowed_packet = "16M"
$max_connections = '151'
$wait_timeout = "28800"
$connect_timeout = "10"
$innodb_file_per_table = '1'
$innodb_status_file = '0'
$innodb_support_xa = '0'
$innodb_flush_log_at_trx_commit = '0'
$innodb_buffer_pool_size = '8M'
$innodb_log_file_size = '5M'
$innodb_flush_method = 'O_DIRECT'
$innodb_thread_concurrency = '8'
$innodb_concurrency_tickets = '500'
$innodb_doublewrite = '1'
$read_only = false
$replication_enabled = false
$expire_logs_days = '10'
$max_binlog_size = '100M'
$replicate_ignore_table = []
$replicate_ignore_db = []
$replicate_do_table = []
$replicate_do_db = []
$extra_configs = {}
$bind_address = '127.0.0.1'
$port = 3306
$etc_root_password = false
$ssl = false
case $::operatingsystem {
"Ubuntu": {
$service_provider = upstart
$apparmor_file = 'mysql/templates/apparmor.usr.sbin.mysqld.erb'
}
default: {
$service_provider = undef
$apparmor_file = undef
}
}

View file

@ -19,8 +19,6 @@ class mysql::server (
$package_ensure = 'present',
$service_name = $mysql::params::service_name,
$service_provider = $mysql::params::service_provider,
$use_apparmor = false,
$apparmor_file = $mysql::params::apparmor_file,
$config_hash = {},
$enabled = true
) inherits mysql::params {
@ -51,16 +49,4 @@ class mysql::server (
provider => $service_provider,
}
if $use_apparmor {
include apparmor
file { "/etc/apparmor.d/usr.sbin.mysqld":
owner => 'root',
group => 'root',
mode => 0644,
content => template($apparmor_file),
require => Package['mysql-server'],
notify => Class['apparmor'],
}
}
}

View file

@ -1,38 +0,0 @@
# vim:syntax=apparmor
# Last Modified: Tue Jun 19 17:37:30 2007
#include <tunables/global>
/usr/sbin/mysqld {
#include <abstractions/base>
#include <abstractions/nameservice>
#include <abstractions/user-tmp>
#include <abstractions/mysql>
#include <abstractions/winbind>
capability dac_override,
capability sys_resource,
capability setgid,
capability setuid,
network tcp,
/etc/hosts.allow r,
/etc/hosts.deny r,
/etc/mysql/*.pem r,
/etc/mysql/conf.d/ r,
/etc/mysql/conf.d/* r,
<%= config_file %> r,
/usr/sbin/mysqld mr,
/usr/share/mysql/** r,
/var/log/mysql.log rw,
/var/log/mysql.err rw,
<%= datadir %>/ r,
<%= datadir %>/** rwk,
/var/log/mysql/ r,
/var/log/mysql/* rw,
<%= pid %> w,
<%= socket %> w,
/sys/devices/system/cpu/ r,
}

View file

@ -1,177 +1,42 @@
###
#### This file managed by puppet.
###
#
# * IMPORTANT
# If you make changes to these settings and your system uses apparmor, you may
# also need to also adjust /etc/apparmor.d/usr.sbin.mysqld.
#
[mysqld]
basedir = <%= basedir %>
datadir = <%= datadir %>
tmpdir = <%= tmpdir %>
socket = <%= socket %>
pid-file = <%= pid %>
user = mysql
##############
# Networking #
##############
bind_address = <%= bind_address %>
port = <%= port %>
skip_name_resolve
skip_external_locking
max_allowed_packet = <%= max_allowed_packet %>
max_connections = <%= max_connections %>
wait_timeout = <%= wait_timeout %>
connect_timeout = <%= connect_timeout %>
###########
# Logging #
###########
log_error = <%= log_error %>
<% if slow_query_log_file -%>
slow_query_log = 1
slow_query_log_file = <%= slow_query_log_file %>
long_query_time = <%= long_query_time %>
<% end -%>
# Character Set
character_set_server = <%= character_set_server %>
collation_server = <%= collation_server %>
# Fulltext searches to find words smaller than <%= ft_min_word_len %> characters
ft_min_word_len = <%= ft_min_word_len %>
####################################
# Buffers, Threads, Caches, Limits #
####################################
tmp_table_size = <%= tmp_table_size %>
max_heap_table_size = <%= max_heap_table_size %>
max_tmp_tables = <%= max_tmp_tables %>
join_buffer_size = <%= join_buffer_size %>
read_buffer_size = <%= read_buffer_size %>
sort_buffer_size = <%= sort_buffer_size %>
table_cache = <%= table_cache %>
table_definition_cache = <%= table_definition_cache %>
open_files_limit = <%= open_files_limit %>
thread_stack = <%= thread_stack %>
thread_cache_size = <%= thread_cache_size %>
thread_concurrency = <%= thread_concurrency %>
query_cache_size = <%= query_cache_size %>
query_cache_limit = <%= query_cache_limit %>
tmp_table_size = <%= tmp_table_size %>
read_rnd_buffer_size = <%= read_rnd_buffer_size %>
<% if default_engine != 'UNSET' %>
default-storage-engine = <%= default_engine %>
<% end %>
<% if ssl == true %>
ssl-ca = <%= ssl_ca %>
ssl-cert = <%= ssl_cert %>
ssl-key = <%= ssl_key %>
<% end %>
###################
# MyISAM Settings #
###################
key_buffer_size = <%= key_buffer_size %>
myisam_sort_buffer_size = <%= myisam_sort_buffer_size %>
myisam_max_sort_file_size = <%= myisam_max_sort_file_size %>
myisam_recover = <%= myisam_recover %>
###################
# InnoDB Settings #
###################
innodb_file_per_table = <%= innodb_file_per_table %>
innodb_status_file = <%= innodb_status_file %>
innodb_support_xa = <%= innodb_support_xa %>
innodb_flush_log_at_trx_commit = <%= innodb_flush_log_at_trx_commit %>
innodb_buffer_pool_size = <%= innodb_buffer_pool_size %>
innodb_log_file_size = <%= innodb_log_file_size %>
innodb_log_group_home_dir = <%= datadir %>
innodb_flush_method = <%= innodb_flush_method %>
innodb_thread_concurrency = <%= innodb_thread_concurrency %>
innodb_concurrency_tickets = <%= innodb_concurrency_tickets %>
innodb_doublewrite = <%= innodb_doublewrite %>
<% if replication_enabled -%>
########################
# Replication Settings #
########################
log_bin = <%= bindir %>/bin
relay-log = <%= bindir %>/relay-bin
relay-log-index = <%= bindir %>/relay-bin.index
expire_logs_days = <%= expire_logs_days %>
max_binlog_size = <%= max_binlog_size %>
# Log slave updates so that any machine may be a master
log_slave_updates
# report as <%= hostname + '.' + port %> to master
report-host=<%= hostname + '.' + port %>
<% #automatically generate a unique master server-id from IP -%>
<% ia = ipaddress.split('.'); server_id = ia[0] + ia[2] + ia[3]; -%>
server-id = <%= server_id %>
<% replicate_ignore_db.each do |db| -%>
replicate_ignore_db = <%= db %>
<% end -%>
<% replicate_ignore_table.each do |table| -%>
replicate_ignore_table = <%= table %>
<% end -%>
<% replicate_do_db.each do |db| -%>
replicate_do_db = <%= db %>
<% end -%>
<% replicate_do_table.each do |table| -%>
replicate_do_table = <%= table %>
<% end -%>
<% end # if replication_enabled -%>
<% # set read_only mode based on read_only variable -%>
read_only = <%= read_only ? 1 : 0 %>
<% # render out any extra_configs as key = value pairs -%>
<% extra_configs.each do |key, value| -%>
<%= "#{key} = #{value}" %>
<% end -%>
# 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 = <%= port %>
socket = <%= socket %>
port = <%= port %>
socket = <%= socket %>
[mysqld_safe]
socket = <%= socket %>
nice = 0
[mysqld]
user = mysql
socket = <%= socket %>
port = <%= port %>
basedir = <%= basedir %>
datadir = <%= datadir %>
tmpdir = /tmp
skip-external-locking
bind-address = <%= bind_address %>
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
myisam-recover = BACKUP
query_cache_limit = 1M
query_cache_size = 16M
log_error = <%= log_error %>
expire_logs_days = 10
max_binlog_size = 100M
<% if default_engine != 'UNSET' %>
default-storage-engine = <%= default_engine %>
<% end %>
<% if ssl == true %>
ssl-ca = <%= ssl_ca %>
ssl-cert = <%= ssl_cert %>
ssl-key = <%= ssl_key %>
<% end %>
[mysqldump]
quick
quote-names
max_allowed_packet = <%= max_allowed_packet %>
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
[isamchk]
key_buffer = 16M
!includedir /etc/mysql/conf.d/