Merge remote branch 'remotes/immerda/master'
Conflicts: manifests/server/base.pp
This commit is contained in:
commit
a3e7b031a3
14 changed files with 384 additions and 332 deletions
|
@ -5,8 +5,8 @@ ENV['HOME'] = '/root'
|
|||
tables = %x{mysql -Bse "SELECT TABLE_SCHEMA,TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0 AND ENGINE IN ('MyISAM','InnoDB','ARCHIVE')"}
|
||||
tables.each { |table|
|
||||
tableitems = table.chomp.split(/\t/)
|
||||
system "mysql #{tableitems[0]} -Bse \"OPTIMIZE TABLE #{tableitems[1]}\" | grep -q OK"
|
||||
system "mysql #{tableitems[0]} -Bse \"OPTIMIZE TABLE \\`#{tableitems[0]}\\`.\\`#{tableitems[1]}\\`\" | grep -q OK"
|
||||
if $?.to_i > 0 then
|
||||
puts "error while optimizing #{tableitems[0]}. #{tableitems[1]}"
|
||||
puts "error while optimizing #{tableitems[0]}.#{tableitems[1]}"
|
||||
end
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
Facter.add("mysql_exists") do
|
||||
ENV["PATH"]="/bin:/sbin:/usr/bin:/usr/sbin"
|
||||
|
||||
setcode do
|
||||
mysqlexists = system "which mysql > /dev/null 2>&1"
|
||||
($?.exitstatus == 0)
|
||||
File.exist? '/usr/bin/mysql'
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# This has to be a separate type to enable collecting
|
||||
Puppet::Type.newtype(:mysql_database) do
|
||||
@doc = "Manage a database."
|
||||
|
||||
ensurable
|
||||
autorequire(:service) { 'mysql' }
|
||||
|
||||
newparam(:name) do
|
||||
desc "The name of the database."
|
||||
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
# This has to be a separate type to enable collecting
|
||||
Puppet::Type.newtype(:mysql_grant) do
|
||||
@doc = "Manage a database user's rights."
|
||||
|
||||
#ensurable
|
||||
autorequire(:service) { 'mysqld' }
|
||||
|
||||
autorequire :mysql_db do
|
||||
# puts "Starting db autoreq for %s" % self[:name]
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
# This has to be a separate type to enable collecting
|
||||
Puppet::Type.newtype(:mysql_user) do
|
||||
@doc = "Manage a database user."
|
||||
|
||||
ensurable
|
||||
autorequire(:service) { 'mysqld' }
|
||||
|
||||
newparam(:name) do
|
||||
desc "The name of the user. This uses the 'username@hostname' form."
|
||||
|
||||
|
|
45
manifests/default_database.pp
Normal file
45
manifests/default_database.pp
Normal file
|
@ -0,0 +1,45 @@
|
|||
# create default database
|
||||
# generate hashed password with:
|
||||
# ruby -r'digest/sha1' -e 'puts "*" + Digest::SHA1.hexdigest(Digest::SHA1.digest(ARGV[0])).upcase' PASSWORD
|
||||
define mysql::default_database(
|
||||
$username = 'absent',
|
||||
$password,
|
||||
$password_is_encrypted = true,
|
||||
$privileges = 'all',
|
||||
$host = '127.0.0.1',
|
||||
$ensure = 'present'
|
||||
) {
|
||||
$real_username = $username ? {
|
||||
'absent' => $name,
|
||||
default => $username
|
||||
}
|
||||
mysql_database{"$name":
|
||||
ensure => $ensure
|
||||
}
|
||||
case $password {
|
||||
'absent': {
|
||||
info("we don't create the user for database: ${name}")
|
||||
$grant_require = Mysql_database["$name"]
|
||||
}
|
||||
default: {
|
||||
mysql_user{"${real_username}@${host}":
|
||||
password_hash => $password_is_encrypted ? {
|
||||
true => "$password",
|
||||
default => mysql_password("$password")
|
||||
},
|
||||
ensure => $ensure,
|
||||
require => [
|
||||
Mysql_database["$name"]
|
||||
],
|
||||
}
|
||||
$grant_require = [
|
||||
Mysql_database["$name"],
|
||||
Mysql_user["${real_username}@${host}"]
|
||||
]
|
||||
}
|
||||
}
|
||||
mysql_grant{"${real_username}@${host}/${name}":
|
||||
privileges => "$privileges",
|
||||
require => $grant_require,
|
||||
}
|
||||
}
|
|
@ -1,9 +1,5 @@
|
|||
class mysql::server {
|
||||
|
||||
include common::moduledir
|
||||
$mysql_moduledir = "${common::moduledir::module_dir_path}/mysql"
|
||||
module_dir { ['mysql', 'mysql/server']: }
|
||||
|
||||
case $operatingsystem {
|
||||
gentoo: { include mysql::server::gentoo }
|
||||
centos: { include mysql::server::centos }
|
||||
|
@ -19,7 +15,10 @@ class mysql::server {
|
|||
}
|
||||
|
||||
if $use_nagios {
|
||||
include mysql::server::nagios
|
||||
case $nagios_check_mysql {
|
||||
false: { info("We don't do nagioschecks for mysql on ${fqdn}" ) }
|
||||
default: { include mysql::server::nagios }
|
||||
}
|
||||
}
|
||||
|
||||
if $use_shorewall {
|
||||
|
|
|
@ -5,13 +5,13 @@ class mysql::server::base {
|
|||
file { 'mysql_main_cnf':
|
||||
path => '/etc/mysql/my.cnf',
|
||||
source => [
|
||||
"puppet://$server/modules/site-mysql/${fqdn}/my.cnf",
|
||||
"puppet://$server/modules/site-mysql/my.cnf.${operatingsystem}.{lsbdistcodename}",
|
||||
"puppet://$server/modules/site-mysql/my.cnf.${operatingsystem}",
|
||||
"puppet://$server/modules/site-mysql/my.cnf",
|
||||
"puppet://$server/modules/mysql/config/my.cnf.${operatingsystem}.{lsbdistcodename}",
|
||||
"puppet://$server/modules/mysql/config/my.cnf.${operatingsystem}",
|
||||
"puppet://$server/modules/mysql/config/my.cnf"
|
||||
"puppet://modules/site-mysql/${fqdn}/my.cnf",
|
||||
"puppet://modules/site-mysql/my.cnf.${operatingsystem}.{lsbdistcodename}",
|
||||
"puppet://modules/site-mysql/my.cnf.${operatingsystem}",
|
||||
"puppet://modules/site-mysql/my.cnf",
|
||||
"puppet://modules/mysql/config/my.cnf.${operatingsystem}.{lsbdistcodename}",
|
||||
"puppet://modules/mysql/config/my.cnf.${operatingsystem}",
|
||||
"puppet://modules/mysql/config/my.cnf"
|
||||
],
|
||||
ensure => file,
|
||||
require => Package['mysql-server'],
|
||||
|
@ -40,8 +40,8 @@ class mysql::server::base {
|
|||
}
|
||||
|
||||
file { 'mysql_setmysqlpass.sh':
|
||||
path => "${mysql_moduledir}/server/setmysqlpass.sh",
|
||||
source => "puppet://${server}/modules/mysql/scripts/${operatingsystem}/setmysqlpass.sh",
|
||||
path => '/usr/local/sbin/setmysqlpass.sh',
|
||||
source => "puppet:///modules/mysql/scripts/${operatingsystem}/setmysqlpass.sh",
|
||||
require => Package['mysql-server'],
|
||||
owner => root, group => 0, mode => 0500;
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ class mysql::server::base {
|
|||
}
|
||||
|
||||
exec { 'mysql_set_rootpw':
|
||||
command => "${mysql_moduledir}/server/setmysqlpass.sh ${mysql_rootpw}",
|
||||
command => "/user/local/sbin/setmysqlpass.sh ${mysql_rootpw}",
|
||||
unless => "mysqladmin -uroot status > /dev/null",
|
||||
require => [ File['mysql_setmysqlpass.sh'], Package['mysql-server'] ],
|
||||
refreshonly => true,
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
class mysql::server::cron {
|
||||
}
|
|
@ -5,18 +5,23 @@ class mysql::server::cron::backup {
|
|||
default => $mysql_backup_dir,
|
||||
}
|
||||
|
||||
case $mysql_manage_backup_dir {
|
||||
false: { info("We don't manage \$mysql_backup_dir ($mysql_backup_dir)") }
|
||||
default: {
|
||||
file { 'mysql_backup_dir':
|
||||
path => $real_mysql_backup_dir,
|
||||
source => "puppet://${server}/modules/common/empty",
|
||||
ensure => directory,
|
||||
owner => root, group => 0, mode => 0700,
|
||||
before => Cron['mysql_backup_cron'],
|
||||
owner => root, group => 0, mode => 0700;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cron { 'mysql_backup_cron':
|
||||
command => '/usr/bin/mysqldump --default-character-set=utf8 --all-databases --all --flush-logs --lock-tables --single-transaction | gzip > ${real_mysql_backup_dir}/mysqldump.sql.gz && chmod 600 ${real_mysql_backup_dir}/mysqldump.sql.gz',
|
||||
command => "/usr/bin/mysqldump --default-character-set=utf8 --all-databases --all --flush-logs --lock-tables --single-transaction | gzip > ${real_mysql_backup_dir}/mysqldump.sql.gz && chmod 600 ${real_mysql_backup_dir}/mysqldump.sql.gz",
|
||||
user => 'root',
|
||||
minute => 0,
|
||||
hour => 1,
|
||||
require => [ Exec['mysql_set_rootpw'], File['mysql_root_cnf'], File['mysql_backup_dir'] ],
|
||||
require => [ Exec['mysql_set_rootpw'], File['mysql_root_cnf'] ],
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
class mysql::server::cron::optimize {
|
||||
|
||||
file { 'mysql_optimize_script':
|
||||
path => "${mysql_moduledir}/server/optimize_tables.rb",
|
||||
source => "puppet://${server}/modules/mysql/scripts/optimize_tables.rb",
|
||||
path => '/usr/local/sbin/optimize_mysql_tables.rb',
|
||||
source => "puppet:///modules/mysql/scripts/optimize_tables.rb",
|
||||
owner => root, group => 0, mode => 0700;
|
||||
}
|
||||
|
||||
cron { 'mysql_optimize_cron':
|
||||
command => "${mysql_moduledir}/server/optimize_tables.rb",
|
||||
command => '/usr/local/sbin/optimize_mysql_tables.rb',
|
||||
user => 'root',
|
||||
minute => 40,
|
||||
hour => 6,
|
||||
|
|
Loading…
Reference in a new issue