Puppet Class: httpd

Defined in:
modules/httpd/manifests/init.pp

Overview

extra_pkgs: An Array of Debian package names of Apache modules which are

not pulled in by the "apache" base package.

Parameters:

  • modules (Array[String]) (defaults to: [])
  • legacy_compat (Wmflib::Ensure) (defaults to: present)
  • period (Enum['daily', 'weekly']) (defaults to: 'daily')
  • rotate (Integer) (defaults to: 30)
  • enable_forensic_log (Boolean) (defaults to: false)
  • extra_pkgs (Array[String]) (defaults to: [])


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
# File 'modules/httpd/manifests/init.pp', line 3

class httpd(
    Array[String] $modules = [],
    Wmflib::Ensure $legacy_compat = present,
    Enum['daily', 'weekly'] $period='daily',
    Integer $rotate=30,
    Boolean $enable_forensic_log = false,
    Array[String] $extra_pkgs = [],
) {
    # Package and service. Links is needed for the status page below
    $base_pkgs = ['apache2', 'links']
    require_package($base_pkgs + $extra_pkgs)

    # Puppet restarts are reloads in apache, as typically that's enough
    service { 'apache2':
        ensure     => running,
        enable     => true,
        provider   => 'debian',
        hasrestart => true,
        restart    => '/usr/sbin/service apache2 reload',
    }

    # When it's not, as is the case for module insertion, have a safe hard restart option
    exec { 'apache2_test_config_and_restart':
        command     => '/usr/sbin/service apache2 restart',
        onlyif      => '/usr/sbin/apache2ctl configtest',
        before      => Service['apache2'],
        refreshonly => true,
    }

    # Ensure the directories for apache config files are in place.
    ['conf', 'env', 'sites'].each |$conf_type| {
        file { "/etc/apache2/${conf_type}-available":
            ensure => directory,
            owner  => 'root',
            group  => 'root',
            mode   => '0755',
        }
        file { "/etc/apache2/${conf_type}-enabled":
            ensure  => directory,
            owner   => 'root',
            group   => 'root',
            mode    => '0755',
            recurse => true,
            purge   => true,
            notify  => Service['apache2'],
        }
    }

    file_line { 'load_env_enabled':
        line  => 'for f in /etc/apache2/env-enabled/*.sh; do [ -r "$f" ] && . "$f" >&2; done || true',
        match => 'env-enabled',
        path  => '/etc/apache2/envvars',
    }

    # Default boilerplate configs
    httpd::conf { 'defaults':
        source   => 'puppet:///modules/httpd/defaults.conf',
        priority => 0,
    }

    httpd::site { 'dummy':
        source   => 'puppet:///modules/httpd/dummy.conf',
        priority => 0,
    }

    # Apache httpd 2.2 compatibility
    httpd::mod_conf { ['filter', 'access_compat']:
        ensure => $legacy_compat,
    }


    httpd::mod_conf { concat(['status'], $modules):
        ensure => present
    }


    # The default mod_status configuration enables /server-status on all vhosts for
    # local requests, but it does not correctly distinguish between requests which
    # are truly local and requests that have been proxied. Because most of our
    # Apaches sit behind a reverse proxy, the default configuration is not safe, so
    # we make sure to replace it with a more conservative configuration that makes
    # /server-status accessible only to requests made via the loopback interface.
    # See T113090.

    file { [
        '/etc/apache2/mods-available/status.conf',
        '/etc/apache2/mods-enabled/status.conf',
    ]:
        ensure  => absent,
        before  => Httpd::Mod_conf['status'],
        require => Package['apache2'],
    }


    # server status page
    httpd::conf { 'server-status':
        source   => 'puppet:///modules/httpd/status.conf',
        priority => 50,
        require  => Httpd::Mod_conf['status'],
    }

    # Check the status
    file { '/usr/local/bin/apache-status':
        source => 'puppet:///modules/httpd/apache-status',
        owner  => 'root',
        group  => 'root',
        mode   => '0555',
    }

    # Forensic logging (logs requests at both beginning and end of request processing)
    if $enable_forensic_log {
        file { '/var/log/apache2/forensic':
            ensure => directory,
            owner  => 'root',
            group  => 'adm',
            mode   => '0750',
            before => Httpd::Conf['log_forensic'],
        }

        httpd::mod_conf { 'log_forensic':
            ensure => present,
            before => Httpd::Conf['log_forensic'],
        }

        httpd::conf { 'log_forensic':
            ensure => present,
            source => 'puppet:///modules/httpd/log_forensic.conf',
        }

        # In the case we use log_forensic, we want to
        # ensure log_forensic logs get rotated just before
        # the main logs, and that apache gets restarted afterwards.
        logrotate::conf { 'apache2':
            ensure  => present,
            content => template('httpd/logrotate.erb')
        }
    }
    else {
        # manage logrotate periodicity and keeping period
        #
        # The augeas rule in apache::logrotate needs /etc/logrotate.d/apache2 which
        # is provided by package apache2
        augeas { 'Apache2 logs':
            lens    => 'Logrotate.lns',
            incl    => '/etc/logrotate.d/apache2',
            changes => [
                "set rule/schedule ${period}",
                "set rule/rotate ${rotate}",
            ],
        }
    }
}