Skip to content

Commit

Permalink
Merge pull request till#783 from till/t/mysql-improvements
Browse files Browse the repository at this point in the history
T/mysql improvements
  • Loading branch information
fh committed Oct 19, 2015
2 parents 34ec666 + 41d09b2 commit 3893d17
Show file tree
Hide file tree
Showing 211 changed files with 23,469 additions and 491 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ AllCops:
- 'vendor/**/*'
- 'rails/**/*'
- 'runit/**/*'
- 'mysql/**/*'

Style/SingleSpaceBeforeFirstArg:
Enabled: false
Expand Down
1 change: 1 addition & 0 deletions VERSIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ cron| [1.3.12](https://github.com/opscode-cookbooks/cron/tree/v1.3.12) | - We a
erlang | [1.5.6](https://github.com/opscode-cookbooks/erlang/commit/2af91e4650c1411fbf8e44626b1a548f777926c4) | ignored in our cs/test setup
fail2ban | 2.2.1 | removed yum dependencies, adapted to our rubocop scheme, changed attributes/default.rb
logrotate | [master](https://github.com/cookbooks/logrotate/commit/d7eca3a8fef69aa489c1236ed1761c364d26fdf8)
mysql | [6.1.2](https://github.com/chef-cookbooks/mysql/commit/4ba145f2d6e5fd710ba586bc86d9f78e35fbfa60) | disabled yum and smf deps
nodejs | [2.4.0](https://github.com/redguide/nodejs/releases/tag/v2.4.0) | disabled deps on `homebrew` and `yum-epel`, added new install method in [d606ee](https://github.com/till/easybib-cookbooks/commit/d606ee9851390458e390a44875afaecc5277c219) and a minor [bugfix](https://github.com/till/easybib-cookbooks/commit/da0895e9f3813d7bf6e646fec2615a4756e3039d)
ohai| 2.0.1 |
rabbitmq | [3.4.0](https://github.com/jjasghar/rabbitmq/commit/b71c0a068419ad10324e8d13b517fafbf373c0c3) | removed yum, ignored in our cs/test setup
Expand Down
2 changes: 1 addition & 1 deletion academy/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
depends 'nginx-app'
depends 'ies'
depends 'ohai'
depends 'percona'
depends 'ies-mysql'
depends 'php-pdo_sqlite'
depends 'nodejs'
depends 'avahi'
Expand Down
4 changes: 2 additions & 2 deletions academy/recipes/role-vagrant.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include_recipe 'ohai'
include_recipe 'percona::server'
include_recipe 'percona::dev'
include_recipe 'ies-mysql'
include_recipe 'ies-mysql::dev'
include_recipe 'easybib::role-phpapp'
include_recipe 'nginx-app::vagrant'
include_recipe 'php-pdo_sqlite'
Expand Down
3 changes: 3 additions & 0 deletions ies-mysql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ies-mysql

A wrapper cookbook to setup MySQL Server & Client in development environments.
24 changes: 24 additions & 0 deletions ies-mysql/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
default['ies-mysql'] = {}
default['ies-mysql']['version'] = '5.6'

default['ies-mysql']['server-config'] = {
'user' => 'root',
'password' => '',
'port' => 3306,
'bind-address' => '0.0.0.0',
'instance-name' => 'vagrant'
}

default['ies-mysql']['mysqld-config'] = {
'interactive_timeout' => 300,
'slow_query_log' => '1',
'slow_query_log_file' => '/var/log/mysql/log-slow-queries.log',
'log_queries_not_using_indexes' => '1',
'log_slow_admin_statements' => '1',
'long_query_time' => 5,
'wait_timeout' => 60,
'innodb_buffer_pool_size' => '512M',
'innodb_flush_log_at_trx_commit' => 0,
'innodb_flush_method' => 'O_DIRECT',
'skip_name_resolve' => '1'
}
File renamed without changes.
8 changes: 8 additions & 0 deletions ies-mysql/metadata.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name 'ies-mysql'

description 'A wrapper recipe to install and configure MySQL Server and client.'

supports 'ubuntu'

depends 'mysql'
depends 'easybib'
4 changes: 4 additions & 0 deletions ies-mysql/recipes/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
mysql_client node['ies-mysql']['server-config']['instance-name'] do
version node['ies-mysql'].fetch('version', '5.6')
action :create
end
41 changes: 41 additions & 0 deletions ies-mysql/recipes/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
mysql_version = node['ies-mysql'].fetch('version', '5.6')

server_config = node['ies-mysql']['server-config']

mysql_service server_config['instance-name'] do
version mysql_version
bind_address server_config['bind-address']
port server_config['port']
initial_root_password server_config['password']
provider Chef::Provider::MysqlServiceUpstart
action [:create, :start]
end

mysql_client server_config['instance-name'] do
version mysql_version
action :create
end

include_recipe 'ies-mysql::client'

config = node['ies-mysql']['mysqld-config']

file config['slow_query_log_file'] do
owner 'mysql'
group 'mysql'
action :create_if_missing
only_if do
config['slow_query_log_file']
end
end

instance = node['ies-mysql']['server-config']['instance-name']

mysql_config 'vagrant-settings' do
instance instance
source 'vagrant.cnf.erb'
variables(
:config => config
)
notifies :restart, "mysql_service[#{instance}]"
end
22 changes: 22 additions & 0 deletions ies-mysql/recipes/dev.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Chef::Resource.send(:include, EasyBib)

# Grant root access from *!
# Obviously not a good idea in production.

cookbook_file '/tmp/grant.sql' do
source 'grant.sql'
mode '0600'
not_if { is_aws(node) }
end

server_config = node['ies-mysql']['server-config']

mysql_command = "mysql -u #{server_config['user']}"
mysql_command += " -p#{server_config['password']}" unless server_config['password'].empty?
mysql_command += ' -h 127.0.0.1'
mysql_command += ' < /tmp/grant.sql'

execute 'open mysql to the world' do
command mysql_command
not_if { is_aws(node) }
end
13 changes: 13 additions & 0 deletions ies-mysql/spec/client_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'chefspec'

describe 'ies-mysql::client' do
let(:runner) do
ChefSpec::Runner.new(:log_level => :error)
end

let(:chef_run) { runner.converge(described_recipe) }

it 'the client' do
expect(chef_run).to create_mysql_client('vagrant')
end
end
20 changes: 20 additions & 0 deletions ies-mysql/spec/default_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
require 'chefspec'

describe 'ies-mysql::default' do
let(:runner) do
ChefSpec::Runner.new(:log_level => :error)
end

let(:chef_run) { runner.converge(described_recipe) }

it 'it installs the server and the client' do
expect(chef_run).to create_mysql_service('vagrant')

expect(chef_run).to include_recipe 'ies-mysql::client'
end

it 'it configures mysql' do
expect(chef_run).to create_file_if_missing('/var/log/mysql/log-slow-queries.log')
expect(chef_run).to create_mysql_config('vagrant-settings')
end
end
28 changes: 28 additions & 0 deletions ies-mysql/spec/dev_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'chefspec'

describe 'ies-mysql::dev' do
let(:runner) do
ChefSpec::Runner.new(:log_level => :error)
end

let(:chef_run) { runner.converge(described_recipe) }
let(:node) { runner.node }

describe 'local/vagrant' do
it 'it does execute the recipe' do
expect(chef_run).to create_cookbook_file('/tmp/grant.sql')
expect(chef_run).to run_execute('open mysql to the world')
end
end

describe 'AWS' do
before do
node.set['opsworks'] = {}
end

it 'it does not execute the recipe' do
expect(chef_run).not_to create_cookbook_file('/tmp/grant.sql')
expect(chef_run).not_to run_execute('open mysql to the world')
end
end
end
File renamed without changes.
5 changes: 5 additions & 0 deletions mysql/.codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
engines:
foodcritic:
enabled: true
rubocop:
enabled: true
46 changes: 46 additions & 0 deletions mysql/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
*.gem
.zero-knife.rb
*.rbc
.bundle
.config
coverage
InstalledFiles
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
Gemfile.lock
_Store
*~
*#
.#*
\#*#
.*.sw[a-z]
*.un~
*.tmp
*.bk
*.bkup
.ruby-version
.ruby-gemset
.rvmrc

# YARD artifacts
.yardoc
_yardoc
doc/
.idea

#chef stuff
Berksfile.lock
.kitchen
.kitchen.local.yml
vendor/
.coverage/

#vagrant stuff
.vagrant/
.vagrant.d/
.kitchen/
Loading

0 comments on commit 3893d17

Please sign in to comment.