GithubHelp home page GithubHelp logo

kamaradclimber / logrotate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sous-chefs/logrotate

0.0 2.0 0.0 141 KB

Development repository for Opscode Cookbook logrotate

Home Page: http://community.opscode.com/cookbooks/logrotate

License: Apache License 2.0

Ruby 100.00%

logrotate's Introduction

Description

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

Requirements

Should work on any platform that includes a 'logrotate' package and writes logrotate configuration to /etc/logrotate.d. Tested on Ubuntu, Debian and Red Hat/CentOS.

Recipes

logrotate::global

Generates and controls a global /etc/logrotate.conf file that will include additional files generated by the logrotate_app definition (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 overrride 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 ].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 definition) 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
}

Definitions

logrotate_app

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

The definition takes the following params:

  • 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.
  • enable: true/false, if true it will create the template in /etc/logrotate.d.
  • frequency: sets the frequency for rotation. Default value is 'weekly'. Valid values are: daily, weekly, monthly, yearly, see the logrotate man page for more information.
  • size: Log files are rotated when they grow bigger than size bytes.
  • template: sets the template source, default is "logrotate.erb".
  • cookbook: select the template source from the specified cookbook. By default it will use the cookbook where the definition is used.
  • create: creation parameters for the logrotate "create" config, follows the form "mode owner group". This is an optional parameter, and is nil by default.
  • postrotate: lines to be executed after the log file is rotated
  • prerotate: lines to be executed before the log file is rotated
  • sharedscripts: if true, the sharedscripts options is specified which makes sure prescript and postscript commands are run only once (even if multiple files match the path)

See USAGE below.

USAGE

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

To create application specific logrotate configs, use the logrotate_app definition. 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
  cookbook "logrotate"
  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
  cookbook "logrotate"
  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
  cookbook "logrotate"
  path "/var/log/tomcat/myapp.log"
  options ["missingok", "delaycompress", "notifempty"]
  frequency "daily"
  rotate 30
  create "644 root adm"
end

License and Author

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.

logrotate's People

Contributors

2-718 avatar akatz avatar alexism avatar chrismacnaughton avatar dje avatar gregkare avatar gregsymons avatar guilhem avatar jannikolai avatar jschneiderhan avatar jwitrick avatar kamaradclimber avatar meineerde avatar nathenharvey avatar scottmlikens avatar sethvargo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.