Skip to content

Commit

Permalink
[COOK-4068] - Fix up Windows recipe
Browse files Browse the repository at this point in the history
Signed-off-by: Sean OMeara <[email protected]>
  • Loading branch information
Julian C. Dunn authored and Sean OMeara committed Dec 21, 2013
1 parent ed0aecb commit ce16693
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 97 deletions.
16 changes: 9 additions & 7 deletions attributes/server_windows.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
case node['platform_family']
when 'windows'
default['mysql']['windows']['package_file'] = "mysql-#{mysql['version']}-#{mysql['arch']}.msi"
default['mysql']['windows']['version'] = '5.5.34'
default['mysql']['windows']['arch'] = node['kernel']['machine'] == 'x86_64' ? 'winx64' : 'win32'
default['mysql']['windows']['package_file'] = "mysql-#{node['mysql']['windows']['version']}-#{node['mysql']['windows']['arch']}.msi"
default['mysql']['windows']['packages'] = ['MySQL Server 5.5']
default['mysql']['windows']['url'] = "http://www.mysql.com/get/Downloads/MySQL-5.5/#{mysql['package_file']}/from/http://mysql.mirrors.pair.com/"
default['mysql']['windows']['version'] = '5.5.32'
# default['mysql']['windows']['arch'] = 'win32'
default['mysql']['windows']['url'] = "http://dev.mysql.com/get/Downloads/MySQL-5.5/#{node['mysql']['windows']['package_file']}"

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

default['mysql']['windows']['conf_dir'] = node['mysql']['windows']['basedir']
default['mysql']['windows']['old_passwords'] = 0
default['mysql']['windows']['grants_path'] = "#{node['mysql']['conf_dir']}\\grants.sql"
default['mysql']['windows']['grants_path'] = "#{node['mysql']['windows']['conf_dir']}\\grants.sql"

default['mysql']['server']['service_name'] = 'mysql'
default['mysql']['server']['slow_query_log'] = 1
end
113 changes: 27 additions & 86 deletions recipes/_server_windows.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
require 'win32/service'
require 'win32/service'

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

def package(*args, &blk)
windows_package(*args, &blk)
end

#----
windows_path node['mysql']['windows']['bin_dir'] do
action :add
end
Expand All @@ -25,99 +19,46 @@ def package(*args, &blk)
notifies :run, 'execute[install mysql service]', :immediately
end

#--- FIX ME - directories

#----
execute 'install mysql service' do
command %Q["#{node['mysql']['windows']['bin_dir']}\\mysqld.exe" --install "#{node['mysql']['server']['service_name']}"]
not_if { ::Win32::Service.exists?(node['mysql']['windows']['service_name']) }
end

#----
template 'initial-my.cnf' do
path "#{node['mysql']['windows']['conf_dir']}/my.cnf"
source 'my.cnf.erb'
mode '0644'
notifies :reload, node['mysql']['windows']['service_name'], :delayed
end

#----

windows_path node['mysql']['bin_dir'] do
action :add
end

windows_batch 'install mysql service' do
command "\"#{node['mysql']['bin_dir']}\\mysqld.exe\" --install #{node['mysql']['service_name']}"
not_if { Win32::Service.exists?(node['mysql']['service_name']) }
end

#----

src_dir = win_friendly_path("#{node['mysql']['basedir']}\\data")
target_dir = win_friendly_path(node['mysql']['data_dir'])

%w{mysql performance_schema}.each do |db|
execute 'mysql-move-db' do
command %Q[move "#{src_dir}\\#{db}" "#{target_dir}"]
action :run
not_if { File.exists?(node['mysql']['data_dir'] + '/mysql/user.frm') }
end
template 'my.ini' do
path "#{node['mysql']['windows']['bin_dir']}\\my.ini"
source 'my.ini.erb'
notifies :restart, "service[mysql]"
end

#----

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

service 'mysql' do
service_name node['mysql']['service_name']
provider Chef::Provider::Service::Upstart if node['mysql']['use_upstart']
supports :status => true, :restart => true, :reload => true
action :enable
end

template 'final-my.cnf' do
path "#{node['mysql']['conf_dir']}/my.cnf"
source 'my.cnf.erb'
mode '0644'
notifies :restart, 'service[mysql]', :immediately
service_name node['mysql']['server']['service_name']
action [:enable, :start]
end

#----

execute 'assign-root-password' do
command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
command %Q["#{node['mysql']['windows']['mysqladmin_bin']}" -u root password #{node['mysql']['server_root_password']}]
action :run
only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
# 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
not_if { node['mysql']['root_password_set'] }
notifies :run, "ruby_block[root-password-set]", :immediately
end

#----

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

begin
resources("template[#{grants_path}]")
rescue
Chef::Log.info('Could not find previously defined grants.sql resource')
template grants_path do
source 'grants.sql.erb'
mode '0600'
action :create
ruby_block 'root-password-set' do
block do
node.set['mysql']['root_password_set'] = true
end
action :nothing
end

#----
windows_batch 'mysql-install-privileges' do
command "\"#{node['mysql']['mysql_bin']}\" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < \"#{grants_path}\""
action :nothing
subscribes :run, resources("template[#{grants_path}]"), :immediately
grants_path = node['mysql']['windows']['grants_path']

template grants_path do
source 'grants.sql.erb'
action :create
notifies :run, "execute[mysql-install-privileges]", :immediately
end

service 'mysql-start' do
service_name node['mysql']['server']['service_name']
action :start
execute 'mysql-install-privileges' do
command "\"#{node['mysql']['windows']['mysql_bin']}\" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < \"#{grants_path}\""
action :nothing
end
8 changes: 4 additions & 4 deletions templates/windows/my.cnf.erb → templates/windows/my.ini.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ max_allowed_packet = <%= node['mysql']['tunable']['max_allowed_packet'] %

#
# Here you can see queries with especially long duration
<%- if node['mysql']['version'].to_f >= 5.5 %>
slow_query_log = <%= node['mysql']['tunable']['slow_query_log'] %>
<%- if node['mysql']['windows']['version'].to_f >= 5.5 %>
slow_query_log = <%= node['mysql']['server']['slow_query_log'] %>
<% else %>
log_slow_queries = <%= node['mysql']['tunable']['slow_query_log'] %>
log_slow_queries = <%= node['mysql']['server']['slow_query_log'] %>
<% end %>

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

<%- if node['mysql']['tunable']['innodb_file_per_table'] %>
innodb_file_per_table
<%- end %>
<%- end %>

0 comments on commit ce16693

Please sign in to comment.