Logrotate App


Back to resource list

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

The resource takes the following properties:


pathString, ArraynilSpecifies a single path (string) or multiple paths (array) that should have logrotation stanzas created in the config file.
cookbookStringlogrotateThe cookbook that continues the template for logrotate_app config resources.
template_nameStringlogrotateSets the template source.
template_modeStringlogrotateThe mode to create the logrotate template.
template_ownerStringlogrotateThe owner of the logrotate template.
template_groupStringlogrotateThe group of the logrotate template.
frequencyStringlogrotateSets the frequency for rotation. Valid values are: hourly, daily, weekly, monthly, yearly, see the logrotate man page for more information.
optionsStringlogrotateAny 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 the above 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'

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/ ] || kill -USR1 `cat /var/run/`'

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