Skip to content

Commit ce16693

Browse files
Julian C. DunnSean OMeara
authored andcommitted
[COOK-4068] - Fix up Windows recipe
Signed-off-by: Sean OMeara <[email protected]>
1 parent ed0aecb commit ce16693

File tree

3 files changed

+40
-97
lines changed

3 files changed

+40
-97
lines changed

attributes/server_windows.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
case node['platform_family']
22
when 'windows'
3-
default['mysql']['windows']['package_file'] = "mysql-#{mysql['version']}-#{mysql['arch']}.msi"
3+
default['mysql']['windows']['version'] = '5.5.34'
4+
default['mysql']['windows']['arch'] = node['kernel']['machine'] == 'x86_64' ? 'winx64' : 'win32'
5+
default['mysql']['windows']['package_file'] = "mysql-#{node['mysql']['windows']['version']}-#{node['mysql']['windows']['arch']}.msi"
46
default['mysql']['windows']['packages'] = ['MySQL Server 5.5']
5-
default['mysql']['windows']['url'] = "http://www.mysql.com/get/Downloads/MySQL-5.5/#{mysql['package_file']}/from/http://mysql.mirrors.pair.com/"
6-
default['mysql']['windows']['version'] = '5.5.32'
7-
# default['mysql']['windows']['arch'] = 'win32'
7+
default['mysql']['windows']['url'] = "http://dev.mysql.com/get/Downloads/MySQL-5.5/#{node['mysql']['windows']['package_file']}"
88

9-
default['mysql']['windows']['basedir'] = "#{ENV['SYSTEMDRIVE']}\\Program Files (x86)\\MySQL\\#{mysql['server']['packages'].first}"
10-
default['mysql']['windows']['data_dir'] = "#{node['mysql']['windows']['basedir']}\\Data"
9+
default['mysql']['windows']['programdir'] = node['kernel']['machine'] == 'x86_64' ? 'Program Files' : 'Program Files (x86)'
10+
default['mysql']['windows']['basedir'] = "#{ENV['SYSTEMDRIVE']}\\#{node['mysql']['windows']['programdir']}\\MySQL\\#{node['mysql']['windows']['packages'].first}"
11+
default['mysql']['windows']['data_dir'] = "#{ENV['ProgramData']}\\MySQL\\#{node['mysql']['windows']['packages'].first}\\Data"
1112
default['mysql']['windows']['bin_dir'] = "#{node['mysql']['windows']['basedir']}\\bin"
1213
default['mysql']['windows']['mysqladmin_bin'] = "#{node['mysql']['windows']['bin_dir']}\\mysqladmin"
1314
default['mysql']['windows']['mysql_bin'] = "#{node['mysql']['windows']['bin_dir']}\\mysql"
1415

1516
default['mysql']['windows']['conf_dir'] = node['mysql']['windows']['basedir']
1617
default['mysql']['windows']['old_passwords'] = 0
17-
default['mysql']['windows']['grants_path'] = "#{node['mysql']['conf_dir']}\\grants.sql"
18+
default['mysql']['windows']['grants_path'] = "#{node['mysql']['windows']['conf_dir']}\\grants.sql"
1819

1920
default['mysql']['server']['service_name'] = 'mysql'
21+
default['mysql']['server']['slow_query_log'] = 1
2022
end

recipes/_server_windows.rb

Lines changed: 27 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
11
require 'win32/service'
2-
require 'win32/service'
32

43
ENV['PATH'] += ";#{node['mysql']['windows']['bin_dir']}"
5-
package_file = Chef::Config[:file_cache_path] + node['mysql']['windows']['package_file']
4+
package_file = Chef::Config[:file_cache_path] + File::ALT_SEPARATOR + node['mysql']['windows']['package_file']
65
install_dir = win_friendly_path(node['mysql']['windows']['basedir'])
76

8-
def package(*args, &blk)
9-
windows_package(*args, &blk)
10-
end
11-
12-
#----
137
windows_path node['mysql']['windows']['bin_dir'] do
148
action :add
159
end
@@ -25,99 +19,46 @@ def package(*args, &blk)
2519
notifies :run, 'execute[install mysql service]', :immediately
2620
end
2721

28-
#--- FIX ME - directories
29-
30-
#----
31-
execute 'install mysql service' do
32-
command %Q["#{node['mysql']['windows']['bin_dir']}\\mysqld.exe" --install "#{node['mysql']['server']['service_name']}"]
33-
not_if { ::Win32::Service.exists?(node['mysql']['windows']['service_name']) }
34-
end
35-
36-
#----
37-
template 'initial-my.cnf' do
38-
path "#{node['mysql']['windows']['conf_dir']}/my.cnf"
39-
source 'my.cnf.erb'
40-
mode '0644'
41-
notifies :reload, node['mysql']['windows']['service_name'], :delayed
42-
end
43-
44-
#----
45-
46-
windows_path node['mysql']['bin_dir'] do
47-
action :add
48-
end
49-
50-
windows_batch 'install mysql service' do
51-
command "\"#{node['mysql']['bin_dir']}\\mysqld.exe\" --install #{node['mysql']['service_name']}"
52-
not_if { Win32::Service.exists?(node['mysql']['service_name']) }
53-
end
54-
55-
#----
56-
57-
src_dir = win_friendly_path("#{node['mysql']['basedir']}\\data")
58-
target_dir = win_friendly_path(node['mysql']['data_dir'])
59-
60-
%w{mysql performance_schema}.each do |db|
61-
execute 'mysql-move-db' do
62-
command %Q[move "#{src_dir}\\#{db}" "#{target_dir}"]
63-
action :run
64-
not_if { File.exists?(node['mysql']['data_dir'] + '/mysql/user.frm') }
65-
end
22+
template 'my.ini' do
23+
path "#{node['mysql']['windows']['bin_dir']}\\my.ini"
24+
source 'my.ini.erb'
25+
notifies :restart, "service[mysql]"
6626
end
6727

