Skip to content

Commit e412e32

Browse files
Justin Witricksethvargo
authored andcommitted
[COOK-3674] Fix an issue where the root password is not set properly with a non-default data_dir
Signed-off-by: Seth Vargo <[email protected]>
1 parent 13bb54c commit e412e32

File tree

2 files changed

+40
-7
lines changed

2 files changed

+40
-7
lines changed

.kitchen.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,10 @@ suites:
4646
- recipe[minitest-handler]
4747
- recipe[mysql_test::server]
4848
attributes: {}
49+
- name: server-nondefault-data
50+
run_list:
51+
- recipe[minitest-handler]
52+
- recipe[mysql_test::server]
53+
attributes:
54+
mysql:
55+
data_dir: "/data/mysql"

recipes/server.rb

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,14 @@ def package(*args, &blk)
178178
action :run
179179
creates "#{node['mysql']['data_dir']}/mysql"
180180
end
181+
182+
# set the root password for situations that don't support pre-seeding.
183+
# (eg. platforms other than debian/ubuntu & drop-in mysql replacements)
184+
execute "assign-root-password mac_os_x" do
185+
command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
186+
action :run
187+
only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
188+
end
181189
else
182190
execute 'mysql-install-db' do
183191
command "mysql_install_db"
@@ -195,15 +203,33 @@ def package(*args, &blk)
195203
end
196204
end
197205

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

206207
unless platform_family?(%w{mac_os_x})
208+
209+
template "#{node['mysql']['conf_dir']}/my.cnf" do
210+
source "my.cnf.erb"
211+
owner "root" unless platform? 'windows'
212+
group node['mysql']['root_group'] unless platform? 'windows'
213+
mode "0644"
214+
case node['mysql']['reload_action']
215+
when 'restart'
216+
notifies :restart, "service[mysql]", :immediately
217+
when 'reload'
218+
notifies :reload, "service[mysql]", :immediately
219+
else
220+
Chef::Log.info "my.cnf updated but mysql.reload_action is #{node['mysql']['reload_action']}. No action taken."
221+
end
222+
variables :skip_federated => skip_federated
223+
end
224+
225+
# set the root password for situations that don't support pre-seeding.
226+
# (eg. platforms other than debian/ubuntu & drop-in mysql replacements)
227+
execute "assign-root-password" do
228+
command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
229+
action :run
230+
only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
231+
end
232+
207233
grants_path = node['mysql']['grants_path']
208234

209235
begin

0 commit comments

Comments
 (0)