summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: 6c1240530c236fdc66c415d9faf2a21a52cf28a3 (plain)
1
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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
#
# Puppet module for Apache
#
# This module is distributed under the GNU Affero General Public License:
# 
# Backup module for puppet
# Copyright (C) 2009 Sarava Group
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
# 
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Using code from Debian Apache2 recipe:
#
#  http://reductivelabs.com/trac/puppet/wiki/Recipes/DebianApache2Recipe
#

class apache(
  $mods           = "/etc/apache2/mods",
  $conf_sites     = "/etc/apache2/sites",
  $conf_d         = "/etc/apache2/conf.d",
  $macros         = "/etc/apache2/conf.d/macros.conf",
  $conf           = "/etc/apache2/apache2.conf",
  $www_folder     = "/var/www/data",
  $error_folder   = "/var/www/error",
  $sites_folder   = "/var/sites",
  $error_dest     = "http://${domain}/missing.html",
  $default_folder = '/var/www/data',
  $server_name    = $hostname,
  $https_proxy    = 'no',
  $remote_addr    = false,
  $http_port      = '80',
  $https_port     = '443',
  $default_user   = 'www-data',
  $default_group  = 'www-data',
) {

  include ssl

  package { 'libapache2-mpm-itk':
    ensure => $::lsbdistcodename ? {
      wheezy  => absent,
      default => present,
    },
  }

  package { "apache":
    name    => $::lsbdistcodename ? {
      wheezy  => 'apache2-mpm-itk',
      default => 'apache2',
    },
    ensure  => installed,
    require => Package['libapache2-mpm-itk'],
  }

  file { "$conf_d":
    ensure  => directory,
    owner   => root,
    group   => root,
    mode    => 0755,
    require => Package["apache"],
  }

  # Integrated into apache2-bin
  package { "mod_macro":
    name   => "libapache2-mod-macro",
    ensure => $::lsbdistcodename ? {
      'wheezy' => present,
      default  => absent,
    },
  }

  service { "apache2":
    alias      => "apache",
    ensure     => running,
    require    => Package["apache"],
    hasstatus  => true,
    hasrestart => true,
  }

  apache::module { "macro":
    ensure  => present,
    require => Package["mod_macro"],
  }

  apache::module { "headers":
    ensure  => present,
    require => Package["apache"],
  }

  apache::module { "ssl":
    ensure  => present,
    require => Package["apache"],
  }

  apache::module { "rewrite":
    ensure  => present,
    require => Package["apache"],
  }

  # Conflicts with mpm_itk
  apache::module { "mpm_event":
    ensure => absent,
    require => Package['apache'],
  }

  apache::module { "mpm_itk":
    ensure  => $::lsbdistcodename ? {
      wheezy  => absent,
      default => present,
    },
    require => [ Package['apache', 'libapache2-mpm-itk'], Apache::Module['mpm_event'] ],
  }

  # disable compression
  # prevents BREACH attack
  # see https://superuser.com/questions/627413/how-do-i-disable-http-level-compression
  apache::module { [ "deflate", "gzip" ]:
    ensure  => absent,
    require => Package["apache"],
  }

  # apache mod_macro configuration
  file { "${macros}":
    ensure  => present,
    content => template('apache/macros.erb'),
    owner   => root,
    group   => root,
    mode    => 0644,
    require => Module["macro"],
    notify  => Service["apache"],
  }

  # apache mod_macro configuration
  file { "${conf}":
    ensure  => present,
    content => template("apache/apache2.conf.${::lsbdistcodename}.erb"),
    owner   => root,
    group   => root,
    mode    => 0644,
    notify  => Service["apache"],
  }

  # apache alias configuration
  file { "${mods}-available/alias.conf":
    ensure  => present,
    content => template('apache/alias.conf.erb'),
    owner   => root,
    group   => root,
    mode    => 0644,
    notify  => Service["apache"],
  }

  # apache autoindex configuration
  file { "${mods}-available/autoindex.conf":
    ensure  => present,
    content => template('apache/autoindex.conf.erb'),
    owner   => root,
    group   => root,
    mode    => 0644,
    notify  => Service["apache"],
  }

  file { "${www_folder}":
    ensure  => directory,
    owner   => "root",
    group   => "root",
    mode    => 0755,
  }

  # icons folder
  # http://larsjung.de/h5ai/
  # http://recursive-design.com/blog/2008/12/29/styling-apache-directory-listings-with-mod_autoindex/
  # http://code.ecchi.ca/apache-tango-icons/README.html
  file { "${www_folder}/icons":
    ensure  => directory,
    recurse => true,
    purge   => true,
    force   => true,
    owner   => "root",
    group   => "root",
    # This mode will also apply to files from the source directory
    mode    => 0644,
    # Puppet will automatically set +x for directories
    source  => [ "puppet:///modules/site_apache/htdocs/$domain/icons",
                 "puppet:///modules/apache/icons", ],
    require => File["${www_folder}"],
  }

  # Legacy configuration
  file { [ "${conf_sites}-available/default", "${conf_sites}-enabled/000-default" ]:
    ensure => absent,
    notify => Service["apache"],
  }

  # default site configuration
  file { "${conf_sites}-available/default.conf":
    ensure  => present,
    content => template('apache/default.erb'),
    owner   => root,
    group   => root,
    mode    => 0644,
    notify  => Service["apache"],
  }

  file { "${conf_sites}-enabled/000-default.conf":
    owner  => root,
    group  => root,
    ensure => "${conf_sites}-available/default.conf",
    notify => Service["apache"],
  }

  # https proxy configuration
  # see http://www.metaltoad.com/blog/running-drupal-secure-pages-behind-proxy
  file { "$conf_d/https-proxy":
    ensure => $https_proxy ? {
      ''      => absent,
      default => present,
    },
    content => $https_proxy ? {
      'force' => "SetEnv HTTPS on\n",
      default => "SetEnvIf X-Forwarded-Proto https HTTPS=on\n",
    },
    owner   => root,
    group   => root,
    mode    => 0644,
    notify  => Service["apache"],
  }

  # TODO: remove this in the future
  # remote addr rewrite
  # see http://stackoverflow.com/questions/2328225/how-to-set-remote-addr-in-apache-before-php-is-invoked
  file { "$conf_d/remote-addr":
    ensure => $remote_addr ? {
      false   => absent,
      default => present,
    },
    content => "RequestHeader set REMOTE_ADDR ${remote_addr}\n",
    owner   => root,
    group   => root,
    mode    => 0644,
    notify  => Service["apache"],
  }

  # Notify this when apache needs a reload. This is only needed when
  # sites are added or removed, since a full restart then would be
  # a waste of time. When the module-config changes, a force-reload is
  # needed.
  exec { "reload-apache2":
     command     => "/etc/init.d/apache2 reload",
     refreshonly => true,
  }

  exec { "force-reload-apache2":
    command     => "/etc/init.d/apache2 force-reload",
    refreshonly => true,
  }

  # Avoid this logrotate error:
  # /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
  file { '/etc/logrotate.d/apache2':
    ensure => present,
    owner  => root,
    group  => root,
    mode   => 0644,
    source => $::virtual ? {
      'vserver' => 'puppet:///modules/apache/logrotate',
      default   => undef,
    },
  }

  class { 'apache::envvars':
    source  => $::virtual ? {
      'vserver' => "puppet:///modules/apache/envvars.vserver.${::lsbdistcodename}",
      default   => "puppet:///modules/apache/envvars.${::lsbdistcodename}",
    },
  }

  # Legacy configuration
  file { "$conf_d/macros":
    ensure => absent,
  }
}