Puppet Class: httpd
- Defined in:
- modules/httpd/manifests/init.pp
Summary
configure httpd daemonOverview
SPDX-License-Identifier: Apache-2.0
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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'modules/httpd/manifests/init.pp', line 15
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 = [],
Boolean $purge_manual_config = true,
Boolean $remove_default_ports = false,
Boolean $http_only = false,
Boolean $wait_network_online = false,
) {
# Package and service. Links is needed for the status page below
$base_pkgs = ['apache2', 'links']
$service_name = 'apache2'
ensure_packages($base_pkgs + $extra_pkgs)
if $remove_default_ports {
# the file is included in apache.conf so just empty it
file { '/etc/apache2/ports.conf':
ensure => file,
content => "# Puppet: default ports are not used\n",
notify => Service[$service_name],
require => Package['apache2'],
}
} elsif $http_only {
# If $http_only is set to true, listen on http/80 only regardless of mod_ssl being loaded, default: false (T277989)
file { '/etc/apache2/ports.conf':
ensure => file,
content => inline_template("#This file is puppetized.\nListen 80\n"),
notify => Service[$service_name],
require => Package['apache2'],
}
} else {
# Use the default ports.conf if nothing else was configured.
file { '/etc/apache2/ports.conf':
ensure => file,
source => 'puppet:///modules/httpd/default-ports.conf',
notify => Service[$service_name],
require => Package['apache2'],
}
}
# 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',
require => Package['apache2'],
}
file { "/etc/apache2/${conf_type}-enabled":
ensure => directory,
owner => 'root',
group => 'root',
mode => '0755',
recurse => $purge_manual_config,
purge => $purge_manual_config,
require => Package['apache2'],
notify => Service[$service_name],
}
}
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',
require => Package['apache2'],
}
# 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'],
require => Package['apache2'],
}
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}",
],
require => Package['apache2'],
}
}
# 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[$service_name],
refreshonly => true,
}
# Apache2 has After=network.target which is not sufficient to guarantee
# the network IP addresses are available.
# https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/
systemd::override { 'apache2-after-network-online-target':
ensure => bool2str($wait_network_online, 'present', 'absent'),
unit => 'apache2',
# Note: entries are appended to the existing one
content => "[Unit]\nAfter=network-online.target\nWants=network-online.target\n",
}
service { $service_name:
ensure => running,
enable => true,
hasrestart => true,
restart => 'systemctl reload apache2',
require => Package['apache2'],
}
$enable_htcacheclean = 'cache_disk' in $modules
profile::auto_restarts::service { 'apache-htcacheclean':
ensure => $enable_htcacheclean.bool2str('present', 'absent'),
}
service { 'apache-htcacheclean':
ensure => stdlib::ensure($enable_htcacheclean, 'service'),
enable => $enable_htcacheclean,
}
}
|