Defined Type: logrotate::rule

Defined in:
modules/logrotate/manifests/rule.pp

Summary

Provides a common template that can be used by different applications to configure log rotation. See logrotate man page for detailed documentation. Most parameters of this class map directly to the corresponding logrotate options.

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • file_glob (String)

    The file glob to act on

  • ensure (Wmflib::Ensure) (defaults to: present)

    the ensureable parameter

  • frequency (Optional[Logrotate::Frequency]) (defaults to: undef)

    frequency of log rotation, must be in daily, weekly, monthly or yearly.

  • not_if_empty (Boolean) (defaults to: false)

    if the file is empty to nothing

  • date_yesterday (Boolean) (defaults to: false)

    Use yesterday's instead of today's date to create the date extension

  • copy_truncate (Boolean) (defaults to: false)

    Truncate the original log file to zero size in place after creating a copy

  • max_age (Optional[Integer[1]]) (defaults to: undef)

    remove rotated logs older than <count> days

  • rotate (Optional[Integer[1]]) (defaults to: undef)

    Log files are rotated count times before being removed or mailed to the address specified in a mail directive

  • date_ext (Boolean) (defaults to: false)

    Archive old versions of log files adding a date extension

  • compress (Boolean) (defaults to: false)

    Old versions of log files are compressed

  • missing_ok (Boolean) (defaults to: false)

    If the log file is missing, go on to the next one without issuing an error message

  • size (Optional[Stdlib::Datasize]) (defaults to: undef)

    Log files are rotated only if they grow bigger than size bytes

  • no_create (Boolean) (defaults to: false)

    New log files are not created

  • post_rotate (Array[String[1]]) (defaults to: [])

    The script is executed after the log file is rotated

  • su (Optional[String[1]]) (defaults to: undef)

    Rotate log files set under this user and group

  • create (Optional[String[1]]) (defaults to: undef)

    Immediately after rotation (before the postrotate script is run) the log file is created (with the same name as the log file just rotated)

  • old_dir (Optional[Stdlib::Unixpath]) (defaults to: undef)

    Logs are moved into directory for rotation



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'modules/logrotate/manifests/rule.pp', line 28

define logrotate::rule (
    String                         $file_glob,
    Wmflib::Ensure                 $ensure         = present,
    Optional[Logrotate::Frequency] $frequency      = undef,
    Boolean                        $not_if_empty   = false,
    Boolean                        $date_yesterday = false,
    Boolean                        $copy_truncate  = false,
    Optional[Integer[1]]           $max_age        = undef,
    Optional[Integer[1]]           $rotate         = undef,
    Boolean                        $date_ext       = false,
    Boolean                        $compress       = false,
    Boolean                        $missing_ok     = false,
    Optional[Stdlib::Datasize]     $size           = undef,
    Boolean                        $no_create      = false,
    Array[String[1]]               $post_rotate    = [],
    Optional[String[1]]            $su             = undef,
    Optional[String[1]]            $create         = undef,
    Optional[Stdlib::Unixpath]     $old_dir        = undef,
) {
    include logrotate
    $actual_size = $size.then |$s| {
        ($frequency =~ Undef).bool2str("size ${s}", "maxsize ${s}")
    }
    if $frequency == 'hourly' and !$logrotate::hourly {
        fail('If using a frequency of hourly then you must also configure `logrotate::hourly: true`')
    }

    logrotate::conf { $title:
        ensure  => $ensure,
        content => template('logrotate/logrotate.erb'),
    }
}