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

RSS

fb_logrotate (1) Versions 0.0.1

Installs/Configures logrotate

Berkshelf
Policyfile
Knife
cookbook 'fb_logrotate', '~> 0.0.1'
cookbook 'fb_logrotate', '~> 0.0.1', :supermarket
knife supermarket install fb_logrotate
knife supermarket download fb_logrotate
README
Dependencies
Quality 50%

fb_logrotate Cookbook

This configures the logrotate package with common configs that go on every server, but do not necessarily have a corresponding cookbook they should go in.

If the system that this cookbook is run on is MAC OS X, it will populate all the files outlined in the configration in the newsylog.d format.

See http://www.freebsd.org/cgi/man.cgi?query=newsyslog.conf for more details about the newsyslog feature.

Requirements

Attributes

  • node['fb_logrotate']['globals'][$CONFIG]
  • node['fb_logrotate']['configs'][$NAME]
  • node['fb_logrotate']['add_locking_to_logrotate']
  • node['fb_logrotate']['debug_log']

Usage

The configuration of logrotate via Chef is best explained by looking directly at attributes/default.rb of this cookbook. A summary is below.

The node['fb_logrotate']['configs'] hash contains one entry per logrotate configuration block.

To rotate a new set of logs, add a new entry to this hash, like so:

node.default['fb_logrotate']['configs']['myapp'] = {
  'files' => ['/var/log/myapp.log'],
  'overrides' => {
    'missingok' => true,
  },
}

The following defaults are provided:

Linux:

  • daily
  • rotate 14
  • maxage 14
  • compress
  • compresscmd /usr/bin/pigz (except on CentOS 6, where pigz is not available)
  • copytruncate
  • notifempty
  • missingok

MAC OS (BSD):

  • rotate 14
  • mode 644
  • size 102400
  • when *
  • flags J

Of these compresscmd, rotate and maxage defaults are specified via node['fb_logrotate']['globals']['...']

These maybe overridden by recipes for a particular platform.

  • compresscmd - Specifies which command to use to compress log files. The default is pigz, except for CentOS 6 where pigz is not available. You can specify this by node['fb_logrotate']['globals']['compresscmd']
  • rotate - Log files are rotated count times before being removed or mailed to the address specified in a mail directive. If count is 0, old versions are removed rather than rotated. You can specify this by node['fb_logrotate']['globals']['rotate']
  • maxage - Remove rotated logs older than $COUNT days. The age is only checked if the logfile is to be rotated. The files are mailed to the configured address if maillast and mail are configured. You can specify this by node['fb_logrotate']['globals']['maxage']

The following attributes are optional and not populated by default. These can be then later specified by setting the appropriate attribute and would get picked up by this logrotate recipe. * size - Log files are rotated if they grow bigger than size bytes. If size is followed by k, the size is assumed to be in kilobytes. If the M is used, the size is in megabytes, and if G is used, the size is in gigabytes. So size 100, size 100k, size 100M and size 100G are all valid. specified by node['fb_logrotate']['globals']['size'] * compressext - Specifies which extension to use on compressed logfiles, if compression is enabled. specified by node['fb_logrotate']['globals']['compressext']

Overrides accepts the following booleans:

  • copytruncate
  • ifempty
  • nocompress
  • missingok
  • sharedscripts
  • nomail
  • noolddir
  • nocopytruncate
  • dateext
  • nodateext
  • nocreate

Simply set them to true in your override hash to enable them. The following additional overrides are accepted and require values:

  • rotation # this is how you specify daily/weekly/monthly/yearly
  • rotate # will be set to 14 if you choose daily but don't specify this
  • size
  • minsize
  • create
  • postrotate
  • prerotate
  • preremove
  • olddir
  • su
  • compressoptions
  • dateformat
  • owner (mac os x, BSD - only)
  • pid_file (mac os x, BSD - only)
  • sig_num (mac os x, BSD - only)

Please don't turn off compression unless you know what you are doing, and please specify only the minimum of overrides.

