Skip to content

Commit

Permalink
COOK-945: add FreeBSD support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrea Campi authored and jtimberman committed Jan 5, 2012
1 parent f55042d commit 43aae15
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 30 deletions.
33 changes: 32 additions & 1 deletion mysql/attributes/server.rb
Expand Up @@ -18,19 +18,50 @@
#

default['mysql']['bind_address'] = attribute?('cloud') ? cloud['local_ipv4'] : ipaddress
default['mysql']['data_dir'] = "/var/lib/mysql"

case node["platform"]
when "centos", "redhat", "fedora", "suse", "scientific", "amazon"
default['mysql']['package_name'] = "mysql-server"
default['mysql']['service_name'] = "mysqld"
default['mysql']['basedir'] = "/usr"
default['mysql']['data_dir'] = "/var/lib/mysql"
default['mysql']['root_group'] = "root"
default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin"
default['mysql']['mysql_bin'] = "/usr/bin/mysql"

set['mysql']['conf_dir'] = '/etc'
set['mysql']['socket'] = "/var/lib/mysql/mysql.sock"
set['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
set['mysql']['old_passwords'] = 1
set['mysql']['grants_path'] = "/etc/mysql_grants.sql"
when "freebsd"
default['mysql']['package_name'] = "mysql55-server"
default['mysql']['service_name'] = "mysql-server"
default['mysql']['basedir'] = "/usr/local"
default['mysql']['data_dir'] = "/var/db/mysql"
default['mysql']['root_group'] = "wheel"
default['mysql']['mysqladmin_bin'] = "/usr/local/bin/mysqladmin"
default['mysql']['mysql_bin'] = "/usr/local/bin/mysql"

set['mysql']['conf_dir'] = '/usr/local/etc'
set['mysql']['socket'] = "/tmp/mysqld.sock"
set['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
set['mysql']['old_passwords'] = 0
set['mysql']['grants_path'] = "/var/db/mysql/grants.sql"
else
default['mysql']['package_name'] = "mysql-server"
default['mysql']['service_name'] = "mysql"
default['mysql']['basedir'] = "/usr"
default['mysql']['data_dir'] = "/var/lib/mysql"
default['mysql']['root_group'] = "root"
default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin"
default['mysql']['mysql_bin'] = "/usr/bin/mysql"

set['mysql']['conf_dir'] = '/etc/mysql'
set['mysql']['socket'] = "/var/run/mysqld/mysqld.sock"
set['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
set['mysql']['old_passwords'] = 0
set['mysql']['grants_path'] = "/etc/mysql/grants.sql"
end

if attribute?('ec2')
Expand Down
32 changes: 16 additions & 16 deletions mysql/recipes/client.rb
Expand Up @@ -19,25 +19,25 @@

::Chef::Resource::Package.send(:include, Opscode::Mysql::Helpers)

package "mysql-client" do
package_name value_for_platform(
[ "centos", "redhat", "suse", "fedora", "scientific", "amazon"] => { "default" => "mysql" },
"default" => "mysql-client"
)
action :install
mysql_packages = case node['platform']
when "centos", "redhat", "suse", "fedora", "scientific", "amazon"
%w{mysql mysql-devel}
when "ubuntu","debian"
if debian_before_squeeze? || ubuntu_before_lucid?
%w{mysql-client libmysqlclient15-dev}
else
%w{mysql-client libmysqlclient-dev}
end
when "freebsd"
%w{mysql55-client}
else
%w{mysql-client libmysqlclient-dev}
end

package "mysql-devel" do
package_name begin
if platform?(%w{ centos redhat suse fedora scientific amazon })
"mysql-devel"
elsif debian_before_squeeze? || ubuntu_before_lucid?
"libmysqlclient15-dev"
else
"libmysqlclient-dev"
end
mysql_packages.each do |mysql_pack|
package mysql_pack do
action :install
end
action :install
end

if platform?(%w{ redhat centos fedora suse scientific amazon })
Expand Down
29 changes: 18 additions & 11 deletions mysql/recipes/server.rb
Expand Up @@ -30,7 +30,7 @@

directory "/var/cache/local/preseeding" do
owner "root"
group "root"
group node['mysql']['root_group']
mode 0755
recursive true
end
Expand All @@ -43,26 +43,33 @@
template "/var/cache/local/preseeding/mysql-server.seed" do
source "mysql-server.seed.erb"
owner "root"
group "root"
group node['mysql']['root_group']
mode "0600"
notifies :run, resources(:execute => "preseed mysql-server"), :immediately
end

template "#{node['mysql']['conf_dir']}/debian.cnf" do
source "debian.cnf.erb"
owner "root"
group "root"
group node['mysql']['root_group']
mode "0600"
end

end

package "mysql-server" do
package node['mysql']['package_name'] do
action :install
end

directory "#{node['mysql']['conf_dir']}/mysql/conf.d" do
owner "mysql"
group "mysql"
action :create
recursive true
end

service "mysql" do
service_name value_for_platform([ "centos", "redhat", "suse", "fedora", "scientific", "amazon" ] => {"default" => "mysqld"}, "default" => "mysql")
service_name node['mysql']['service_name']
if (platform?("ubuntu") && node.platform_version.to_f >= 10.04)
restart_command "restart mysql"
stop_command "stop mysql"
Expand All @@ -84,7 +91,7 @@
template "#{node['mysql']['conf_dir']}/my.cnf" do
source "my.cnf.erb"
owner "root"
group "root"
group node['mysql']['root_group']
mode "0644"
notifies :restart, resources(:service => "mysql"), :immediately
variables :skip_federated => skip_federated
Expand All @@ -104,14 +111,14 @@
unless platform?(%w{debian ubuntu})

execute "assign-root-password" do
command "/usr/bin/mysqladmin -u root password \"#{node['mysql']['server_root_password']}\""
command "#{node['mysql']['mysqladmin_bin']} -u root password \"#{node['mysql']['server_root_password']}\""
action :run
only_if "/usr/bin/mysql -u root -e 'show databases;'"
only_if "#{node['mysql']['mysql_bin']} -u root -e 'show databases;'"
end

end

grants_path = "#{node['mysql']['conf_dir']}/mysql_grants.sql"
grants_path = node['mysql']['grants_path']

begin
t = resources("template[#{grants_path}]")
Expand All @@ -120,14 +127,14 @@
t = template grants_path do
source "grants.sql.erb"
owner "root"
group "root"
group node['mysql']['root_group']
mode "0600"
action :create
end
end

execute "mysql-install-privileges" do
command "/usr/bin/mysql -u root #{node['mysql']['server_root_password'].empty? ? '' : '-p' }\"#{node['mysql']['server_root_password']}\" < #{grants_path}"
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
end
4 changes: 2 additions & 2 deletions mysql/templates/default/my.cnf.erb
Expand Up @@ -47,7 +47,7 @@ user = mysql
pid-file = <%= node['mysql']['pid_file'] %>
socket = <%= node['mysql']['socket'] %>
port = 3306
basedir = /usr
basedir = <%= node['mysql']['basedir'] %>
datadir = <%= node['mysql']['data_dir'] %>
tmpdir = /tmp
skip-external-locking
Expand Down Expand Up @@ -172,5 +172,5 @@ old_passwords = <%= node['mysql']['old_passwords'] %>
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/
!includedir <%= node['mysql']['conf_dir'] %>/mysql/conf.d/
<% end -%>

0 comments on commit 43aae15

Please sign in to comment.