All Projects → sous-chefs → Logrotate

sous-chefs / Logrotate

Licence: apache-2.0
Development repository for the logrotate cookbook

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Logrotate

Rsyslog
Development repository for the rsyslog cookbook
Stars: ✭ 66 (-45.9%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Grafana
Development repository for the grafana cookbook
Stars: ✭ 69 (-43.44%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Java
Development repository for the java cookbook
Stars: ✭ 365 (+199.18%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Docker
Development repository for the docker cookbook
Stars: ✭ 1,253 (+927.05%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Powershell
Development repository for the powershell cookbook
Stars: ✭ 104 (-14.75%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Nginx
Development repository for the nginx cookbook
Stars: ✭ 528 (+332.79%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Openvpn
Development repository for the openvpn cookbook
Stars: ✭ 102 (-16.39%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Ruby rbenv
Development repository for the ruby_rbenv cookbook
Stars: ✭ 339 (+177.87%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Openssh
Development repository for the openssh cookbook
Stars: ✭ 108 (-11.48%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Erlang
Development repository for the erlang cookbook
Stars: ✭ 78 (-36.07%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Rvm
Development repository for the rvm cookbook
Stars: ✭ 525 (+330.33%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Git
Development repository for the git cookbook
Stars: ✭ 117 (-4.1%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Aws
Development repository for the aws cookbook
Stars: ✭ 473 (+287.7%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Iis
Development repository for the iis cookbook
Stars: ✭ 79 (-35.25%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Jenkins
Development repository for the jenkins cookbook
Stars: ✭ 416 (+240.98%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Chef Splunk
Development repository for the chef-splunk cookbook
Stars: ✭ 70 (-42.62%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Postgresql
Development repository for the postgresql cookbook
Stars: ✭ 326 (+167.21%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Mysql
Sous Chefs MySQL Cookbook
Stars: ✭ 325 (+166.39%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Php
Development repository for the php cookbook
Stars: ✭ 347 (+184.43%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource
Etcd
Development repository for the etcd cookbook
Stars: ✭ 71 (-41.8%)
Mutual labels:  hacktoberfest, chef, chef-cookbook, chef-resource

logrotate Cookbook

Cookbook Version CI State OpenCollective OpenCollective License

Manages the logrotate package and provides a resource to manage application specific logrotate configuration.

Maintainers

This cookbook is maintained by the Sous Chefs. The Sous Chefs are a community of Chef cookbook maintainers working together to maintain important cookbooks. If you’d like to know more please visit sous-chefs.org or come chat with us on the Chef Community Slack in #sous-chefs.

Requirements

Platforms

Should work on any platform that includes a 'logrotate' package and writes logrotate configuration to /etc/logrotate.d.

Tested on:

  • Ubuntu / Debian
  • CentOS
  • Amazon Linux
  • openSUSE Leap

Chef

  • Chef 12.5+

Cookbooks

  • none

Recipes

global

Generates and controls a global /etc/logrotate.conf file that will include additional files generated by the logrotate_app resource (see below). The contents of the configuration file is controlled through node attributes under node['logrotate']['global']. The default attributes are based on the configuration from the Ubuntu logrotate package.

To define a valueless directive (e.g. compress, copy) simply add an attribute named for the directive with a truthy value:

node['logrotate']['global']['compress'] = 'any value here'

Note that defining a valueless directive with a falsey value will not make it false, but will remove it:

# Removes a defaulted 'compress' directive; does not add a 'nocompress' directive.
node.override['logrotate']['global']['compress'] = false

To fully override a booleanish directive like compress, you should probably remove the positive form and add the negative form:

node.override['logrotate']['global']['compress'] = false
node.override['logrotate']['global']['nocompress'] = true

The same is true of frequency directives; to be certain the frequency directive you want is included in the global configuration, you should override the ones you don't want as false:

%w[ daily weekly yearly ].each do |freq|
  node.override['logrotate']['global'][freq] = false
end
node.override['logrotate']['global']['monthly'] = true

To define a parameter with a value (e.g. create, mail) add an attribute with the desired value:

node['logrotate']['global']['create'] = '0644 root adm'

To define a path stanza in the global configuration (generally unneeded because of the logrotate_app resource) just add an attribute with the path as the name and a hash containing directives and parameters as described above:

node['logrotate']['global']['/var/log/wtmp'] = {
  'missingok' => true,
  'monthly'   => true,
  'create'    => '0660 root utmp',
  'rotate'    => 1
}

firstaction, prerotate, postrotate, and lastaction scripts can be defined either as arrays of the lines to put in the script or multiline strings:

node['logrotate']['global']['/var/log/foo/*.log'] = {
  'missingok'  => true,
  'monthly'    => true,
  'create'     => '0660 root adm',
  'rotate'     => 1,
  'prerotate'  => ['service foo start_rotate', 'logger started foo service log rotation'],
  'postrotate' => <<-EOF
    service foo end_rotate
    logger completed foo service log rotation
  EOF
}

Resources

logrotate_app

This resource can be used to drop off customized logrotate config files on a per application basis.

The resource takes the following properties:

  • path: specifies a single path (string) or multiple paths (array) that should have logrotation stanzas created in the config file. No default, this must be specified.
  • cookbook: The cookbook that continues the template for logrotate_app config resources. By default this is logrotate. Users can provide their own template by setting this attribute to point at a different cookbook.
  • template_name: sets the template source, default is "logrotate.erb".
  • template_mode: the mode to create the logrotate template with (default: "0644")
  • template_owner: the owner of the logrotate template (default: "root")
  • template_group: the group of the logrotate template (default: "root")
  • frequency: sets the frequency for rotation. Default value is 'weekly'. Valid values are: hourly, daily, weekly, monthly, yearly, see the logrotate man page for more information. Note that usually logrotate is configured to be run by cron daily. You have to change this configuration and run logrotate hourly to be able to really rotate logs hourly. Hourly rotation requires logrotate v3.8.5 or higher.
  • options: Any logrotate configuration option that doesn't specify a value. See the logrotate(8) manual page of v3.9.2 or earlier for details.

In addition to these properties, any logrotate option that takes a parameter can be used as a logrotate_app property. For example, to set the rotate option you can use a resource declaration such as:

logrotate_app 'tomcat-myapp' do
  path      '/var/log/tomcat/myapp.log'
  frequency 'daily'
  rotate    30
  create    '644 root adm'
end

Also, any logrotate option that takes one of scripts names (firstaction, prerotate, postrotate, and lastaction) can be used. Script body should be passed as value of this option. For example, nginx logrotation with postrotate:

logrotate_app 'nginx' do
  path      '/var/log/nginx/*.log'
  frequency 'daily'
  options %w(missingok compress delaycompress notifempty dateext dateyesterday nomail sharedscripts)
  rotate 365
  create '640 www-data www-data'
  dateformat '.%Y-%m-%d'
  maxage 365
  postrotate '[ ! -f /var/run/nginx.pid ] || kill -USR1 `cat /var/run/nginx.pid`'
end

See the logrotate(8) manual page of v3.9.2 or earlier for the list of available options.

Usage

The default recipe will ensure logrotate is always up to date.

To create application specific logrotate configs, use the logrotate_app resource. For example, to rotate logs for a tomcat application named myapp that writes its log file to /var/log/tomcat/myapp.log:

logrotate_app 'tomcat-myapp' do
  path      '/var/log/tomcat/myapp.log'
  frequency 'daily'
  rotate    30
  create    '644 root adm'
end

To rotate multiple logfile paths, specify the path as an array:

logrotate_app 'tomcat-myapp' do
  path      ['/var/log/tomcat/myapp.log', '/opt/local/tomcat/catalina.out']
  frequency 'daily'
  create    '644 root adm'
  rotate    7
end

To specify which logrotate options, specify the options as an array:

logrotate_app 'tomcat-myapp' do
  path      '/var/log/tomcat/myapp.log'
  options   ['missingok', 'delaycompress', 'notifempty']
  frequency 'daily'
  rotate    30
  create    '644 root adm'
end

Contributors

This project exists thanks to all the people who contribute.

Backers

Thank you to all our backers!

https://opencollective.com/sous-chefs#backers

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website.

https://opencollective.com/sous-chefs/sponsor/0/website https://opencollective.com/sous-chefs/sponsor/1/website https://opencollective.com/sous-chefs/sponsor/2/website https://opencollective.com/sous-chefs/sponsor/3/website https://opencollective.com/sous-chefs/sponsor/4/website https://opencollective.com/sous-chefs/sponsor/5/website https://opencollective.com/sous-chefs/sponsor/6/website https://opencollective.com/sous-chefs/sponsor/7/website https://opencollective.com/sous-chefs/sponsor/8/website https://opencollective.com/sous-chefs/sponsor/9/website

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].