-
Notifications
You must be signed in to change notification settings - Fork 794
run mysql_install_db if datadir is set annd mysql database is missing #405
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
Conversation
@@ -6,4 +6,17 @@ | |||
name => $mysql::server::package_name, | |||
} | |||
|
|||
# run mysql_install_db if datadir is set and datadir doesn't contain the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the comment here says the same thing as the code, one of the two is unnecessary ;)
Perhaps you should instead comment on the "why"
I can change the comment if it is that obvious what the code is doing. But for me it was more obvious, that the mysql server without the mysql database won't start ;-) |
So a proper comment may be:
(: |
I would rather change it to:
because "mysql server won't start without this" is in most cases (datadir isn't changed) false. |
anyway, ignoring my pedantry with regard to comments, is there a way to add tests for this change? |
I appreciate any feedback, even if I disagree, because normally it improves the code and my understanding of it. I also thought about a test for this change. But I couldn't come up with a good test. This could be because I'm not very familiar with the puppet test environment. Partly because they won't run on my main computer, because of ruby version issues. The only test I came up with was something like:
I can add this test, but I'm not sure if /tmp is the correct directory to use or if this test is really useful and will work at all. So feedback would be appreciated. |
@apenney what'd you think? |
In terms of tests I would do something like: 1: run apply_manifest("class { 'mysql::server': datadir => '/tmp/test' }", :catch_failures => true) to get a baseline. Those checks combined should be enough to ensure it's able to create properly. Failing that you can just run it for the first time with /tmp/test and then immediately check the /tmp/test/mysql* files exist. Make sense? |
If I'm not mistaken, then this kind of test must be an acceptance tests. I have found no way to run them, because 'rake spec' doesn't seem to work. I found some help how to run them with vagrant, but that seems overly complicated, just to check if the test is working as intended. Is there some documentation how to run the acceptance tests, possibly without having to setup vagrant or other vm solutions? |
Unfortunately, in order to actually test this there's no choice but actually run it. |
@vicinus I had the same issue ages ago. Just install https://rvm.io/ and update the "local" copy of ruby to 1.9.3 or something. |
Hello, I've been working on installing MariaDB to an alternate location using this mysql module (version 2.1), and I came across your commit to install.pp, which resolved the biggest hurdle I was facing. However, I had to add two lines to your exec statement to make it work:
We are still using Puppet 2.7, and this was applied to a CentOS 6.4 box. If you're still working on making this module install to an alternate datadir, I had to create an additional "wrapper" class to take care of additional pre-install setup, and I'd be happy to share what I've done. But thank you for contributing this code, it saved me a lot of work. |
@vicinus would you like to incorporate @bradleyfrank and @apenney's comments, or do you want someone to take over? |
@vicinus any progress here? |
It is very annoing that $datadir option is just ignored and database is install into default /var/lib/mysql directory.... |
DeathBorn, it's the exact problem I was running into. I need to install to /srv/database but the mysql module installs to /var/lib/mysql first. The change I added above re-installs the default DB into the new datadir, but the original stays intact, and "remove_default_accounts" doesn't clean it up. My solution/work-around is to make /var/lib/mysql a symlink of /srv/database so everything goes to the right place initially. I ended up not needed vicinus' changes at all. If it helps, here's what I wrote, note that I'm using MariaDB, but you can easily substitute MySQL back in: http://pastebin.com/srjdwtcf |
@bradleyfrank there's nothing wrong adding the code here, do you mind if I copy the pastebin in the comment? class hmdc_mariadb::datadir inherits hmdc_mariadb {
Exec {
path => $exec_path,
}
exec { 'fcontext-mariadb':
command => "semanage fcontext -a -t ${mariadb_context} \"${semanage_path}\"",
unless => "semanage fcontext -l | grep \"^${semanage_path}.*:${mariadb_context}:\"",
}
exec { 'restorecon-mariadb':
command => "restorecon -R ${datadir}",
unless => "matchpathcon -V ${datadir} | grep verified",
}
file { $datadir:
ensure => 'directory',
group => 'mysql',
mode => '0755',
owner => 'mysql',
}
file { "${datadir}/lost+found":
ensure => 'absent',
force => true,
}
file { '/var/lib/mysql':
ensure => link,
target => $datadir,
}
# From the MariaDB-server RPM package:
# /usr/sbin/groupadd -g 27 -o -r mysql
group { 'mysql':
ensure => 'present',
allowdupe => true, # -o
gid => '27', # -g 27
system => true, # -r
}
# From the MariaDB-server RPM package:
# /usr/sbin/useradd -M -N -g mysql -o -r -d $datadir -s /bin/bash
# -c "MySQL Server" -u 27 mysql
user { 'mysql':
ensure => 'present',
allowdupe => true, # -o
comment => 'MariaDB Server', # -c "MySQL Server"
home => $datadir, # -d $datadir
gid => 'mysql', # -g mysql
managehome => false, # -M
require => Group['mysql'], #
shell => '/bin/bash', # -s /bin/bash
system => true, # -r
uid => '27', # -u 27
}
User['mysql'] ->
File[$datadir] ->
File['/var/lib/mysql'] ->
Exec['fcontext-mariadb'] ->
Exec['restorecon-mariadb']
class hmdc_mariadb (
$datadir = $hmdc_mariadb::params::datadir,
) inherits hmdc_mariadb::params {
require 'mariadb_repo'
include hmdc_mariadb::datadir
package { 'MariaDB-shared':
ensure => 'present',
}
class { '::mysql::server':
databases => $databases,
override_options => $override_options,
grants => $grants,
package_name => 'MariaDB-server',
remove_default_accounts => true,
restart => true,
service_enabled => true,
service_name => 'mysql',
users => $users,
}
class { '::mysql::client':
package_ensure => 'present',
package_name => 'MariaDB-client'
}
Class['hmdc_mariadb::datadir'] ->
Package['MariaDB-shared'] ->
Class['::mysql::client'] ->
Class['::mysql::server'] |
Sure, no problem! It was just lengthy and I wasn't sure what the etiquette was. Hopefully it can help someone else with the same problem! |
I thought about using symlink or just mounting a directory and chose the second option.Thank you, bradleyfrank, for providing configuration. |
Any progress here? |
@vicinus Any chance of a rebase here? |
Fixed in #536 |
If the datadir is changed in the my.cnf, then mysql_install_db must be run to create the basic mysql database etc. in the new datadir. This change checks if datadir is set and if the directory mysql is missing in the datadir, if so mysql_install_db is run.