switching to librarian to track these

This commit is contained in:
mattray
2012-08-07 21:49:13 -05:00
parent bb87164701
commit 3dd804b845
9 changed files with 194 additions and 498 deletions

View File

@@ -11,12 +11,14 @@ Platform
* Debian, Ubuntu
* CentOS, Red Hat, Fedora
* Mac OS X (Using homebrew)
Tested on:
* Debian 5.0
* Ubuntu 10.04
* CentOS 5.5
* Mac OS X 10.7.2
Cookbooks
---------
@@ -25,6 +27,8 @@ Requires Opscode's openssl cookbook for secure password generation. See _Attribu
Requires a C compiler and Ruby development package in order to build mysql gem with native extensions. On Debian and Ubuntu systems this is satisfied by installing the "build-essential" and "ruby-dev" packages before running Chef. See USAGE below for information on how to handle this during a Chef run.
Requires homebrew cookbook on Mac OS X.
Resources and Providers
=======================
@@ -40,6 +44,8 @@ Attributes
* `mysql['data_dir']` - Location for mysql data directory, default is "/var/lib/mysql"
* `mysql['conf_dir']` - Location for mysql conf directory, default is "/etc/mysql"
* `mysql['ec2_path']` - location of mysql data_dir on EC2 nodes, default "/mnt/mysql"
* `mysql['reload_action']` - Action to take when mysql conf files are modified, default "restart". Also allows "reload" and "none".
Performance tuning attributes, each corresponds to the same-named parameter in my.cnf; default values listed

View File

@@ -17,8 +17,6 @@
# limitations under the License.
#
default['mysql']['gem_binary'] = nil
case node["platform"]
when "windows"
default['mysql']['client']['version'] = "6.0.2"

View File

@@ -2,7 +2,7 @@
# Cookbook Name:: mysql
# Attributes:: server
#
# Copyright 2008-2012, Opscode, Inc.
# Copyright 2008-2009, Opscode, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -17,7 +17,8 @@
# limitations under the License.
#
default['mysql']['bind_address'] = attribute?('cloud') ? cloud['local_ipv4'] : ipaddress
default['mysql']['bind_address'] = attribute?('cloud') ? cloud['local_ipv4'] : ipaddress
default['mysql']['port'] = 3306
case node["platform"]
when "centos", "redhat", "fedora", "suse", "scientific", "amazon"
@@ -35,6 +36,8 @@ when "centos", "redhat", "fedora", "suse", "scientific", "amazon"
set['mysql']['pid_file'] = "/var/run/mysqld/mysqld.pid"
set['mysql']['old_passwords'] = 1
set['mysql']['grants_path'] = "/etc/mysql_grants.sql"
# RHEL/CentOS mysql package does not support this option.
set['mysql']['tunable']['innodb_adaptive_flushing'] = false
when "freebsd"
default['mysql']['package_name'] = "mysql55-server"
default['mysql']['service_name'] = "mysql-server"
@@ -67,6 +70,13 @@ when "windows"
default['mysql']['conf_dir'] = "#{mysql['basedir']}"
default['mysql']['old_passwords'] = 0
default['mysql']['grants_path'] = "#{mysql['conf_dir']}\\grants.sql"
when "mac_os_x"
default['mysql']['package_name'] = "mysql"
default['mysql']['basedir'] = "/usr/local/Cellar"
default['mysql']['data_dir'] = "/usr/local/var/mysql"
default['mysql']['root_group'] = "admin"
default['mysql']['mysqladmin_bin'] = "/usr/local/bin/mysqladmin"
default['mysql']['mysql_bin'] = "/usr/local/bin/mysql"
else
default['mysql']['package_name'] = "mysql-server"
default['mysql']['service_name'] = "mysql"
@@ -90,8 +100,13 @@ if attribute?('ec2')
default['mysql']['ebs_vol_size'] = 50
end
default['mysql']['reload_action'] = "restart" # or "reload" or "none"
default['mysql']['use_upstart'] = 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']['back_log'] = "128"
default['mysql']['tunable']['key_buffer'] = "256M"
@@ -109,6 +124,26 @@ default['mysql']['tunable']['thread_concurrency'] = 10
default['mysql']['tunable']['thread_stack'] = "256K"
default['mysql']['tunable']['wait_timeout'] = "180"
default['mysql']['tunable']['log_bin'] = nil
default['mysql']['tunable']['log_bin_trust_function_creators'] = false
default['mysql']['tunable']['relay_log'] = nil
default['mysql']['tunable']['log_slave_updates'] = false
default['mysql']['tunable']['sync_binlog'] = 0
default['mysql']['tunable']['skip_slave_start'] = false
default['mysql']['tunable']['log_error'] = nil
default['mysql']['tunable']['log_queries_not_using_index'] = true
default['mysql']['tunable']['log_bin_trust_function_creators'] = false
default['mysql']['tunable']['innodb_buffer_pool_size'] = "128M"
default['mysql']['tunable']['innodb_log_file_size'] = "5M"
default['mysql']['tunable']['innodb_buffer_pool_size'] = "128M"
default['mysql']['tunable']['innodb_additional_mem_pool_size'] = "8M"
default['mysql']['tunable']['innodb_data_file_path'] = "ibdata1:10M:autoextend"
default['mysql']['tunable']['innodb_flush_log_at_trx_commit'] = "1"
default['mysql']['tunable']['innodb_flush_method'] = false
default['mysql']['tunable']['innodb_log_buffer_size'] = "8M"
default['mysql']['tunable']['query_cache_limit'] = "1M"
default['mysql']['tunable']['query_cache_size'] = "16M"
@@ -117,5 +152,3 @@ default['mysql']['tunable']['long_query_time'] = 2
default['mysql']['tunable']['expire_logs_days'] = 10
default['mysql']['tunable']['max_binlog_size'] = "100M"
default['mysql']['tunable']['innodb_buffer_pool_size'] = "256M"

