Skip to content
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

Add support for Percona and fixes for the DB initialization #1

Open
wants to merge 6 commits into
base: puppetlabs_3.7.0
Choose a base branch
from
Open
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
13 changes: 7 additions & 6 deletions lib/puppet/provider/mysql_datadir/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def create
user = @resource.value(:user) || "mysql"
basedir = @resource.value(:basedir) || "/usr"
datadir = @resource.value(:datadir) || @resource[:name]
log_error = @resource.value(:log_error) || "/var/tmp/mysqld_initialize.log"

unless defaults_extra_file.nil?
if File.exist?(defaults_extra_file)
Expand All @@ -34,15 +35,15 @@ def create
end

if mysqld_version.nil?
debug("Installing MySQL data directory with mysql_install_db --basedir=#{basedir} #{defaults_extra_file} --datadir=#{datadir} --user=#{user}")
mysql_install_db(["--basedir=#{basedir}",defaults_extra_file, "--datadir=#{datadir}", "--user=#{user}"].compact)
debug("Installing MySQL data directory with mysql_install_db #{defaults_extra_file} --basedir=#{basedir} --datadir=#{datadir} --user=#{user}")
mysql_install_db([defaults_extra_file, "--basedir=#{basedir}", "--datadir=#{datadir}", "--user=#{user}"].compact)
else
if mysqld_type == "mysql" and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0
if (mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. We change this in 3 separate places in 2 files so I'm thinking we should really define a predicate function with this condition in it, otherwise I worry that other people will continue to ignore percona when making changes. Going to look around and see where might be a good idea to define that function.

debug("Initializing MySQL data directory >= 5.7.6 with 'mysqld #{defaults_extra_file} #{initialize} --basedir=#{basedir} --datadir=#{datadir} --user=#{user}'")
mysqld([defaults_extra_file,initialize,"--basedir=#{basedir}","--datadir=#{datadir}", "--user=#{user}", "--log_error=/var/tmp/mysqld_initialize.log"].compact)
mysqld([defaults_extra_file, initialize, "--basedir=#{basedir}", "--datadir=#{datadir}", "--user=#{user}", "--log-error=#{log_error}"].compact)
else
debug("Installing MySQL data directory with mysql_install_db --basedir=#{basedir} #{defaults_extra_file} --datadir=#{datadir} --user=#{user}")
mysql_install_db(["--basedir=#{basedir}",defaults_extra_file, "--datadir=#{datadir}", "--user=#{user}"].compact)
debug("Installing MySQL data directory with mysql_install_db #{defaults_extra_file} --basedir=#{basedir} --datadir=#{datadir} --user=#{user}")
mysql_install_db([defaults_extra_file, "--basedir=#{basedir}", "--datadir=#{datadir}", "--user=#{user}"].compact)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is default_extra_file?

end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/puppet/provider/mysql_user/mysql.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.instances
## Default ...
query = "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{name}'"
else
if mysqld_type == "mysql" and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0
if (mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0
query = "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, AUTHENTICATION_STRING, PLUGIN FROM mysql.user WHERE CONCAT(user, '@', host) = '#{name}'"
else
query = "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, PASSWORD /*!50508 , PLUGIN */ FROM mysql.user WHERE CONCAT(user, '@', host) = '#{name}'"
Expand Down Expand Up @@ -109,7 +109,7 @@ def password_hash=(string)
mysql([defaults_file, '-e', "SET PASSWORD FOR #{merged_name} = '#{string}'"].compact)
else
# Version >= 5.7.6 (many password related changes)
if mysqld_type == "mysql" and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0
if (mysqld_type == "mysql" or mysqld_type == "percona") and Puppet::Util::Package.versioncmp(mysqld_version, '5.7.6') >= 0
if string.match(/^\*/)
mysql([defaults_file, '-e', "ALTER USER #{merged_name} IDENTIFIED WITH mysql_native_password AS '#{string}'"].compact)
else
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/mysql_datadir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@
desc "Insecure initialization (needed for 5.7.6++)."
end

newparam(:log_error) do
desc "The path to the mysqld error log file (used with the --log-error option)"
newvalues(/^\//)
end

end
2 changes: 2 additions & 0 deletions manifests/server/installdb.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
$datadir = $mysql::server::options['mysqld']['datadir']
$basedir = $mysql::server::options['mysqld']['basedir']
$config_file = $mysql::server::config_file
$log_error = $mysql::server::options['mysqld']['log-error']

if $mysql::server::manage_config_file {
$_config_file=$config_file
Expand All @@ -20,6 +21,7 @@
datadir => $datadir,
basedir => $basedir,
user => $mysqluser,
log_error => $log_error,
defaults_extra_file => $_config_file,
}

Expand Down