server_maint 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. data/.gitmodules +21 -0
  2. data/lib/cookbooks/aws/CHANGELOG.md +11 -0
  3. data/lib/cookbooks/aws/CONTRIBUTING +29 -0
  4. data/lib/cookbooks/aws/LICENSE +201 -0
  5. data/lib/cookbooks/aws/README.md +271 -0
  6. data/lib/cookbooks/aws/attributes/default.rb +20 -0
  7. data/lib/cookbooks/aws/libraries/ec2.rb +58 -0
  8. data/lib/cookbooks/aws/metadata.rb +7 -0
  9. data/lib/cookbooks/aws/providers/ebs_volume.rb +236 -0
  10. data/lib/cookbooks/aws/providers/elastic_ip.rb +90 -0
  11. data/lib/cookbooks/aws/providers/elastic_lb.rb +24 -0
  12. data/lib/cookbooks/aws/providers/resource_tag.rb +93 -0
  13. data/lib/cookbooks/aws/recipes/default.rb +25 -0
  14. data/lib/cookbooks/aws/resources/ebs_volume.rb +17 -0
  15. data/lib/cookbooks/aws/resources/elastic_ip.rb +11 -0
  16. data/lib/cookbooks/aws/resources/elastic_lb.rb +10 -0
  17. data/lib/cookbooks/aws/resources/resource_tag.rb +11 -0
  18. data/lib/cookbooks/database/.gitignore +1 -0
  19. data/lib/cookbooks/database/CHANGELOG.md +51 -0
  20. data/lib/cookbooks/database/CONTRIBUTING +29 -0
  21. data/lib/cookbooks/database/LICENSE +201 -0
  22. data/lib/cookbooks/database/README.md +468 -0
  23. data/lib/cookbooks/database/libraries/provider_database_mysql.rb +103 -0
  24. data/lib/cookbooks/database/libraries/provider_database_mysql_user.rb +76 -0
  25. data/lib/cookbooks/database/libraries/provider_database_postgresql.rb +131 -0
  26. data/lib/cookbooks/database/libraries/provider_database_postgresql_user.rb +83 -0
  27. data/lib/cookbooks/database/libraries/provider_database_sql_server.rb +109 -0
  28. data/lib/cookbooks/database/libraries/provider_database_sql_server_user.rb +106 -0
  29. data/lib/cookbooks/database/libraries/resource_database.rb +119 -0
  30. data/lib/cookbooks/database/libraries/resource_database_user.rb +90 -0
  31. data/lib/cookbooks/database/libraries/resource_mysql_database.rb +34 -0
  32. data/lib/cookbooks/database/libraries/resource_mysql_database_user.rb +34 -0
  33. data/lib/cookbooks/database/libraries/resource_postgresql_database.rb +35 -0
  34. data/lib/cookbooks/database/libraries/resource_postgresql_database_user.rb +35 -0
  35. data/lib/cookbooks/database/libraries/resource_sql_server_database.rb +34 -0
  36. data/lib/cookbooks/database/libraries/resource_sql_server_database_user.rb +34 -0
  37. data/lib/cookbooks/database/metadata.rb +22 -0
  38. data/lib/cookbooks/database/recipes/default.rb +20 -0
  39. data/lib/cookbooks/database/recipes/ebs_backup.rb +89 -0
  40. data/lib/cookbooks/database/recipes/ebs_volume.rb +204 -0
  41. data/lib/cookbooks/database/recipes/master.rb +78 -0
  42. data/lib/cookbooks/database/recipes/mysql.rb +20 -0
  43. data/lib/cookbooks/database/recipes/postgresql.rb +20 -0
  44. data/lib/cookbooks/database/recipes/snapshot.rb +62 -0
  45. data/lib/cookbooks/database/templates/default/app_grants.sql.erb +8 -0
  46. data/lib/cookbooks/database/templates/default/aws_config.erb +3 -0
  47. data/lib/cookbooks/database/templates/default/chef-solo-database-snapshot.cron.erb +6 -0
  48. data/lib/cookbooks/database/templates/default/chef-solo-database-snapshot.json.erb +1 -0
  49. data/lib/cookbooks/database/templates/default/chef-solo-database-snapshot.rb.erb +6 -0
  50. data/lib/cookbooks/database/templates/default/ebs-backup-cron.erb +2 -0
  51. data/lib/cookbooks/database/templates/default/ebs-db-backup.sh.erb +8 -0
  52. data/lib/cookbooks/database/templates/default/ebs-db-restore.sh.erb +10 -0
  53. data/lib/cookbooks/database/templates/default/s3cfg.erb +27 -0
  54. data/lib/cookbooks/mysql/.gitignore +5 -0
  55. data/lib/cookbooks/mysql/CHANGELOG.md +86 -0
  56. data/lib/cookbooks/mysql/CONTRIBUTING +29 -0
  57. data/lib/cookbooks/mysql/Gemfile +8 -0
  58. data/lib/cookbooks/mysql/LICENSE +201 -0
  59. data/lib/cookbooks/mysql/README.md +227 -0
  60. data/lib/cookbooks/mysql/attributes/client.rb +50 -0
  61. data/lib/cookbooks/mysql/attributes/server.rb +153 -0
  62. data/lib/cookbooks/mysql/files/default/tests/minitest/server_test.rb +36 -0
  63. data/lib/cookbooks/mysql/files/default/tests/minitest/support/helpers.rb +11 -0
  64. data/lib/cookbooks/mysql/libraries/helpers.rb +33 -0
  65. data/lib/cookbooks/mysql/metadata.rb +140 -0
  66. data/lib/cookbooks/mysql/recipes/client.rb +59 -0
  67. data/lib/cookbooks/mysql/recipes/default.rb +20 -0
  68. data/lib/cookbooks/mysql/recipes/ruby.rb +36 -0
  69. data/lib/cookbooks/mysql/recipes/server.rb +216 -0
  70. data/lib/cookbooks/mysql/recipes/server_ec2.rb +51 -0
  71. data/lib/cookbooks/mysql/templates/default/debian.cnf.erb +12 -0
  72. data/lib/cookbooks/mysql/templates/default/grants.sql.erb +15 -0
  73. data/lib/cookbooks/mysql/templates/default/my.cnf.erb +211 -0
  74. data/lib/cookbooks/mysql/templates/default/mysql-server.seed.erb +10 -0
  75. data/lib/cookbooks/mysql/templates/default/port_mysql.erb +3 -0
  76. data/lib/cookbooks/mysql/templates/windows/my.cnf.erb +61 -0
  77. data/lib/cookbooks/mysql/test/features/query_database.feature +26 -0
  78. data/lib/cookbooks/mysql/test/features/step_definitions/mysql_steps.rb +47 -0
  79. data/lib/cookbooks/mysql/test/features/support/env.rb +3 -0
  80. data/lib/cookbooks/mysql/test/features/support/mysql_helpers.rb +51 -0
  81. data/lib/cookbooks/mysql/test/kitchen/Kitchenfile +5 -0
  82. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/.gitignore +1 -0
  83. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/README.md +63 -0
  84. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/attributes/default.rb +27 -0
  85. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/metadata.rb +10 -0
  86. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/recipes/client.rb +20 -0
  87. data/lib/cookbooks/mysql/test/kitchen/cookbooks/mysql_test/recipes/server.rb +72 -0
  88. data/lib/cookbooks/openssl/CHANGELOG.md +0 -0
  89. data/lib/cookbooks/openssl/CONTRIBUTING +29 -0
  90. data/lib/cookbooks/openssl/LICENSE +201 -0
  91. data/lib/cookbooks/openssl/README.md +37 -0
  92. data/lib/cookbooks/openssl/libraries/secure_password.rb +37 -0
  93. data/lib/cookbooks/openssl/metadata.rb +8 -0
  94. data/lib/cookbooks/openssl/recipes/default.rb +19 -0
  95. data/lib/cookbooks/postgresql/CHANGELOG.md +35 -0
  96. data/lib/cookbooks/postgresql/CONTRIBUTING +29 -0
  97. data/lib/cookbooks/postgresql/LICENSE +201 -0
  98. data/lib/cookbooks/postgresql/README.md +148 -0
  99. data/lib/cookbooks/postgresql/attributes/default.rb +103 -0
  100. data/lib/cookbooks/postgresql/metadata.rb +21 -0
  101. data/lib/cookbooks/postgresql/recipes/client.rb +26 -0
  102. data/lib/cookbooks/postgresql/recipes/default.rb +20 -0
  103. data/lib/cookbooks/postgresql/recipes/ruby.rb +40 -0
  104. data/lib/cookbooks/postgresql/recipes/server.rb +64 -0
  105. data/lib/cookbooks/postgresql/recipes/server_debian.rb +64 -0
  106. data/lib/cookbooks/postgresql/recipes/server_redhat.rb +77 -0
  107. data/lib/cookbooks/postgresql/templates/default/debian.postgresql.conf.erb +499 -0
  108. data/lib/cookbooks/postgresql/templates/default/pg_hba.conf.erb +83 -0
  109. data/lib/cookbooks/postgresql/templates/default/redhat.postgresql.conf.erb +501 -0
  110. data/lib/cookbooks/sqlite/.gitignore +4 -0
  111. data/lib/cookbooks/sqlite/CHANGELOG.md +3 -0
  112. data/lib/cookbooks/sqlite/CONTRIBUTING +29 -0
  113. data/lib/cookbooks/sqlite/Gemfile +2 -0
  114. data/lib/cookbooks/sqlite/LICENSE +201 -0
  115. data/lib/cookbooks/sqlite/README.md +36 -0
  116. data/lib/cookbooks/sqlite/metadata.rb +12 -0
  117. data/lib/cookbooks/sqlite/recipes/default.rb +30 -0
  118. data/lib/cookbooks/sqlite/test/kitchen/Kitchenfile +1 -0
  119. data/lib/cookbooks/xfs/CHANGELOG.md +0 -0
  120. data/lib/cookbooks/xfs/CONTRIBUTING +29 -0
  121. data/lib/cookbooks/xfs/LICENSE +201 -0
  122. data/lib/cookbooks/xfs/README.md +30 -0
  123. data/lib/cookbooks/xfs/metadata.rb +12 -0
  124. data/lib/cookbooks/xfs/recipes/default.rb +26 -0
  125. data/lib/server_maint/version.rb +1 -1
  126. metadata +127 -4
