default.rb 5.02 KB
#
# Author:: Earth U (<sysadmin @ chromedia.com>)
# Cookbook Name:: cfe-mariadb
# Attributes:: default
#
# Copyright 2016, Chromedia Far East, Inc.
#
# 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.
# See the License for the specific language governing permissions and
# limitations under the License.
#

## The 'db_map' should contain this format:
# default['cfe-mariadb']['db_map'] = {
#   'example_db_name' => {
#     :db_user       => 'example_db_username',
#     :db_pass       => 'example_db_password',
#     :bak_filename  => 'example_db_name.sql',
#     :bak_maxcopies => 30
## Optional:
#     :char_set      => 'utf8',
#     :collate       => 'utf8_general_ci',
#     :bak_encrypted => false
#   }
# }
default['cfe-mariadb']['db_map'] = {}

# Make sure to set replication on only when necessary
default['cfe-mariadb']['replication'] = false

default['cfe-mariadb']['s3_region'] = 'us-east-1'
default['cfe-mariadb']['s3_bucket'] = 'example-bucket'

if node['platform'] == 'ubuntu' and node['platform_version'].to_f == 14.04
  default['cfe-mariadb']['backup']['aws_bin']       = '/usr/local/bin/aws'
  default['cfe-mariadb']['backup']['mysqldump_bin'] = '/usr/bin/mysqldump'
else
  # Haven't tested on other platforms yet, so same as above for now.
  default['cfe-mariadb']['backup']['aws_bin']       = '/usr/local/bin/aws'
  default['cfe-mariadb']['backup']['mysqldump_bin'] = '/usr/bin/mysqldump'
end
# Path to directory where the backup script should be placed.
# Uncomment to set custom locations.
#default['cfe-mariadb']['backup']['script_dir'] = ::File.join(
#  node['mariadb']['configuration']['path'], 'scripts'
#)

default['cfe-mariadb']['backup']['cron']['min']    = '0'
default['cfe-mariadb']['backup']['cron']['hour']   = '0'
default['cfe-mariadb']['backup']['cron']['day']    = '*'
default['cfe-mariadb']['backup']['cron']['mon']    = '*'
default['cfe-mariadb']['backup']['cron']['wday']   = '*'
default['cfe-mariadb']['backup']['cron']['mailto'] = "''" # Empty single quotes

# Basic options for logrotate
default['cfe-mariadb']['backup']['logrotate']['conf_dir'] = '/etc/logrotate.d'
default['cfe-mariadb']['backup']['logrotate']['options']  = %w{
  weekly
  rotate\ 12
  missingok
  compress
  notifempty
}

# Optional attributes for recipe 'reload_from_s3' only
# (Usually used during testing)
# Recommend: use EC2 instances with proper S3 access roles and 
# leave these attributes unset:
#default['cfe-mariadb']['reload']['aws_access_key_id'] = 'MYKEYID'
#default['cfe-mariadb']['reload']['aws_secret_access_key'] = 'MYSECRETKEY'

# Whether to encrypt the backup DB dumps before storing them in S3.
#   'priv_key': String. Contents of the private key file.
#
#               Used only in recipe 'reload_from_s3' if some/all DB dumps
#               to be reloaded are encrypted.
#
#               File is automatically deleted after the recipe is run.
#   'pub_key': String. Contents of the public key file.
#
#              Used by the backup script to encrypt the DB dump
#              if ':bak_encrypted' is set to true for that DB.
#
#              The key file will be stored in the same directory
#              as the script as 'pub.key'.
# NOTE:
#   Enabling encryption will result in HUGE file sizes and,
#   depending on how large a database is, can take a LOT of time
#   during the backup process. That said, it is still recommended to
#   enforce encryption on DB backups.
default['cfe-mariadb']['encrypt']['priv_key'] = nil
default['cfe-mariadb']['encrypt']['pub_key']  = nil

default['mariadb']['server_root_password']   = 'secretpassword'
default['mariadb']['mysqld']['bind_address'] = '127.0.0.1'
default['mariadb']['mysqld']['port']         = '3306'
default['mariadb']['install']['type']        = 'package'
default['mariadb']['install']['version']     = '10.0'
default['mariadb']['use_default_repository'] = true
default['mariadb']['forbid_remote_root']     = true
# io_capacity has to be roughly the IO capacity of the EC2 instance.
# buffer_pool_size can be increased to 75% (0.75) of RAM if dedicated server.
default['mariadb']['innodb']['io_capacity']      = '40'
default['mariadb']['innodb']['buffer_pool_size'] =
  ( %x(free -m).split(' ')[7].to_i * 0.5 ).round.to_s
# Set innodb_open_files value same as table_open_cache.
# But set open_files_limit as highest.
default['mariadb']['innodb']['open_files']       = '2000'
default['mariadb']['mysqld']['table_open_cache'] = '2000'
default['mariadb']['mysqld']['open_files_limit'] = '24000'

## Tip:
## For encrypted attributes like passwords,
## the following is possible in the attributes file:
##
# secret = Chef::EncryptedDataBagItem.load(
#   my_data_bag, my_secret_data_bag_item
# )
# default['cfe-mariadb']['some_prop'] = secret['db_password']