View File

@@ -1,19 +0,0 @@
begin
require 'mysql'
rescue LoadError
Chef::Log.info("Missing gem 'mysql'")
end
module Opscode
module Mysql
module Database
def db
@db ||= ::Mysql.new new_resource.host, new_resource.username, new_resource.password
end
def close
@db.close rescue nil
@db = nil
end
end
end
end

File diff suppressed because one or more lines are too long

View File

@@ -3,19 +3,20 @@ maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs and configures mysql for client or server"
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version "1.2.6"
version "1.2.7"
recipe "mysql", "Includes the client recipe to configure a client"
recipe "mysql::client", "Installs packages required for mysql clients using run_action magic"
recipe "mysql::server", "Installs packages required for mysql servers w/o manual intervention"
recipe "mysql::server_ec2", "Performs EC2-specific mountpoint manipulation"
%w{ debian ubuntu centos suse fedora redhat scientific amazon freebsd windows }.each do |os|
%w{ debian ubuntu centos suse fedora redhat scientific amazon freebsd windows mac_os_x }.each do |os|
supports os
end
depends "build-essential"
depends "openssl"
depends "windows"
suggests "homebrew"
suggests "windows"
attribute "mysql/server_root_password",
:display_name => "MySQL Server Root Password",
@@ -42,6 +43,11 @@ attribute "mysql/ec2_path",
:description => "Location of mysql directory on EC2 instance EBS volumes",
:default => "/mnt/mysql"
attribute "mysql/reload_action",
:display_name => "MySQL conf file reload action",
:description => "Action to take when mysql conf files are modified",
:default => "reload"
attribute "mysql/tunable",
:display_name => "MySQL Tunables",
:description => "Hash of MySQL tunable attributes",

View File

