diff --git a/Modulefile b/Modulefile index 32c7403..ac7d99c 100644 --- a/Modulefile +++ b/Modulefile @@ -6,3 +6,5 @@ license 'Apache' summary 'Mysql module' description 'Mysql module' project_page 'http://github.com/puppetlabs/puppetlabs-mysql' + +dependency 'puppetlasb/create_resources', '>= 1.2.0' diff --git a/manifests/config.pp b/manifests/config.pp new file mode 100644 index 0000000..2f9df81 --- /dev/null +++ b/manifests/config.pp @@ -0,0 +1,41 @@ +class mysql::config( + $root_password = 'UNSET', + $old_root_password = '', + $bind_address = '127.0.0.1', + $port = 3306 +) { + + # manage root password if it is set + if ! $root_password == 'UNSET' { + $root_password = $config_hash['root_password'] + 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 => on_failure, + logoutput => true, + unless => "mysqladmin -u root -p${root_password} status > /dev/null", + path => '/usr/local/sbin:/usr/bin', + require => [Package['mysql-server'], Service['mysqld']], + before => File['/root/.my.cnf', '/etc/my.cnf'], + notify => Exec['mysqld-restart'], + } + } + File { + owner => 'root', + group => 'root', + notify => Exec['mysqld-restart'], + require => Package['mysql-server'] + } + file{'/root/.my.cnf': + mode => '0400', + content => template('mysql/my.cnf.pass.erb'), + } + + file { '/etc/mysql/my.cnf': + mode => '0400', + content => template('mysql/my.cnf.erb'), + } +} diff --git a/manifests/server.pp b/manifests/server.pp index dacf833..4eb4d4d 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -17,22 +17,16 @@ # class mysql::server( $service_name = $mysql::params::service_name, - $root_password = undef, - $old_root_password = undef, + $config_hash = {}, $package_name = 'mysql-server' ) inherits mysql::params { - case $operatingsystem { - 'centos', 'redhat', 'fedora': { - class { 'mysql::server::redhat': - root_password => $root_password, - old_root_password => $old_root_password, - } - } - 'ubuntu', 'debian': { - # there is not any debian specific config yet - } + # automatically create a class to deal with + # configuration + $hash = { + "mysql::config" => $config_hash } + create_resources("class", $hash) package{'mysql-server': name => $package_name, @@ -57,4 +51,4 @@ class mysql::server( group => 'mysql', require => Package['mysql-server'], } -} \ No newline at end of file +} diff --git a/manifests/server/redhat.pp b/manifests/server/redhat.pp deleted file mode 100644 index 43c6997..0000000 --- a/manifests/server/redhat.pp +++ /dev/null @@ -1,27 +0,0 @@ -class mysql::server::redhat( - $root_password, - $old_root_password = '' -) { - 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 => on_failure, - logoutput => true, - unless => "mysqladmin -u root -p${root_password} status > /dev/null", - path => '/usr/local/sbin:/usr/bin', - require => [Package['mysql-server'], Service['mysqld']], - before => File['/root/.my.cnf', '/etc/my.cnf'], - notify => Exec['mysqld-restart'], - } - file{['/root/.my.cnf', '/etc/my.cnf']: - owner => 'root', - group => 'root', - mode => '0400', - content => template('mysql/my.cnf.erb'), - notify => Exec['mysqld-restart'], - require => Package['mysql-server'], - } -} diff --git a/templates/my.cnf.erb b/templates/my.cnf.erb index ef5b62b..816cacb 100644 --- a/templates/my.cnf.erb +++ b/templates/my.cnf.erb @@ -1,4 +1,33 @@ [client] -user=root -host=localhost -password=<%= root_password -%> +port = <%= port %> +socket = /var/run/mysqld/mysqld.sock +[mysqld_safe] +socket = /var/run/mysqld/mysqld.sock +nice = 0 +[mysqld] +user = mysql +socket = /var/run/mysqld/mysqld.sock +port = <%= port %> +basedir = /usr +datadir = /var/lib/mysql +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 = /var/log/mysql/error.log +expire_logs_days = 10 +max_binlog_size = 100M +[mysqldump] +quick +quote-names +max_allowed_packet = 16M +[mysql] +[isamchk] +key_buffer = 16M +!includedir /etc/mysql/conf.d/ diff --git a/templates/my.cnf.pass.erb b/templates/my.cnf.pass.erb new file mode 100644 index 0000000..38a3a4a --- /dev/null +++ b/templates/my.cnf.pass.erb @@ -0,0 +1,6 @@ +[client] +user=root +host=localhost +<% unless root_password == 'UNSET' -%> +password=<%= root_password %> +<% end -%>