Defined Type: systemd::syslog

Defined in:
modules/systemd/manifests/syslog.pp

Overview

Define: systemd::syslog

Configures logging via rsyslog and logrotate for systemd units. Use the SyslogIdentifier parameter in the service's unit file if firejail (or similar) is used otherwise rsyslog will not receive the right program name.

Parameters

base_dir

Base path, 'title' will be appended to form the final directory path. For example: $title => 'servicebla', log dir => '/var/log/servicebla' Default: '/var/log'

owner

User owner of the logging directory. Default: $title

group

Group owner of the logging directory. Default: $title

readable_by

Establish the file permissions assigned to the logging directory. Options available: 'user' (0600), 'group' (0640), all '0644' Default: 'group'

log_filename

Filename of the logging file. Default: 'syslog.log'

force_stop

Force 'stop' rule in the syslog configuration to avoid sending the logs to syslog/daemon.log files. Default: false

programname_comparison

Operator to use when matching programname. Possible values: startswith, isequal Default: startswith

Parameters:

  • ensure (Wmflib::Ensure) (defaults to: 'present')
  • base_dir (Stdlib::Unixpath) (defaults to: '/var/log')
  • owner (String[1]) (defaults to: $title)
  • group (String[1]) (defaults to: $title)
  • readable_by (Enum['user', 'group', 'all']) (defaults to: 'group')
  • log_filename (String[1]) (defaults to: 'syslog.log')
  • force_stop (Boolean) (defaults to: false)
  • programname_comparison (Enum['startswith', 'isequal']) (defaults to: 'startswith')


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'modules/systemd/manifests/syslog.pp', line 42

define systemd::syslog(
    Wmflib::Ensure                $ensure                 = 'present',
    Stdlib::Unixpath              $base_dir               = '/var/log',
    String[1]                     $owner                  = $title,
    String[1]                     $group                  = $title,
    Enum['user', 'group', 'all']  $readable_by            = 'group',
    String[1]                     $log_filename           = 'syslog.log',
    Boolean                       $force_stop             = false,
    Enum['startswith', 'isequal'] $programname_comparison = 'startswith',
) {
    if $::initsystem != 'systemd' {
        fail('systemd::syslog is useful only with systemd')
    }

    # File permissions
    $dirmode = '0755'
    $filemode = $readable_by ? {
        'user'  => '0600',
        'group' => '0640',
        'all'   => '0644'
    }

    $local_logdir = "${base_dir}/${title}"
    $local_syslogfile = "${local_logdir}/${log_filename}"

    if ! defined(File[$local_logdir]) {
        file { $local_logdir:
            ensure => ensure_directory($ensure),
            owner  => $owner,
            group  => $group,
            mode   => $dirmode,
            force  => true,
        }
    }

    file { $local_syslogfile:
        ensure  => $ensure,
        replace => false,
        content => '',
        owner   => $owner,
        group   => $group,
        mode    => $filemode,
        before  => Rsyslog::Conf[$title],
    }

    rsyslog::conf { $title:
        ensure   => $ensure,
        content  => template('systemd/rsyslog.conf.erb'),
        priority => 20,
        require  => File[$local_logdir],
    }

    if defined(Service[$title]) {
        Rsyslog::Conf[$title] -> Service[$title]
    }

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