Permalink
Browse files

[COOK-1694] - additional cleanup, platform nuances

* Resolve most foodcritic style findings (consistent node attributes,
  strings instead of symbols). FC002 is outstanding because we want
  the value to be a string. FC007 is outstanding because mac_os_x
  may not be a common platform. FC024 is outstanding because other
  additional platforms haven't been verified for skip_federated
* Use 'default' instead of 'set' in attributes files.
* Guard against older CentOS/RHEL platforms that do not support
  certain options in my.cnf (event_scheduler, table_open_cache,
  binlog_format)
* The service should be enabled, but not have action :start until the
  end of the recipe to avoid configuration issues that prevent startup.
* Packages should notify the service to start immediately to get
  around the above config file issue, but allow the other
  configuration that requires mysql running (like grants)
* Create the slow_query_log file's directory.
  • Loading branch information...
1 parent 39b98aa commit 3dab2beaee4ce1712c8055f5163d9b6ccefd7551 @jtimberman jtimberman committed Dec 11, 2012
Showing with 61 additions and 52 deletions.
  1. +43 −37 attributes/server.rb
  2. +4 −4 libraries/helpers.rb
  3. +7 −10 recipes/server.rb
  4. +1 −1 templates/default/grants.sql.erb
  5. +6 −0 templates/default/my.cnf.erb