IMPORTANT NOTE: No syntax checking is done for the logrotate configs. You are responsible for ensuring you are entering correct, typo-free data. Please make sure that you use a valid options from logrotate(8) otherwise warning message will be issued.

Let's go ahead and now take a look at a full sample structure, and the resulting config file it would generate:

node.default['fb_logrotate']['configs']['mcproxy'] = {
  'files' => [
    "/var/log/mcproxy-tao.log",
    "/var/log/mcproxy-tao2.log",
    "/var/log/mcproxy.init.log",
    "/var/log/mcproxy.tao.log",
    "/var/log/mcproxy.tao2.log",
    "/var/log/mcproxy2.tao.log",
    "/var/log/mcproxy.log.global",
    "/var/log/mcproxy.log",
    "/var/log/mcproxy.global",
    "/var/log/mcproxy.regional.log",
  ],
  'overrides' => {
    'size' => '50M',
    'copytruncate' => true,
    'missingok' => true,
    'sharedscripts' => true,
  },
}

From the above structure, the following config file is generated:

/var/log/mcproxy-tao.log /var/log/mcproxy-tao2.log /var/log/mcproxy.init.log /var/log/mcproxy.tao.log /var/log/mcproxy.tao2.log /var/log/mcproxy2.tao.log /var/log/mcproxy.log.global /var/log/mcproxy.log /var/log/mcproxy.global /var/log/mcproxy.regional.log {
  size 50M
  copytruncate
  missingok
  sharedscripts
}

Another example that shows the newsyslog.d conf file as generated on a MAC machine using the following sample strucutre:

node.default['fb_logrotate']['configs']['mylogfile'] = {
  'files' => ['/var/log/mylogfile'],
  'overrides' => {
    'size' => '1048576', # 1GB
  },
}

From the above structure, the a config file (/etc/newsyslog.d/fb_bsd_newsyslog.conf) is generated with output:

# logfilename                       [owner:group]        mode count size     when  flags [/pid_file] [sig_num]
/var/log/messages                                        644  5     1024     24    J
/var/log/mylogfile                                       644  14    1048576  *     J
/var/log/secure                                          644  14    1048576  *     J

Note that by default rotations for /var/log/messages and /var/log/secure are auto-populated into the newsyslog.d conf file.

add_locking_to_logrotate

The node['fb_logrotate']['add_locking_to_logrotate'] feature will overwrite the cronjob for logrotate (/etc/cron.daily/logrotate) with one that wraps the call to logrotate in a flock call to prevent logrotate runs from stepping on each other. It also adds low priority nice and ionice to the logrotate process. This can be very useful, but be aware you are overwriting a file from the system package.

debug_log

The node['fb_logrotate']['debug_log'] feature is disabled by default. Setting this to true will cause verbose logrotate output to be captured in /tmp/logrotate.debug.log. This option is only available if the add_locking_to_logrotate feature is also enabled.

size and logrotate run frequency

Note that the use of the size property together with logrotate runs that are more frequent than daily will result in duplicate log entry errors in logrotate because the default dateformat is -%Y%m%d. To handle this, specify a more granular dateformat, e.g. -%Y%m%d%H.

Dependent cookbooks

fb_helpers >= 0.0.0

Contingent cookbooks

There are no cookbooks that are contingent upon this one.

Collaborator Number Metric
            

0.0.1 failed this metric

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

Contributing File Metric
            

0.0.1 passed this metric

Foodcritic Metric
            

0.0.1 failed this metric

FC064: Ensure issues_url is set in metadata: fb_logrotate/metadata.rb:1
FC066: Ensure chef_version is set in metadata: fb_logrotate/metadata.rb:1
Run with Foodcritic Version 14.0.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any

No Binaries Metric
            

0.0.1 passed this metric

Publish Metric
            

0.0.1 passed this metric

Supported Platforms Metric
            

0.0.1 passed this metric

Testing File Metric
            

0.0.1 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.0.1 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