@@ -21,6 +21,10 @@
# to debian_before_squeeze? and ubuntu_before_lucid?
::Chef::Recipe.send(:include, Opscode::Mysql::Helpers)
#install the mysql gem for the Chef Ruby used by the database cookbook LWRPs
node.set['build_essential']['compiletime'] = true
include_recipe "build-essential"
mysql_packages = case node['platform']
when "centos", "redhat", "suse", "fedora", "scientific", "amazon"
%w{mysql mysql-devel}
@@ -49,6 +53,9 @@ when "windows"
windows_package(*args, &blk)
end
[node['mysql']['client']['package_name']]
when "mac_os_x"
include_recipe 'homebrew'
%w{mysql-connector-c}
else
%w{mysql-client libmysqlclient-dev}
end
@@ -59,9 +66,19 @@ mysql_packages.each do |mysql_pack|
end
end
gem_package "mysql" do
gem_binary = node['mysql']['gem_binary']
action :install
chef_gem "mysql" do
action :nothing
subscribes :install, resources(:package => mysql_packages.last), :immediately
end
if platform?(%w{ redhat centos fedora suse scientific amazon })
package 'ruby-mysql'
elsif platform?(%w{ debian ubuntu })
package "libmysql-ruby"
else
gem_package "mysql" do
action :install
end
end
if platform? 'windows'

View File

