Puppet Class: mailman3::listserve

Defined in:
modules/mailman3/manifests/listserve.pp

Overview

SPDX-License-Identifier: Apache-2.0

Class mailman3::listserve

This class provisions all the resources necessary to run the core Mailman service.

https://docs.mailman3.org/projects/mailman/en/latest/README.html

Parameters:

  • host (Stdlib::Fqdn)
  • db_host (Stdlib::Fqdn)
  • db_name (String)
  • db_user (String)
  • db_password (String)
  • api_password (String)
  • service_ensure (Wmflib::Ensure) (defaults to: 'present')
  • allow_incoming_mail (Boolean) (defaults to: true)
  • mailman_root (Stdlib::Unixpath) (defaults to: '/var/lib/mailman3')


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'modules/mailman3/manifests/listserve.pp', line 9

class mailman3::listserve (
    Stdlib::Fqdn $host,
    Stdlib::Fqdn $db_host,
    String $db_name,
    String $db_user,
    String $db_password,
    String $api_password,
    Wmflib::Ensure $service_ensure = 'present',
    Boolean $allow_incoming_mail = true,
    Stdlib::Unixpath $mailman_root = '/var/lib/mailman3',
) {
    stdlib::ensure_packages([
        'python3-pymysql',
        'python3-mailman-hyperkitty',
    ])

    $mailman3_debs = [
        'mailman3',
        'python3-authheaders',
        'python3-falcon',
        'python3-flufl.bounce',
        'python3-flufl.lock',
        'python3-importlib-resources',
        'python3-zope.interface',
    ]

    # Use stock mailman3 in bookworm and newer
    stdlib::ensure_packages($mailman3_debs)

    Package['dbconfig-no-thanks'] ~> Package['mailman3']

    file { '/etc/mailman3/mailman.cfg':
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        content => template('mailman3/mailman.cfg.erb'),
    }

    service { 'mailman3':
        ensure    => stdlib::ensure($service_ensure, 'service'),
        pattern   => 'mailmanctl',
        subscribe => File['/etc/mailman3/mailman.cfg'],
    }

    profile::auto_restarts::service { 'mailman3':
        ensure => $service_ensure,
    }

    if $service_ensure == 'present' {
        systemd::unmask { 'mailman3.service': }
    } else {
        systemd::mask { 'mailman3.service': }
    }

    file { '/etc/logrotate.d/mailman3':
        ensure  => 'present',
        owner   => 'root',
        group   => 'root',
        mode    => '0444',
        source  => 'puppet:///modules/mailman3/logrotate.conf',
        require => Package['mailman3'],
    }

    # Helper scripts
    file { '/usr/local/sbin/remove_from_lists':
        ensure => 'present',
        owner  => 'root',
        group  => 'list',
        mode   => '0550',
        source => 'puppet:///modules/mailman3/scripts/remove_from_lists.py',
    }

    file { '/usr/local/sbin/discard_held_messages':
        ensure => 'present',
        owner  => 'root',
        group  => 'list',
        mode   => '0550',
        source => 'puppet:///modules/mailman3/scripts/discard_held_messages.py',
    }

    systemd::timer::job { 'discard_held_messages':
        ensure      => $service_ensure,
        user        => 'root',
        description => 'discard un-moderated held messages after 90 days (T109838)',
        command     => '/usr/local/sbin/discard_held_messages 90',
        interval    => {'start' => 'OnCalendar', 'interval' => 'daily'},
    }

    file { '/usr/local/sbin/discard_stale_subscriptions':
        ensure => 'present',
        owner  => 'root',
        group  => 'list',
        mode   => '0550',
        source => 'puppet:///modules/mailman3/scripts/discard_stale_subscriptions.py',
    }

    $stale_subs_metrics = '/var/lib/prometheus/node.d/discard_stale_sub_mailman.prom'
    systemd::timer::job { 'discard_stale_subscriptions':
        ensure      => $service_ensure,
        user        => 'root',
        description => 'discard unconfirmed (subscriber-owned) pending subscription requests after 30 days (T353891)',
        command     => "/usr/local/sbin/discard_stale_subscriptions 30 --prom-file ${stale_subs_metrics}",
        interval    => {'start' => 'OnCalendar', 'interval' => 'daily'},
    }

    # On the passive host the timer is absent and nothing refreshes the metrics
    # textfile; remove any stale copy so its frozen timestamp does not trigger a
    # false MailmanStaleSubsJanitorStale alert after a failover.
    if $service_ensure != 'present' {
        file { $stale_subs_metrics:
            ensure => absent,
        }
    }

    file { '/usr/local/sbin/migrate_to_mailman3':
        ensure => 'present',
        owner  => 'root',
        group  => 'list',
        mode   => '0550',
        source => 'puppet:///modules/mailman3/scripts/migrate_to_mailman3.py',
    }

    file { "${$mailman_root}/templates/domains/":
        ensure => directory,
        owner  => 'root',
        group  => 'list',
        mode   => '0555',
    }

    file { "${$mailman_root}/templates/domains/${host}/":
        ensure  => directory,
        owner   => 'root',
        group   => 'list',
        mode    => '0555',
        require => File["${$mailman_root}/templates/domains/"],
    }

    file { "${$mailman_root}/templates/domains/${host}/en/":
        ensure  => directory,
        owner   => 'root',
        group   => 'list',
        mode    => '0555',
        require => File["${$mailman_root}/templates/domains/${host}/"],
    }

    $templates = [
        'domain_admin_notice_new-list.txt',
        'help.txt',
        'list_admin_action_post.txt',
        'list_admin_action_subscribe.txt',
        'list_admin_action_unsubscribe.txt',
        'list_admin_notice_disable.txt',
        'list_admin_notice_removal.txt',
        'list_admin_notice_subscribe.txt',
        'list_admin_notice_unrecognized.txt',
        'list_admin_notice_unsubscribe.txt',
        'list_member_digest_header.txt',
        'list_member_digest_masthead.txt',
        'list_member_generic_footer.txt',
        'list_member_regular_header.txt',
        'list_user_action_invite.txt',
        'list_user_action_subscribe.txt',
        'list_user_action_unsubscribe.txt',
        'list_user_notice_goodbye.txt',
        'list_user_notice_hold.txt',
        'list_user_notice_no-more-today.txt',
        'list_user_notice_post.txt',
        'list_user_notice_probe.txt',
        'list_user_notice_refuse.txt',
        'list_user_notice_rejected.txt',
        'list_user_notice_warning.txt',
        'list_user_notice_welcome.txt'
    ]

    $templates.each |String $template| {
        $dest_filename = regsubst($template, /_/, ':', 'G')
        file { "${$mailman_root}/templates/domains/${host}/en/${dest_filename}":
            ensure  => file,
            source  => "puppet:///modules/mailman3/templates/${template}",
            owner   => 'root',
            group   => 'list',
            mode    => '0555',
            require => File["${$mailman_root}/templates/domains/${host}/en"],
        }
    }

    firewall::service { 'mailman-smtp':
        ensure => stdlib::ensure($allow_incoming_mail),
        proto  => 'tcp',
        port   => 25,
    }
}