VertiPub/mysql — pull request #2 by ashahab-altiscale (2013-10-04 20:45:24+00:00)
Title: Dp-16 This updates our mysql chef repo to Opscode's one

We need this to pass dp-16: Move mysql to another mount.

The following are the changes:
-node['mysql']['server']['packages'].each do |package_name|
- package package_name do
- action :install
- notifies :start, "service[mysql]", :immediately
+# Need to create user before chown'ing files and dirs in case of first run
+unless platform_family?(%w{windows})
+
+ group "mysql" do
+ action :create
+ end
+
+ user "mysql" do
+ comment "MySQL Server"
+ gid "mysql"
+ system true
+ home node['mysql']['data_dir']
+ shell "/sbin/nologin"
end
+
end

unless platform_family?(%w{mac_os_x})
@@ -113,19 +123,6 @@ def package(*args, &blk)
end
end

- if platform_family? 'windows'
- require 'win32/service'
-
- 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
- end
-
skip_federated = case node['platform']
when 'fedora', 'ubuntu', 'amazon'
true
@@ -134,6 +131,43 @@ def package(*args, &blk)
else
false
end
+
+ 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]", :delayed
+ when 'reload'
+ notifies :reload, "service[mysql]", :delayed
+ 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
+
+end
+
+node['mysql']['server']['packages'].each do |package_name|
+ package package_name do
+ action :install
+ notifies :start, "service[mysql]", :immediately
+ end
+end
+
+if platform_family? 'windows'
+ require 'win32/service'
+
+ 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
end

# Homebrew has its own way to do databases
@@ -164,9 +198,9 @@ def package(*args, &blk)
# 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 "\"#{node['mysql']['mysqladmin_bin']}\" -u root password \"#{node['mysql']['server_root_password']}\""
+ command %Q["#{node['mysql']['mysqladmin_bin']}" -u root password '#{node['mysql']['server_root_password']}']
action :run
- only_if "\"#{node['mysql']['mysql_bin']}\" -u root -e 'show databases;'"
+ only_if %Q["#{node['mysql']['mysql_bin']}" -u root -e 'show databases;']
end

unless platform_family?(%w{mac_os_x})
@@ -193,28 +227,12 @@ def package(*args, &blk)
end
else
execute "mysql-install-privileges" do
- command %Q["#{node['mysql']['mysql_bin']}" -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }"#{node['mysql']['server_root_password']}" < "#{grants_path}"]
+ command %Q["#{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
end
end

- 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
-
service "mysql" do
action :start
end