summaryrefslogtreecommitdiff
path: root/manifests/init.pp
blob: 22d4bc6bfd5b1a5c96b8f08fdbb329a53b9806bf (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
#
# 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(
  $sites          = "/etc/apache2/sites",
  $mods           = "/etc/apache2/mods",
  $conf_d         = "/etc/apache2/conf.d",
  $macros         = "/etc/apache2/conf.d/macros",
  $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
) {

  include ssl

  package { "apache":
    name   => "apache2-mpm-itk",
    ensure => installed,
  }

  package { "mod_macro":
    name   => "libapache2-mod-macro",
    ensure => installed,                                                                                                     
  }

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

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

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

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

  module { "rewrite":
    ensure  => present,
    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.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"],
  }

  # 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", ]
  }

  # default site configuration
  file { "${sites}-available/default":
    ensure  => present,
    content => template('apache/default.erb'),
    owner   => root,
    group   => root,
    mode    => 0644,
    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,
  }
}