Puppet Class: swift::storage

Defined in:
modules/swift/manifests/storage.pp

Overview

SPDX-License-Identifier: Apache-2.0

Parameters:

  • statsd_host (Any) (defaults to: undef)
  • statsd_port (Any) (defaults to: 8125)
  • statsd_metric_prefix (Any) (defaults to: undef)
  • statsd_sample_rate_factor (Any) (defaults to: '1')
  • memcached_servers (Any) (defaults to: ['localhost'])
  • memcached_port (Any) (defaults to: 11211)
  • container_replicator_concurrency (Any) (defaults to: '1')
  • container_replicator_interval (Any) (defaults to: undef)
  • object_replicator_concurrency (Any) (defaults to: '3')
  • object_replicator_interval (Any) (defaults to: undef)
  • object_server_default_workers (Any) (defaults to: undef)
  • servers_per_port (Any) (defaults to: 3)
  • backends (Any) (defaults to: [])
  • replication_limit_memory_percent (Any) (defaults to: 0)
  • loopback_device_size (Any) (defaults to: undef)
  • loopback_device_count (Any) (defaults to: 0)
  • disable_fallocate (Boolean) (defaults to: false)


2
3
4
5
6
7
8
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
# File 'modules/swift/manifests/storage.pp', line 2

class swift::storage (
    $statsd_host                      = undef,
    $statsd_port                      = 8125,
    $statsd_metric_prefix             = undef,
    $statsd_sample_rate_factor        = '1',
    $memcached_servers                = ['localhost'],
    $memcached_port                   = 11211,
    $container_replicator_concurrency = '1',
    $container_replicator_interval    = undef,
    $object_replicator_concurrency    = '3',
    $object_replicator_interval       = undef,
    $object_server_default_workers    = undef,
    $servers_per_port                 = 3,
    $backends                         = [],
    $replication_limit_memory_percent = 0,
    $loopback_device_size             = undef,
    $loopback_device_count            = 0,
    Boolean $disable_fallocate        = false,
) {
    package {
        [ 'swift-account',
          'swift-container',
          'swift-object',
          'swift-drive-audit',
    ]:
        ensure => present,
    }

    # eventlet + getaddrinfo is busted in Bullseye, thus use addresses
    # https://phabricator.wikimedia.org/T283714
    $memcached_addresses = $memcached_servers.map |$server| {
        $addr = ipresolve($server, 4); "${addr}:${memcached_port}"
    }

    $loopback_dir = '/var/lib/swift/'
    $swift_data_dir = '/srv/swift-storage/'

    # Install overrides for object replication daemons (rsync, swift-object-replicator) to be able
    # to limit their memory usage
    systemd::service { 'rsync':
        ensure   => present,
        content  => init_template('rsync', 'systemd_override'),
        override => true,
        restart  => true,
    }

    systemd::service { 'swift-object-replicator':
        ensure   => present,
        content  => init_template('swift-object-replicator', 'systemd_override'),
        override => true,
        restart  => true,
    }

    class { 'rsync::server':
        log_file => '/var/log/rsyncd.log',
    }

    rsync::server::module { 'account':
        uid             => 'swift',
        gid             => 'swift',
        max_connections => Integer(length($backends) * 2),
        path            => $swift_data_dir,
        read_only       => 'no',
        lock_file       => '/var/lock/account.lock',
    }
    rsync::server::module { 'container':
        uid             => 'swift',
        gid             => 'swift',
        max_connections => Integer(length($backends) * 2),
        path            => $swift_data_dir,
        read_only       => 'no',
        lock_file       => '/var/lock/container.lock',
    }
    rsync::server::module { 'object':
        uid             => 'swift',
        gid             => 'swift',
        max_connections => Integer(length($backends) * 2),
        path            => $swift_data_dir,
        read_only       => 'no',
        lock_file       => '/var/lock/object.lock',
    }

    # set up swift specific configs
    file {
        default:
            owner => 'swift',
            group => 'swift',
            mode  => '0440';
        '/etc/swift/account-server.conf':
            content => template('swift/account-server.conf.erb');
        '/etc/swift/container-server.conf':
            content => template('swift/container-server.conf.erb');
        '/etc/swift/object-server.conf':
            content => template('swift/object-server.conf.erb');
        '/etc/swift/container-reconciler.conf':
            content => template('swift/container-reconciler.conf.erb');
        # The uwsgi configurations are similar to what Debian ships but logging to syslog
        '/etc/swift/swift-account-server-uwsgi.ini':
            content => template('swift/swift-account-server-uwsgi.ini.erb');
        '/etc/swift/swift-container-server-uwsgi.ini':
            content => template('swift/swift-container-server-uwsgi.ini.erb');
        $swift_data_dir:,
            ensure  => directory,
            require => Package['swift'],
            # the 1 is to allow nagios to read the drives for check_disk
            mode    => '0751';
        '/usr/bin/swift-grow-ssd-part':
            mode   => '0555',
            source => 'puppet:///modules/swift/grow_ssd_part.py',
    }

    service { [
        'swift-account',
        'swift-account-auditor',
        'swift-account-reaper',
        'swift-account-replicator',
        'swift-container',
        'swift-container-auditor',
        'swift-container-replicator',
        'swift-container-updater',
        'swift-object',
        'swift-object-auditor',
        'swift-object-updater',
    ]:
        ensure => running,
    }

    # object-reconstructor and container-sharder are not used in WMF deployment, yet are enabled
    # by the Debian package.
    # Remove their unit so 'systemctl <action> swift*' exits zero.
    # If one of the units matching the wildcard is masked then systemctl
    # exits non-zero on e.g. restart.
    ['swift-object-reconstructor', 'swift-container-sharder'].each |String $unit| {
        file { "/lib/systemd/system/${unit}.service":
            ensure => absent,
            notify => Exec['reload systemd daemon'],
        }
    }

    exec { 'reload systemd daemon':
        command     => '/bin/systemctl daemon-reload',
        refreshonly => true,
    }

    file { '/etc/swift/swift-drive-audit.conf':
        owner  => 'root',
        group  => 'root',
        mode   => '0440',
        source => 'puppet:///modules/swift/swift-drive-audit.conf',
    }

    # Loopback storage has been requested, initialize it and make sure devices exist at boot
    if $loopback_device_count > 0 {
        systemd::unit { 'loopback-device@':
            ensure  => 'present',
            content => systemd_template('loopback-device@'),
        }

        # Hack: rename /dev/loop0 to /dev/ld[a-d] to match a physical device and workaround XFS' label
        # length limitation (12 chars)
        udev::rule{ 'swift_loop':
            source => 'puppet:///modules/swift/swift_loop.rules',
        }

        range(0, $loopback_device_count - 1).each |$i| {
            exec { 'Initialize loop storage device':
                command => "/usr/bin/truncate -s ${loopback_device_size} ${loopback_dir}/loop${i}.img",
                creates => "${loopback_dir}/loop${i}.img",
            }

            service { "loopback-device@${i}.service":
                ensure  => running,
                enable  => true,
                require => Systemd::Unit['loopback-device@'],
            }
        }
    }
}