Skip to content

Handle changing the datadir properly. #536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions manifests/server/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,24 @@
name => $mysql::server::package_name,
}

# Build the initial databases.
if $mysql::server::override_options['mysqld'] and $mysql::server::override_options['mysqld']['datadir'] {
$mysqluser = $mysql::server::options['mysqld']['user']
$datadir = $mysql::server::override_options['mysqld']['datadir']

exec { 'mysql_install_db':
command => "mysql_install_db --datadir=${datadir} --user=${mysqluser}",
creates => "${datadir}/mysql",
logoutput => on_failure,
path => '/bin:/sbin:/usr/bin:/usr/sbin',
require => Package['mysql-server'],
}

if $mysql::server::restart {
Exec['mysql_install_db'] {
notify => Class['mysql::service'],
}
}
}

}
16 changes: 16 additions & 0 deletions spec/acceptance/mysql_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -285,4 +285,20 @@ class { 'mysql::server':
end
end

describe 'creates the appropriate databases when datadir is set' do
tmpdir = default.tmpdir('mysql')
it 'sets up mysql' do
pp = <<-EOS
class { 'mysql::server':
override_options => { 'mysqld' => { 'datadir' => '#{tmpdir}/mysql' }},
}
EOS
shell("mkdir -p #{tmpdir}; chown -R mysql:mysql #{tmpdir}")
apply_manifest(pp, :catch_failures => true)
end

describe file("#{tmpdir}/mysql/mysql") do
it { should be_directory }
end
end
end
1 change: 1 addition & 0 deletions spec/acceptance/nodesets/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ HOSTS:
centos-64-x64:
roles:
- master
- default
platform: el-6-x86_64
box : centos-64-x64-vbox4210-nocm
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
Expand Down