View
@@ -31,19 +31,19 @@
default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin"
default['mysql']['mysql_bin'] = "/usr/bin/mysql"
- set['mysql']['conf_dir'] = '/etc/mysql'
- set['mysql']['confd_dir'] = '/etc/mysql/conf.d'
- 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"
+ default['mysql']['conf_dir'] = '/etc/mysql'
+ default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
+ default['mysql']['socket'] = "/var/run/mysqld/mysqld.sock"
+ default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
+ default['mysql']['old_passwords'] = 0
+ default['mysql']['grants_path'] = "/etc/mysql/grants.sql"
when "rhel", "fedora", "suse"
if node["mysql"]["version"].to_f >= 5.5
default['mysql']['service_name'] = "mysql"
- set['mysql']['pid_file'] = "/var/run/mysql/mysql.pid"
+ default['mysql']['pid_file'] = "/var/run/mysql/mysql.pid"
else
default['mysql']['service_name'] = "mysqld"
- set['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
+ default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
end
default['mysql']['server']['packages'] = %w{mysql-server}
default['mysql']['basedir'] = "/usr"
@@ -52,13 +52,13 @@
default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin"
default['mysql']['mysql_bin'] = "/usr/bin/mysql"
- set['mysql']['conf_dir'] = '/etc'
- set['mysql']['confd_dir'] = '/etc/mysql/conf.d'
- set['mysql']['socket'] = "/var/lib/mysql/mysql.sock"
- set['mysql']['old_passwords'] = 1
- set['mysql']['grants_path'] = "/etc/mysql_grants.sql"
+ default['mysql']['conf_dir'] = '/etc'
+ default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
+ default['mysql']['socket'] = "/var/lib/mysql/mysql.sock"
+ default['mysql']['old_passwords'] = 1
+ default['mysql']['grants_path'] = "/etc/mysql_grants.sql"
# RHEL/CentOS mysql package does not support this option.
- set['mysql']['tunable']['innodb_adaptive_flushing'] = false
+ default['mysql']['tunable']['innodb_adaptive_flushing'] = false
when "freebsd"
default['mysql']['server']['packages'] = %w{mysql55-server}
default['mysql']['service_name'] = "mysql-server"
@@ -68,12 +68,12 @@
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']['confd_dir'] = '/usr/local/etc/mysql/conf.d'
- 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"
+ default['mysql']['conf_dir'] = '/usr/local/etc'
+ default['mysql']['confd_dir'] = '/usr/local/etc/mysql/conf.d'
+ default['mysql']['socket'] = "/tmp/mysqld.sock"
+ default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
+ default['mysql']['old_passwords'] = 0
+ default['mysql']['grants_path'] = "/var/db/mysql/grants.sql"
when "windows"
default['mysql']['server']['packages'] = ["MySQL Server 5.5"]
default['mysql']['version'] = '5.5.21'
@@ -83,14 +83,14 @@
default['mysql']['service_name'] = "mysql"
default['mysql']['basedir'] = "#{ENV['SYSTEMDRIVE']}\\Program Files (x86)\\MySQL\\#{mysql['server']['packages'].first}"
- default['mysql']['data_dir'] = "#{mysql['basedir']}\\Data"
- default['mysql']['bin_dir'] = "#{mysql['basedir']}\\bin"
- default['mysql']['mysqladmin_bin'] = "#{mysql['bin_dir']}\\mysqladmin"
- default['mysql']['mysql_bin'] = "#{mysql['bin_dir']}\\mysql"
+ default['mysql']['data_dir'] = "#{node['mysql']['basedir']}\\Data"
+ default['mysql']['bin_dir'] = "#{node['mysql']['basedir']}\\bin"
+ default['mysql']['mysqladmin_bin'] = "#{node['mysql']['bin_dir']}\\mysqladmin"
+ default['mysql']['mysql_bin'] = "#{node['mysql']['bin_dir']}\\mysql"
- default['mysql']['conf_dir'] = "#{mysql['basedir']}"
+ default['mysql']['conf_dir'] = node['mysql']['basedir']
default['mysql']['old_passwords'] = 0
- default['mysql']['grants_path'] = "#{mysql['conf_dir']}\\grants.sql"
+ default['mysql']['grants_path'] = "#{node['mysql']['conf_dir']}\\grants.sql"
when "mac_os_x"
default['mysql']['server']['packages'] = %w{mysql}
default['mysql']['basedir'] = "/usr/local/Cellar"
@@ -107,12 +107,12 @@
default['mysql']['mysqladmin_bin'] = "/usr/bin/mysqladmin"
default['mysql']['mysql_bin'] = "/usr/bin/mysql"
- set['mysql']['conf_dir'] = '/etc/mysql'
- set['mysql']['confd_dir'] = '/etc/mysql/conf.d'
- 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"
+ default['mysql']['conf_dir'] = '/etc/mysql'
+ default['mysql']['confd_dir'] = '/etc/mysql/conf.d'
+ default['mysql']['socket'] = "/var/run/mysqld/mysqld.sock"
+ default['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
+ default['mysql']['old_passwords'] = 0
+ default['mysql']['grants_path'] = "/etc/mysql/grants.sql"
end
if attribute?('ec2')
@@ -123,15 +123,14 @@
default['mysql']['reload_action'] = "restart" # or "reload" or "none"
-default['mysql']['use_upstart'] = node.platform == "ubuntu" && node['platform_version'].to_f >= 10.04
+default['mysql']['use_upstart'] = node['platform'] == "ubuntu" && node['platform_version'].to_f >= 10.04
default['mysql']['auto-increment-increment'] = 1
default['mysql']['auto-increment-offset'] = 1
default['mysql']['allow_remote_root'] = false
default['mysql']['tunable']['character-set-server'] = "utf8"
default['mysql']['tunable']['collation-server'] = "utf8_general_ci"
-default['mysql']['tunable']['event_scheduler'] = 0
default['mysql']['tunable']['back_log'] = "128"
default['mysql']['tunable']['key_buffer'] = "256M"
default['mysql']['tunable']['myisam_sort_buffer_size'] = "8M"
@@ -150,7 +149,7 @@
default['mysql']['tunable']['net_read_timeout'] = "30"
default['mysql']['tunable']['net_write_timeout'] = "30"
default['mysql']['tunable']['table_cache'] = "128"
-default['mysql']['tunable']['table_open_cache'] = "128"
+
default['mysql']['tunable']['thread_cache'] = "128"
default['mysql']['tunable']['thread_cache_size'] = 8
default['mysql']['tunable']['thread_concurrency'] = 10
@@ -172,11 +171,11 @@
default['mysql']['tunable']['server_id'] = nil
default['mysql']['tunable']['log_bin'] = nil
default['mysql']['tunable']['log_bin_trust_function_creators'] = false
-default['mysql']['tunable']['binlog_format'] = "statement"
+
default['mysql']['tunable']['relay_log'] = nil
default['mysql']['tunable']['relay_log_index'] = nil
default['mysql']['tunable']['log_slave_updates'] = false
-default['mysql']['tunable']['binlog_format'] = "MIXED"
+
default['mysql']['tunable']['sync_binlog'] = 0
default['mysql']['tunable']['skip_slave_start'] = false
@@ -231,3 +230,10 @@
default['mysql']['log_dir'] = node['mysql']['data_dir']
default['mysql']['log_files_in_group'] = false
default['mysql']['innodb_status_file'] = false
+
+unless node['platform_family'] && node['platform_version'].to_i < 6
+ # older RHEL platforms don't support these options
+ default['mysql']['tunable']['event_scheduler'] = 0
+ default['mysql']['tunable']['table_open_cache'] = "128"
+ default['mysql']['tunable']['binlog_format'] = "statement" if node['mysql']['tunable']['log_bin']
+end
@@ -6,9 +6,9 @@
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -21,11 +21,11 @@ module Mysql
module Helpers
def debian_before_squeeze?
- (node.platform == "debian") && (node.platform_version.to_f < 6.0)
+ (node['platform'] == "debian") && (node['platform_version'].to_f < 6.0)
end
def ubuntu_before_lucid?
- (node.platform == "ubuntu") && (node.platform_version.to_f < 10.0)
+ (node['platform'] == "ubuntu") && (node['platform_version'].to_f < 10.0)
end
end
View
@@ -93,12 +93,14 @@ def package(*args, &blk)
node['mysql']['server']['packages'].each do |package_name|
package package_name do
action :install
+ notifies :start, "service[mysql]", :immediately
end
end
unless platform_family?(%w{mac_os_x})
[File.dirname(node['mysql']['pid_file']),
+ File.dirname(node['mysql']['tunable']['slow_query_log']),
node['mysql']['confd_dir'],
node['mysql']['confd_dir'],
node['mysql']['log_dir'],
@@ -124,15 +126,6 @@ def package(*args, &blk)
end
end
- service "mysql" do
- service_name node['mysql']['service_name']
- if node['mysql']['use_upstart']
- restart_command "restart mysql"
- stop_command "stop mysql"
- start_command "start mysql"
- end
- end
-
skip_federated = case node['platform']
when 'fedora', 'ubuntu', 'amazon'
true
@@ -164,7 +157,7 @@ def package(*args, &blk)
provider Chef::Provider::Service::Upstart
end
supports :status => true, :restart => true, :reload => true
- action [:start, :enable]
+ action :enable
end
end
@@ -221,4 +214,8 @@ def package(*args, &blk)
end
variables :skip_federated => skip_federated
end
+
+ service "mysql" do
+ action :start
+ end
end
@@ -3,7 +3,7 @@
<% case node['platform_family'] -%>
<% when "debian" -%>
-GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '<%= node[:mysql][:server_debian_password] %>' WITH GRANT OPTION;
+GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY '<%= node['mysql']['server_debian_password'] %>' WITH GRANT OPTION;
<% end -%>
# Grant replication for a slave user.
GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' identified by '<%= node['mysql']['server_repl_password'] %>';
@@ -58,7 +58,9 @@ skip-name-resolve
# Charset and Collation
character-set-server = <%= node['mysql']['tunable']['character-set-server'] %>
collation-server = <%= node['mysql']['tunable']['collation-server'] %>
+<%- if node['mysql']['tunable']['event_scheduler'] %>
event_scheduler = <%= node['mysql']['tunable']['event_scheduler'] %>
+<%- end %>
<%- if node['mysql']['tunable']['skip-character-set-client-handshake'] %>
skip-character-set-client-handshake
<%- end %>
@@ -94,7 +96,9 @@ net_read_timeout = <%= node['mysql']['tunable']['net_read_timeout'] %>
net_write_timeout = <%= node['mysql']['tunable']['net_write_timeout'] %>
back_log = <%= node['mysql']['tunable']['back_log'] %>
table_cache = <%= node['mysql']['tunable']['table_cache'] %>
+<%- if node['mysql']['tunable']['table_open_cache'] %>
table_open_cache = <%= node['mysql']['tunable']['table_open_cache'] %>
+<%- end %>
tmp_table_size = <%= node['mysql']['tunable']['tmp_table_size'] %>
max_heap_table_size = <%= node['mysql']['tunable']['max_heap_table_size'] %>
bulk_insert_buffer_size = <%= node['mysql']['tunable']['bulk_insert_buffer_size'] %>
@@ -150,9 +154,11 @@ log-queries-not-using-indexes
<%- if node['mysql']['tunable']['server_id'] %>
server-id = <%= node['mysql']['tunable']['server_id'] %>
<% end %>
+<%- if node['mysql']['tunable']['binlog_format'] %>
binlog_format = <%= node['mysql']['tunable']['binlog_format'] %>
+<%- end %>
<%- if node['mysql']['tunable']['log_bin'] %>
log_bin = <%= node['mysql']['tunable']['log_bin'] %>
<%- if node['mysql']['tunable']['log_bin'] %>

0 comments on commit 3dab2be

Please sign in to comment.