68-
#----
69-
70-
execute 'mysql-install-db' do
71-
command 'mysql_install_db'
72-
action :run
73-
not_if { File.exists?(node['mysql']['data_dir'] + '/mysql/user.frm') }
28+
execute 'install mysql service' do
29+
command %Q["#{node['mysql']['windows']['bin_dir']}\\mysqld.exe" --install "#{node['mysql']['server']['service_name']}" --defaults-file="#{node['mysql']['windows']['bin_dir']}\\my.ini"]
30+
not_if { ::Win32::Service.exists?(node['mysql']['server']['service_name']) }
7431
end
7532

7633
service 'mysql' do
77-
service_name node['mysql']['service_name']
78-
provider Chef::Provider::Service::Upstart if node['mysql']['use_upstart']
79-
supports :status => true, :restart => true, :reload => true
80-
action :enable
81-
end
82-
83-
template 'final-my.cnf' do
84-
path "#{node['mysql']['conf_dir']}/my.cnf"
85-
source 'my.cnf.erb'
86-
mode '0644'
87-
notifies :restart, 'service[mysql]', :immediately
34+
service_name node['mysql']['server']['service_name']
35+
action [:enable, :start]
8836
end
8937

90-
#----
91-
9238
execute 'assign-root-password' do
93-
command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
39+
command %Q["#{node['mysql']['windows']['mysqladmin_bin']}" -u root password #{node['mysql']['server_root_password']}]
9440
action :run
95-
only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
41+
# only_if %Q["#{node['mysql']['windows']['mysql_bin']}" -u root -e 'show databases;'] # unreliable due to CHEF-4783; always returns 0 when run in Chef
42+
not_if { node['mysql']['root_password_set'] }
43+
notifies :run, "ruby_block[root-password-set]", :immediately
9644
end
9745

98-
#----
99-
100-
grants_path = node['mysql']['grants_path']
101-
102-
begin
103-
resources("template[#{grants_path}]")
104-
rescue
105-
Chef::Log.info('Could not find previously defined grants.sql resource')
106-
template grants_path do
107-
source 'grants.sql.erb'
108-
mode '0600'
109-
action :create
46+
ruby_block 'root-password-set' do
47+
block do
48+
node.set['mysql']['root_password_set'] = true
11049
end
50+
action :nothing
11151
end
11252

113-
#----
114-
windows_batch 'mysql-install-privileges' do
115-
command "\"#{node['mysql']['mysql_bin']}\" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < \"#{grants_path}\""
116-
action :nothing
117-
subscribes :run, resources("template[#{grants_path}]"), :immediately
53+
grants_path = node['mysql']['windows']['grants_path']
54+
55+
template grants_path do
56+
source 'grants.sql.erb'
57+
action :create
58+
notifies :run, "execute[mysql-install-privileges]", :immediately
11859
end
11960

120-
service 'mysql-start' do
121-
service_name node['mysql']['server']['service_name']
122-
action :start
61+
execute 'mysql-install-privileges' do
62+
command "\"#{node['mysql']['windows']['mysql_bin']}\" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < \"#{grants_path}\""
63+
action :nothing
12364
end

templates/windows/my.cnf.erb renamed to templates/windows/my.ini.erb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ max_allowed_packet = <%= node['mysql']['tunable']['max_allowed_packet'] %
5656

5757
#
5858
# Here you can see queries with especially long duration
59-
<%- if node['mysql']['version'].to_f >= 5.5 %>
60-
slow_query_log = <%= node['mysql']['tunable']['slow_query_log'] %>
59+
<%- if node['mysql']['windows']['version'].to_f >= 5.5 %>
60+
slow_query_log = <%= node['mysql']['server']['slow_query_log'] %>
6161
<% else %>
62-
log_slow_queries = <%= node['mysql']['tunable']['slow_query_log'] %>
62+
log_slow_queries = <%= node['mysql']['server']['slow_query_log'] %>
6363
<% end %>
6464

6565
long_query_time = <%= node['mysql']['tunable']['long_query_time'] %>
@@ -82,4 +82,4 @@ innodb_thread_concurrency = 8
8282

8383
<%- if node['mysql']['tunable']['innodb_file_per_table'] %>
8484
innodb_file_per_table
85-
<%- end %>
85+
<%- end %>

0 commit comments

Comments
 (0)