Skip to content

Commit

Permalink
[COOK-3149] Create .my.cnf before installing
Browse files Browse the repository at this point in the history
Signed-off-by: Seth Vargo <sethvargo@gmail.com>
  • Loading branch information
Alex Barnes authored and sethvargo committed Oct 3, 2013
1 parent 6ec4bda commit 3a87637
Showing 1 changed file with 51 additions and 33 deletions.
84 changes: 51 additions & 33 deletions recipes/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,21 @@ def package(*args, &blk)
end
end

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})
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -199,22 +233,6 @@ def package(*args, &blk)
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
Expand Down

0 comments on commit 3a87637

Please sign in to comment.