@@ -78,53 +78,63 @@ package node['mysql']['package_name'] do
action :install
end
directory node['mysql']['confd_dir'] do
owner "mysql" unless platform? 'windows'
group "mysql" unless platform? 'windows'
action :create
recursive true
end
unless platform?(%w{mac_os_x})
if platform? 'windows'
require 'win32/service'
windows_path node['mysql']['bin_dir'] do
action :add
directory node['mysql']['confd_dir'] do
owner "mysql" unless platform? 'windows'
group "mysql" unless platform? 'windows'
action :create
recursive true
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']) }
if platform? '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
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"
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
supports :status => true, :restart => true, :reload => true
action :nothing
end
supports :status => true, :restart => true, :reload => true
action :nothing
end
skip_federated = case node['platform']
when 'fedora', 'ubuntu', 'amazon'
true
when 'centos', 'redhat', 'scientific'
node['platform_version'].to_f < 6.0
else
false
end
skip_federated = case node['platform']
when 'fedora', 'ubuntu', 'amazon'
true
when 'centos', 'redhat', 'scientific'
node['platform_version'].to_f < 6.0
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"
notifies :restart, resources(:service => "mysql"), :immediately
variables :skip_federated => skip_federated
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, resources(:service => "mysql"), :immediately
when 'reload'
notifies :reload, resources(: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
end
unless Chef::Config[:solo]
@@ -148,31 +158,42 @@ unless platform?(%w{debian ubuntu})
end
grants_path = node['mysql']['grants_path']
# Homebrew has its own way to do databases
if platform?(%w{mac_os_x})
begin
t = resources("template[#{grants_path}]")
rescue
Chef::Log.info("Could not find previously defined grants.sql resource")
t = template grants_path do
source "grants.sql.erb"
owner "root" unless platform? 'windows'
group node['mysql']['root_group'] unless platform? 'windows'
mode "0600"
action :create
execute "mysql-install-db" do
command "mysql_install_db --verbose --user=`whoami` --basedir=\"$(brew --prefix mysql)\" --datadir=#{node['mysql']['data_dir']} --tmpdir=/tmp"
environment('TMPDIR' => nil)
action :run
creates "#{node['mysql']['data_dir']}/mysql"
end
end
if platform? 'windows'
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
end
else
execute "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']['grants_path']
begin
t = resources("template[#{grants_path}]")
rescue
Chef::Log.info("Could not find previously defined grants.sql resource")
t = template grants_path do
source "grants.sql.erb"
owner "root" unless platform? 'windows'
group node['mysql']['root_group'] unless platform? 'windows'
mode "0600"
action :create
end
end
if platform? 'windows'
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
end
else
execute "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
end
end
end

View File

@@ -2,13 +2,13 @@
# Generated by Chef for <%= node['hostname'] %>
#
# Local modifications will be overwritten.
#
#
# The MySQL database server configuration file.
#
# You can copy this to one of:
# - "/etc/mysql/my.cnf" to set global options,
# - "~/.my.cnf" to set user-specific options.
#
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
@@ -21,7 +21,7 @@
# escpecially if they contain "#" chars...
# Remember to edit /etc/mysql/debian.cnf when changing the socket location.
[client]
port = 3306
port = <%= node['mysql']['port'] %>
socket = <%= node['mysql']['socket'] %>
# Here is entries for some specific programs
@@ -46,7 +46,7 @@ nice = 0
user = mysql
pid-file = <%= node['mysql']['pid_file'] %>
socket = <%= node['mysql']['socket'] %>
port = 3306
port = <%= node['mysql']['port'] %>
basedir = <%= node['mysql']['basedir'] %>
datadir = <%= node['mysql']['data_dir'] %>
tmpdir = /tmp
@@ -62,6 +62,10 @@ key_buffer = <%= node['mysql']['tunable']['key_buffer'] %>
max_allowed_packet = <%= node['mysql']['tunable']['max_allowed_packet'] %>
thread_stack = <%= node['mysql']['tunable']['thread_stack'] %>
thread_cache_size = <%= node['mysql']['tunable']['thread_cache_size'] %>
auto-increment-increment = <%= node['mysql']['auto-increment-increment'] %>
auto-increment-offset = <%= node['mysql']['auto-increment-offset'] %>
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
@@ -89,21 +93,40 @@ query_cache_size = <%= node['mysql']['tunable']['query_cache_size'] %>
#log = /var/log/mysql/mysql.log
#
# Error logging goes to syslog. This is a Debian improvement :)
<%- if node['mysql']['tunable']['log_error'] %>
log-error = <%= node['mysql']['tunable']['log_error'] %>
<%- end %>
#
# Here you can see queries with especially long duration
log_slow_queries = <%= node['mysql']['tunable']['log_slow_queries'] %>
long_query_time = <%= node['mysql']['tunable']['long_query_time'] %>
<%- if node['mysql']['tunable']['log_queries_not_using_index'] %>
log-queries-not-using-indexes
<%- end %>
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
#server-id = 1
#log_bin = /var/log/mysql/mysql-bin.log
<%- if node['mysql']['tunable']['log_bin'] %>
log_bin = <%= node['mysql']['tunable']['log_bin'] %>
log_slave_updates = <%= node['mysql']['tunable']['log_slave_updates'] %>
<%- end %>
<%- if node['mysql']['tunable']['log_bin_trust_function_creators'] %>
log_bin_trust_function_creators
<%- end %>
expire_logs_days = <%= node['mysql']['tunable']['expire_logs_days'] %>
max_binlog_size = <%= node['mysql']['tunable']['max_binlog_size'] %>
#binlog_do_db = include_database_name
#binlog_ignore_db = include_database_name
<%- if node['mysql']['tunable']['relay_log'] %>
relay-log = <%= node['mysql']['tunable']['relay_log'] %>
<%- end %>
sync_binlog = <%= node['mysql']['tunable']['sync_binlog'] %>
<%- if node['mysql']['tunable']['skip_slave_start'] %>
skip_slave_start
<%- end %>
#
# * InnoDB
#
@@ -112,6 +135,18 @@ max_binlog_size = <%= node['mysql']['tunable']['max_binlog_size'] %>
# You might want to disable InnoDB to shrink the mysqld process by circa 100MB.
#skip-innodb
innodb_buffer_pool_size = <%= node['mysql']['tunable']['innodb_buffer_pool_size'] %>
innodb_log_file_size = <%= node['mysql']['tunable']['innodb_log_file_size'] %>
innodb_additional_mem_pool_size = <%= node['mysql']['tunable']['innodb_additional_mem_pool_size'] %>
innodb_data_file_path = <%= node['mysql']['tunable']['innodb_data_file_path'] %>
innodb_file_per_table
innodb_flush_log_at_trx_commit = <%= node['mysql']['tunable']['innodb_flush_log_at_trx_commit'] %>
<%- if node['mysql']['tunable']['innodb_flush_method'] %>
innodb_flush_method = <%= node['mysql']['tunable']['innodb_flush_method'] %>
<%- end %>
innodb_log_buffer_size = <%= node['mysql']['tunable']['innodb_log_buffer_size'] %>
<%- if node['mysql']['tunable']['innodb_adaptive_flushing'] %>
innodb_adaptive_flushing = <%= node['mysql']['tunable']['innodb_adaptive_flushing'] %>
<%- end %>
<% if @skip_federated %>
#