Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

Select Status

RSS

mysql_logrotate (5) Versions 0.2.0

Installs/Configures log rotation for mysql_service (mysql cookbook > 6.0)

Policyfile
Berkshelf
Knife
cookbook 'mysql_logrotate', '= 0.2.0', :supermarket
cookbook 'mysql_logrotate', '= 0.2.0'
knife supermarket install mysql_logrotate
knife supermarket download mysql_logrotate
README
Dependencies
Changelog
Quality 29%

mysql_logrotate

Workaround for mysql logrotate issues introduced with mysql cookbook V6.0.0

The problem and workaround

The old (pre V6.0.0) mysql cookbook did a default installation of mysql server,
which worked fine with logrotate.
Starting with V6.0.0, the cookbook was reconfigured to allow installing
multiple mysql instances. This broke logrotate in a couple ways:
* The default logrotate setup was still created but it was set to rotate inactive logs,
and the mysql user credentials (needed by the logrotate postrotate script to flush the logs)
were not created. (See "What about the default logrotate setup that keeps failing?" for one solution.)
* Logrotate was not set up for the new mysql server instances' logs
(with the same issue regarding credentials.)

The intention of this cookbook is to implement working log rotation for any
mysql service created by mysql cookbook (> 6.0) by copying the implementation
created for the older cookbooks where this worked.

Resources

mysql_logrotate_agent

This resource is where everything happens:
* a new database user is created to enable mysql log flushing
* the new database user credentials are saved in a file accessible to the logrotate postrotate script
* a new logrotate script is created to effect rotation

Attributes
* name, kind_of: String, name_attribute: true. This has to match the name used for the associated mysql_service instance.
* mysql_password, kind_of: String, required: true. Password for new mysql user created to enable flushing the logs in a postrotate script.
* connection, kind_of: Hash, required: true. This is the connection required to create a new mysql_database_user.
Please refer to teh database cookbook for details.

Logrotate attributes

The following attributes are passed directly to the logrotate cookbook's logrotate_app definition.
Note that some of the defaults set here are not the same as for logrotate_app,
but are intended to create a logrotate setup like the default that was created for the old (pre v6) mysql::server recipe.
See NOTES for details.

* rotate, kind_of: Integer, required: false, default: 7
* frequency, kind_of: String, required: false, default: 'daily'
* dateformat, kind_of: String, required: false, default: nil
* size, kind_of: String, required: false, default: nil
* maxsize, kind_of: String, required: false, default: nil
* logrotate_options, kind_of: Array, required: false, default: ['missingok', 'compress']

Example

  # assume you have set up a mysql_service
  mysql_service 'default' do
    ... # see mysql cookbook >= v6.0 for details
  end
  # create connection info as an external ruby has (a la the database cookbook)
  mysql_connection_info = {
    :host     => '127.0.0.1',
    :username => 'root',
    :password => 'the_default_service_root_password'
  }
  # and set up the log rotation for your mysql service
  mysql_logrotate_agent 'default' do
    mysql_password 'the_logrotation_password'
    connection mysql_connection_info
    action :create
  end

What about the default logrotate setup that keeps failing?

You can probably disable the failing default (and unused) mysql logrotate script with this:
ruby
logrotate_app 'mysql-server' do
enable false
end

(It worked for me.)

Limitations

This is for current needs so I just wrote if for Ubuntu 14.04.
If you want to use it on another platform, hopefully this will be a good headstart.

Also note that this cookbook relies heavily on implementation details of the mysql_server resource
(mysql cookbook.)

NOTES

The "old" setup was verified by running up a vagrant box and including just
* mysql cookbook 5.6.3
* logrotate cookbook

with some dummy attributes.

Key elements:

The log rotation script was created here:

-rw-r--r-- 1 root root 847 Jan 21 21:31 /etc/logrotate.d/mysql-server

# - I put everything in one block and added sharedscripts, so that mysql gets
#   flush-logs'd only once.
#   Else the binary logs would automatically increase by n times every day.
/var/log/mysql.log /var/log/mysql/mysql.log /var/log/mysql/mysql-slow.log /var/log/mysql/error.log {
  daily
  rotate 7
  missingok
  create 640 mysql adm
  compress
  sharedscripts
  postrotate
    test -x /usr/bin/mysqladmin || exit 0
    # If this fails, check debian.conf!
    MYADMIN="/usr/bin/mysqladmin --defaults-file=/etc/mysql/debian.cnf"
    if [ -z "`$MYADMIN ping 2>/dev/null`" ]; then
      # Really no mysqld or rather a missing debian-sys-maint user?
      # If this occurs and is not a error please report a bug.
      #if ps cax | grep -q mysqld; then
      if killall -q -s0 -umysql mysqld; then
        exit 1
      fi
    else
      $MYADMIN flush-logs
    fi
  endscript
}

It depends on the /etc/mysql/debian.cnf file, created here:

-rw------- 1 root root 333 Apr 13 14:27 /etc/mysql/debian.cnf

# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = AIcdhgzW37q8zOqO
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = AIcdhgzW37q8zOqO
socket   = /var/run/mysqld/mysqld.sock
basedir  = /usr

mysql privileges

It turns out that the user for the postrotate script only needs to "ping" and "flush-logs",
and you can do that with only the "usage" and "reload" privileges.

Contributions...

I whipped out this cookbook to solve a production problem, and it may not be a good universal solution.
Believe me, you will not hurt anyone's feeling to raise issues, suggest changes, submit pull requests,
fork this repo (or start over,) or otherwise come up with a better solution!

Dependent cookbooks

logrotate ~> 1.7
mysql >= 6.0
database >= 0.0.0

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

mysql_logrotate CHANGELOG

This file is used to list changes made in each version of the mysql_logrotate cookbook.

0.2.0

  • Initial commit (previous commits destroyed, deemed dangerous and misleding.)

Check the Markdown Syntax Guide for help with Markdown.

The Github Flavored Markdown page describes the differences between markdown on github and standard markdown.

Collaborator Number Metric
            

0.2.0 failed this metric

Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.

Contributing File Metric
            

0.2.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file

Foodcritic Metric
            

0.2.0 passed this metric

License Metric
            

0.2.0 failed this metric

mysql_logrotate does not have a valid open source license.
Acceptable licenses include Apache-2.0, apachev2, Apache 2.0, MIT, mit, GPL-2.0, gplv2, GNU Public License 2.0, GPL-3.0, gplv3, GNU Public License 3.0.

No Binaries Metric
            

0.2.0 passed this metric

Testing File Metric
            

0.2.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file

Version Tag Metric
            

0.2.0 failed this metric

Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number