Skip to content

Commit

Permalink
[COOK-3674] Fix an issue where the root password is not set properly …
Browse files Browse the repository at this point in the history
…with a non-default `data_dir`

Signed-off-by: Seth Vargo <sethvargo@gmail.com>
  • Loading branch information
Justin Witrick authored and sethvargo committed Oct 5, 2013
1 parent 13bb54c commit e412e32
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
7 changes: 7 additions & 0 deletions .kitchen.yml
Expand Up @@ -46,3 +46,10 @@ suites:
- recipe[minitest-handler]
- recipe[mysql_test::server]
attributes: {}
- name: server-nondefault-data
run_list:
- recipe[minitest-handler]
- recipe[mysql_test::server]
attributes:
mysql:
data_dir: "/data/mysql"
40 changes: 33 additions & 7 deletions recipes/server.rb
Expand Up @@ -178,6 +178,14 @@ def package(*args, &blk)
action :run
creates "#{node['mysql']['data_dir']}/mysql"
end

# set the root password for situations that don't support pre-seeding.
# (eg. platforms other than debian/ubuntu & drop-in mysql replacements)
execute "assign-root-password mac_os_x" do
command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
action :run
only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
end
else
execute 'mysql-install-db' do
command "mysql_install_db"
Expand All @@ -195,15 +203,33 @@ def package(*args, &blk)
end
end

# set the root password for situations that don't support pre-seeding.
# (eg. platforms other than debian/ubuntu & drop-in mysql replacements)
execute "assign-root-password" do
command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
action :run
only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
end

unless platform_family?(%w{mac_os_x})

template "#{node['mysql']['conf_dir']}/my.cnf" do
source "my.cnf.erb"
owner "root" unless platform? 'windows'
group node['mysql']['root_group'] unless platform? 'windows'
mode "0644"
case node['mysql']['reload_action']
when 'restart'
notifies :restart, "service[mysql]", :immediately
when 'reload'
notifies :reload, "service[mysql]", :immediately
else
Chef::Log.info "my.cnf updated but mysql.reload_action is #{node['mysql']['reload_action']}. No action taken."
end
variables :skip_federated => skip_federated
end

# set the root password for situations that don't support pre-seeding.
# (eg. platforms other than debian/ubuntu & drop-in mysql replacements)
execute "assign-root-password" do
command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
action :run
only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
end

grants_path = node['mysql']['grants_path']

begin
Expand Down

4 comments on commit e412e32

@claco
Copy link

@claco claco commented on e412e32 Oct 7, 2013

Choose a reason for hiding this comment

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

This, much like my beef with the postgres book; thisnow has the same issue. Wrapper books can't undo an :immediately notification, but they can choose to notify immediately if they need to. So we're stuck in situations where wrapper books are failing because my.conf is dropped, possibly incorrectly in the lib or app book , or user changing attritues and the service will never start. No amount of updating books and running chef-client then can fix that until you log into the server manually.

@willkelly
Copy link

Choose a reason for hiding this comment

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

+1 to claco. :immediately makes me cry and breaks my codes.

@WMeldon
Copy link

Choose a reason for hiding this comment

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

Isn't this redundant anyway? The EXACT same template update occurs under the EXACT same conditional higher up in the code. The only difference the notification is immediately instead of delayed.

@claco
Copy link

@claco claco commented on e412e32 Oct 10, 2013

Choose a reason for hiding this comment

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

@WMeldon Not sure who that's directed at (and for future lurkers) Here's what I mean about the problem with the cookbook changing to :immediately, dropping custom templates in the wrapper book, order of operations, etc: https://tickets.opscode.com/browse/COOK-3427

Please sign in to comment.