@@ -0,0 +1,204 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Author:: AJ Christensen (<aj@opscode.com>)
4
+ # Cookbook Name:: database
5
+ # Recipe:: ebs_volume
6
+ #
7
+ # Copyright 2009-2010, Opscode, Inc.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ #
21
+
22
+ if node[:ec2]
23
+ include_recipe "aws"
24
+ include_recipe "xfs"
25
+
26
+ begin
27
+ aws = Chef::DataBagItem.load(:aws, :main)
28
+ Chef::Log.info("Loaded AWS information from DataBagItem aws[#{aws['id']}]")
29
+ rescue
30
+ Chef::Log.fatal("Could not find the 'main' item in the 'aws' data bag")
31
+ raise
32
+ end
33
+
34
+ ebs_vol_dev = node['mysql']['ebs_vol_dev']
35
+ if (platform?("ubuntu") && node['platform_version'].to_f >= 11.04)
36
+ ebs_vol_dev_mount = ebs_vol_dev.sub(/^\/dev\/sd/, "/dev/xvd")
37
+ else
38
+ ebs_vol_dev_mount = ebs_vol_dev
39
+ end
40
+ ebs_vol_id = String.new
41
+ db_type = String.new
42
+ db_role = String.new
43
+ master_role = String.new
44
+ slave_role = String.new
45
+ root_pw = String.new
46
+ snapshots_to_keep = String.new
47
+ snapshot_cron_schedule = "00 * * * *" # default to hourly snapshots
48
+
49
+ search(:apps) do |app|
50
+ if (app["database_master_role"] & node.run_list.roles).length == 1 || (app["database_slave_role"] & node.run_list.roles).length == 1
51
+ master_role = app["database_master_role"] & node.run_list.roles
52
+ slave_role = app["database_slave_role"] & node.run_list.roles
53
+ root_pw = app["mysql_root_password"][node.chef_environment]
54
+ snapshots_to_keep = app["snapshots_to_keep"][node.chef_environment]
55
+ snapshot_cron_schedule = app["snapshot_cron_schedule"][node.chef_environment] if app["snapshot_cron_schedule"] && app["snapshot_cron_schedule"][node.chef_environment]
56
+
57
+ if (master_role & node.run_list.roles).length == 1
58
+ db_type = "master"
59
+ db_role = RUBY_VERSION.to_f <= 1.8 ? master_role : master_role.join
60
+ elsif (slave_role & node.run_list.roles).length == 1
61
+ db_type = "slave"
62
+ db_role = RUBY_VERSION.to_f <= 1.8 ? slave_role : slave_role.join
63
+ end
64
+
65
+ Chef::Log.info "database::ebs_volume - db_role: #{db_role} db_type: #{db_type}"
66
+ end
67
+ end
68
+
69
+ begin
70
+ ebs_info = Chef::DataBagItem.load(:aws, "ebs_#{db_role}_#{node.chef_environment}")
71
+ Chef::Log.info("Loaded #{ebs_info['volume_id']} from DataBagItem aws[#{ebs_info['id']}]")
72
+ rescue
73
+ Chef::Log.warn("Could not find the 'ebs_#{db_role}_#{node.chef_environment}' item in the 'aws' data bag")
74
+ ebs_info = Hash.new
75
+ end
76
+
77
+ begin
78
+ master_info = Chef::DataBagItem.load(:aws, "ebs_#{master_role}_#{node.chef_environment}")
79
+ Chef::Log.info "Loaded #{master_info['volume_id']} from DataBagItem aws[#{master_info['id']}]"
80
+ rescue
81
+ Chef::Application.fatal! "Could not load replication masters snapshot details", -41 if db_type == "slave"
82
+ end
83
+
84
+ ruby_block "store_#{db_role}_#{node.chef_environment}_volid" do
85
+ block do
86
+ ebs_vol_id = node[:aws][:ebs_volume]["#{db_role}_#{node.chef_environment}"][:volume_id]
87
+
88
+ unless ebs_info['volume_id']
89
+ item = {
90
+ "id" => "ebs_#{db_role}_#{node.chef_environment}",
91
+ "volume_id" => ebs_vol_id
92
+ }
93
+ Chef::Log.info "Storing volume_id #{item.inspect}"
94
+ databag_item = Chef::DataBagItem.new
95
+ databag_item.data_bag("aws")
96
+ databag_item.raw_data = item
97
+ databag_item.save
98
+ Chef::Log.info("Created #{item['id']} in #{databag_item.data_bag}")
99
+ end
100
+ end
101
+ action :nothing
102
+ end
103
+
104
+ aws_ebs_volume "#{db_role}_#{node.chef_environment}" do
105
+ aws_access_key aws['aws_access_key_id']
106
+ aws_secret_access_key aws['aws_secret_access_key']
107
+ size 50
108
+ device ebs_vol_dev
109
+ snapshots_to_keep snapshots_to_keep
110
+ case db_type
111
+ when "master"
112
+ if ebs_info['volume_id'] && ebs_info['volume_id'] =~ /vol/
113
+ volume_id ebs_info['volume_id']
114
+ action :attach
115
+ elsif ebs_info['volume_id'] && ebs_info['volume_id'] =~ /snap/
116
+ snapshot_id ebs_info['volume_id']
117
+ action [ :create, :attach ]
118
+ else
119
+ action [ :create, :attach ]
120
+ end
121
+ notifies :create, resources(:ruby_block => "store_#{db_role}_#{node.chef_environment}_volid")
122
+ when "slave"
123
+ if master_info['volume_id']
124
+ snapshot_id master_info['volume_id']
125
+ action [:create, :attach]
126
+ else
127
+ Chef::Log.warn("Couldn't detect snapshot ID.")
128
+ action :nothing
129
+ end
130
+ end
131
+ provider "aws_ebs_volume"
132
+ end
133
+
134
+ if db_type == "master"
135
+ Chef::Log.info "Setting up templates for chef-solo snapshots"
136
+ template "/etc/chef/chef-solo-database-snapshot.rb" do
137
+ source "chef-solo-database-snapshot.rb.erb"
138
+ variables :cookbook_path => Chef::Config[:cookbook_path]
139
+ owner "root"
140
+ group "root"
141
+ mode 0600
142
+ end
143
+
144
+ template "/etc/chef/chef-solo-database-snapshot.json" do
145
+ source "chef-solo-database-snapshot.json.erb"
146
+ variables(
147
+ :output => {
148
+ 'db_snapshot' => {
149
+ 'ebs_vol_dev' => node.mysql.ec2_path,
150
+ 'db_role' => db_role,
151
+ 'app_environment' => node.chef_environment,
152
+ 'username' => 'root',
153
+ 'password' => root_pw,
154
+ 'aws_access_key_id' => aws['aws_access_key_id'],
155
+ 'aws_secret_access_key' => aws['aws_secret_access_key'],
156
+ 'snapshots_to_keep' => snapshots_to_keep,
157
+ 'volume_id' => ebs_info['volume_id']
158
+ },
159
+ 'run_list' => [
160
+ "recipe[database::snapshot]"
161
+ ]
162
+ }
163
+ )
164
+ owner "root"
165
+ group "root"
166
+ mode 0600
167
+ end
168
+
169
+ template "/etc/cron.d/chef-solo-database-snapshot" do
170
+ source "chef-solo-database-snapshot.cron.erb"
171
+ variables(
172
+ :json_attribs => "/etc/chef/chef-solo-database-snapshot.json",
173
+ :config_file => "/etc/chef/chef-solo-database-snapshot.rb",
174
+ :schedule => snapshot_cron_schedule
175
+ )
176
+ owner "root"
177
+ group "root"
178
+ mode 0600
179
+ end
180
+ end
181
+
182
+ execute "mkfs.xfs #{ebs_vol_dev_mount}" do
183
+ only_if "xfs_admin -l #{ebs_vol_dev_mount} 2>&1 | grep -qx 'xfs_admin: #{ebs_vol_dev_mount} is not a valid XFS filesystem (unexpected SB magic number 0x00000000)'"
184
+ end
185
+
186
+ %w{ec2_path data_dir}.each do |dir|
187
+ directory node['mysql'][dir] do
188
+ mode 0755
189
+ end
190
+ end
191
+
192
+ mount node['mysql']['ec2_path'] do
193
+ device ebs_vol_dev_mount
194
+ fstype "xfs"
195
+ action :mount
196
+ end
197
+
198
+ mount node['mysql']['data_dir'] do
199
+ device node['mysql']['ec2_path']
200
+ fstype "none"
201
+ options "bind,rw"
202
+ action :mount
203
+ end
204
+ end
@@ -0,0 +1,78 @@
1
+ #
2
+ # Author:: Joshua Timberman (<joshua@opscode.com>)
3
+ # Cookbook Name:: database
4
+ # Recipe:: master
5
+ #
6
+ # Copyright 2009-2010, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ # This is potentially destructive to the nodes mysql password attributes, since
21
+ # we iterate over all the app databags. If this database server provides
22
+ # databases for multiple applications, the last app found in the databags
23
+ # will win out, so make sure the databags have the same passwords set for
24
+ # the root, repl, and debian-sys-maint users.
25
+ #
26
+
27
+ db_info = Hash.new
28
+ root_pw = String.new
29
+
30
+ search(:apps) do |app|
31
+ (app['database_master_role'] & node.run_list.roles).each do |dbm_role|
32
+ %w{ root repl debian }.each do |user|
33
+ user_pw = app["mysql_#{user}_password"]
34
+ if !user_pw.nil? and user_pw[node.chef_environment]
35
+ Chef::Log.debug("Saving password for #{user} as node attribute node['mysql']['server_#{user}_password'")
36
+ node.set['mysql']["server_#{user}_password"] = user_pw[node.chef_environment]
37
+ node.save
38
+ else
39
+ log "A password for MySQL user #{user} was not found in DataBag 'apps' item '#{app["id"]}' for environment ' for #{node.chef_environment}'." do
40
+ level :warn
41
+ end
42
+ log "A random password will be generated by the mysql cookbook and added as 'node.mysql.server_#{user}_password'. Edit the DataBag item to ensure it is set correctly on new nodes" do
43
+ level :warn
44
+ end
45
+ end
46
+ end
47
+ app['databases'].each do |env,db|
48
+ db_info[env] = db
49
+ end
50
+ end
51
+ end
52
+
53
+ include_recipe "mysql::server"
54
+
55
+ connection_info = {:host => "localhost", :username => 'root', :password => node['mysql']['server_root_password']}
56
+
57
+ search(:apps) do |app|
58
+ (app['database_master_role'] & node.run_list.roles).each do |dbm_role|
59
+ app['databases'].each do |env,db|
60
+ if env =~ /#{node.chef_environment}/
61
+ mysql_database "create #{db['database']}" do
62
+ database_name db['database']
63
+ connection connection_info
64
+ action :create
65
+ end
66
+ %W{ % #{node['fqdn']} localhost }.each do |h|
67
+ mysql_database_user db['username'] do
68
+ connection connection_info
69
+ password db['password']
70
+ database_name db['database']
71
+ host h
72
+ action :grant
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Author:: Jesse Howarth (<him@jessehowarth.com>)
3
+ #
4
+ # Copyright:: Copyright (c) 2012, Opscode, Inc. (<legal@opscode.com>)
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ include_recipe "mysql::ruby"
@@ -0,0 +1,20 @@
1
+ #
2
+ # Author:: Jesse Howarth (<him@jessehowarth.com>)
3
+ #
4
+ # Copyright:: Copyright (c) 2012, Opscode, Inc. (<legal@opscode.com>)
5
+ # License:: Apache License, Version 2.0
6
+ #
7
+ # Licensed under the Apache License, Version 2.0 (the "License");
8
+ # you may not use this file except in compliance with the License.
9
+ # You may obtain a copy of the License at
10
+ #
11
+ # http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+
20
+ include_recipe "postgresql::ruby"
@@ -0,0 +1,62 @@
1
+ #
2
+ # Author:: AJ Christensen (<aj@opscode.com>)
3
+ # Cookbook Name:: database
4
+ # Recipe:: snapshot
5
+ #
6
+ # Copyright 2009-2010, Opscode, Inc.
7
+ #
8
+ # Licensed under the Apache License, Version 2.0 (the "License");
9
+ # you may not use this file except in compliance with the License.
10
+ # You may obtain a copy of the License at
11
+ #
12
+ # http://www.apache.org/licenses/LICENSE-2.0
13
+ #
14
+ # Unless required by applicable law or agreed to in writing, software
15
+ # distributed under the License is distributed on an "AS IS" BASIS,
16
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ # See the License for the specific language governing permissions and
18
+ # limitations under the License.
19
+ #
20
+ include_recipe "aws"
21
+ include_recipe "xfs"
22
+
23
+ %w{ebs_vol_dev db_role app_environment username password aws_access_key_id aws_secret_access_key snapshots_to_keep volume_id}.collect do |key|
24
+ Chef::Application.fatal!("Required db_snapshot configuration #{key} not found.", -47) unless node.db_snapshot.has_key? key
25
+ end
26
+
27
+ connection_info = {:host => "localhost", :username => node.db_snapshot.username, :password => node.db_snapshot.password}
28
+
29
+ mysql_database "locking tables for #{node.db_snapshot.app_environment}" do
30
+ connection connection_info
31
+ sql "flush tables with read lock"
32
+ action :query
33
+ end
34
+
35
+ execute "xfs freeze" do
36
+ command "xfs_freeze -f #{node.db_snapshot.ebs_vol_dev}"
37
+ end
38
+
39
+ aws_ebs_volume "#{node.db_snapshot.db_role.first}_#{node.db_snapshot.app_environment}" do
40
+ aws_access_key node.db_snapshot.aws_access_key_id
41
+ aws_secret_access_key node.db_snapshot.aws_secret_access_key
42
+ size 50
43
+ device node.db_snapshot.ebs_vol_dev
44
+ snapshots_to_keep node.db_snapshot.snapshots_to_keep
45
+ action :snapshot
46
+ volume_id node.db_snapshot.volume_id
47
+ ignore_failure true # if this fails, continue to unfreeze and unlock
48
+ end
49
+
50
+ execute "xfs unfreeze" do
51
+ command "xfs_freeze -u #{node.db_snapshot.ebs_vol_dev}"
52
+ end
53
+
54
+ mysql_database "unflushing tables for #{node.db_snapshot.app_environment}" do
55
+ connection connection_info
56
+ sql "unlock tables"
57
+ action :query
58
+ end
59
+
60
+ aws_ebs_volume "#{node.db_snapshot.db_role.first}_#{node.db_snapshot.app_environment}" do
61
+ action :prune
62
+ end
@@ -0,0 +1,8 @@
1
+ # Generated by Chef. Local modifications will be overwritten.
2
+ <% @db_info.each do |env,db| -%>
3
+ # Privileges for databases in <%= env %>
4
+ GRANT ALL ON <%= db['database'] %>.* TO '<%= db['username'] %>'@'localhost' IDENTIFIED BY '<%= db['password'] %>';
5
+ GRANT ALL ON <%= db['database'] %>.* TO '<%= db['username'] %>'@'<%= node['fqdn'] %>' IDENTIFIED BY '<%= db['password'] %>';
6
+ GRANT ALL ON <%= db['database'] %>.* TO '<%= db['username'] %>'@'%' IDENTIFIED BY '<%= db['password'] %>';
7
+ <% end -%>
8
+ flush privileges;
@@ -0,0 +1,3 @@
1
+ AWS_ACCESS_KEY_ID=<%= @access_key %>
2
+ AWS_SECRET_ACCESS_KEY=<%= @secret_key %>
3
+ BUCKET_BASE_NAME=db-backups
@@ -0,0 +1,6 @@
1
+ # Managed by Chef
2
+ # m h dom mon dow command
3
+ # Keep 1 day of hourly snapshots
4
+ PATH=/usr/sbin:/usr/bin:/sbin:/bin
5
+ <% cs = "chef-solo -j #{@json_attribs} -c #{@config_file}" %>
6
+ <%= @schedule %> root <%= cs %>
@@ -0,0 +1 @@
1
+ <%= require 'json'; JSON.pretty_generate(@output) %>
@@ -0,0 +1,6 @@
1
+ executable_path ENV['PATH'] ? ENV['PATH'].split(File::PATH_SEPARATOR) : []
2
+ <% if @cookbook_path.is_a? Array %>
3
+ cookbook_path [ <%= @cookbook_path.collect { |cb| "\"#{cb}\""}.join(", ") -%> ]
4
+ <% else %>
5
+ cookbook_path "<%= @cookbook_path -%>"
6
+ <% end %>
@@ -0,0 +1,2 @@
1
+ # Chef Name: ebs_db_backup
2
+ 15 0 * * * root /usr/local/bin/db-backup.sh
@@ -0,0 +1,8 @@
1
+ #!/bin/bash
2
+ #
3
+ # Back up a MySQL database via EBS snapshot
4
+
5
+ . /mnt/aws-config/config
6
+
7
+ /opt/ec2_mysql/bin/ec2_mysql -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY -p '<%= @mysql_root_passwd %>' -k 5 master
8
+ echo "done"
@@ -0,0 +1,10 @@
1
+ #!/bin/bash
2
+ #
3
+ # Restore a MySQL database from EBS
4
+
5
+ mkdir -p /mnt/restore
6
+
7
+ . /mnt/aws-config/config
8
+
9
+ /opt/ec2_mysql/bin/ec2_mysql -a $AWS_ACCESS_KEY_ID -s $AWS_SECRET_ACCESS_KEY -p '<%= @mysql_root_password %>' -v '<%= @ebs_vol_id %>' -m /mnt/restore -d <%= @mysql_device %> -r <%= @mysql_device %> -l debug -n slave
10
+ echo "done"
@@ -0,0 +1,27 @@
1
+ [default]
2
+ access_key = <%= @aws['aws_access_key_id'] %>
3
+ acl_public = False
4
+ bucket_location = US
5
+ debug_syncmatch = False
6
+ default_mime_type = binary/octet-stream
7
+ delete_removed = False
8
+ dry_run = False
9
+ encrypt = False
10
+ force = False
11
+ gpg_command = /usr/bin/gpg
12
+ gpg_decrypt = %(gpg_command)s -d --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
13
+ gpg_encrypt = %(gpg_command)s -c --verbose --no-use-agent --batch --yes --passphrase-fd %(passphrase_fd)s -o %(output_file)s %(input_file)s
14
+ gpg_passphrase =
15
+ guess_mime_type = False
16
+ host_base = s3.amazonaws.com
17
+ host_bucket = %(bucket)s.s3.amazonaws.com
18
+ human_readable_sizes = False
19
+ preserve_attrs = True
20
+ proxy_host =
21
+ proxy_port = 0
22
+ recv_chunk = 4096
23
+ secret_key = <%= @aws['aws_secret_access_key'] %>
24
+ send_chunk = 4096
25
+ simpledb_host = sdb.amazonaws.com
26
+ use_https = True
27
+ verbosity = WARNING
@@ -0,0 +1,5 @@
1
+ .bundle
2
+ .cache
3
+ .kitchen
4
+ bin
5
+ *.sw[op]
@@ -0,0 +1,86 @@
1
+ ## v1.3.0:
2
+
3
+ **Important note for this release**
4
+
5
+ This version no longer installs Ruby bindings in the client recipe by
6
+ default. Use the ruby recipe if you'd like the RubyGem. If you'd like
7
+ packages from your distribution, use them in your application's
8
+ specific cookbook/recipe, or modify the client packages attribute.
9
+ This resolves the following tickets:
10
+
11
+ * COOK-932
12
+ * COOK-1009
13
+ * COOK-1384
14
+
15
+ Additionally, this cookbook now has tests (COOK-1439) for use under
16
+ test-kitchen.
17
+
18
+ The following issues are also addressed in this release.
19
+
20
+ * [COOK-1443] - MySQL (>= 5.1.24) does not support `innodb_flush_method`
21
+ = fdatasync
22
+ * [COOK-1175] - Add Mac OS X support
23
+ * [COOK-1289] - handle additional tunable attributes
24
+ * [COOK-1305] - add auto-increment-increment and auto-increment-offset
25
+ attributes
26
+ * [COOK-1397] - make the port an attribute
27
+ * [COOK-1439] - Add MySQL cookbook tests for test-kitchen support
28
+ * [COOK-1236] - Move package names into attributes to allow percona to
29
+ free-ride
30
+ * [COOK-934] - remove deprecated mysql/libraries/database.rb, use the
31
+ database cookbook instead.
32
+ * [COOK-1475] - fix restart on config change
33
+
34
+ ## v1.2.6:
35
+
36
+ * [COOK-1113] - Use an attribute to determine if upstart is used
37
+ * [COOK-1121] - Add support for Windows
38
+ * [COOK-1140] - Fix conf.d on Debian
39
+ * [COOK-1151] - Fix server_ec2 handling /var/lib/mysql bind mount
40
+ * [COOK-1321] - Document setting password attributes for solo
41
+
42
+ ## v1.2.4
43
+
44
+ * [COOK-992] - fix FATAL nameerror
45
+ * [COOK-827] - `mysql:server_ec2` recipe can't mount `data_dir`
46
+ * [COOK-945] - FreeBSD support
47
+
48
+ ## v1.2.2
49
+
50
+ * [COOK-826] mysql::server recipe doesn't quote password string
51
+ * [COOK-834] Add 'scientific' and 'amazon' platforms to mysql cookbook
52
+
53
+ ## v1.2.1
54
+
55
+ * [COOK-644] Mysql client cookbook 'package missing' error message is confusing
56
+ * [COOK-645] RHEL6/CentOS6 - mysql cookbook contains 'skip-federated' directive which is unsupported on MySQL 5.1
57
+
58
+ ## v1.2.0
59
+
60
+ * [COOK-684] remove mysql_database LWRP
61
+
62
+ ## v1.0.8:
63
+
64
+ * [COOK-633] ensure "cloud" attribute is available
65
+
66
+ ## v1.0.7:
67
+
68
+ * [COOK-614] expose all mysql tunable settings in config
69
+ * [COOK-617] bind to private IP if available
70
+
71
+ ## v1.0.6:
72
+
73
+ * [COOK-605] install mysql-client package on ubuntu/debian
74
+
75
+ ## v1.0.5:
76
+
77
+ * [COOK-465] allow optional remote root connections to mysql
78
+ * [COOK-455] improve platform version handling
79
+ * externalize conf_dir attribute for easier cross platform support
80
+ * change datadir attribute to data_dir for consistency
81
+
82
+ ## v1.0.4:
83
+
84
+ * fix regressions on debian platform
85
+ * [COOK-578] wrap root password in quotes
86
+ * [COOK-562] expose all tunables in my.cnf
@@ -0,0 +1,29 @@
1
+ If you would like to contribute, please open a ticket in JIRA:
2
+
3
+ * http://tickets.opscode.com
4
+
5
+ Create the ticket in the COOK project and use the cookbook name as the
6
+ component.
7
+
8
+ For all code contributions, we ask that contributors sign a
9
+ contributor license agreement (CLA). Instructions may be found here:
10
+
11
+ * http://wiki.opscode.com/display/chef/How+to+Contribute
12
+
13
+ When contributing changes to individual cookbooks, please do not
14
+ modify the version number in the metadata.rb. Also please do not
15
+ update the CHANGELOG.md for a new version. Not all changes to a
16
+ cookbook may be merged and released in the same versions. Opscode will
17
+ handle the version updates during the release process. You are welcome
18
+ to correct typos or otherwise make updates to documentation in the
19
+ README.
20
+
21
+ If a contribution adds new platforms or platform versions, indicate
22
+ such in the body of the commit message(s), and update the relevant
23
+ COOK ticket. When writing commit messages, it is helpful for others if
24
+ you indicate the COOK ticket. For example:
25
+
26
+ git commit -m '[COOK-1041] Updated pool resource to correctly delete.'
27
+
28
+ In the ticket itself, it is also helpful if you include log output of
29
+ a successful Chef run, but this is not absolutely required.
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ gem 'cucumber', '~> 1.1.8'
4
+ gem 'minitest', '~> 3.0.0'
5
+
6
+ group :kitchen do
7
+ gem 'test-kitchen'
8
+ end