udd -> hiera role; explicitly include apache2
[mirror/dsa-puppet.git] / modules / apache2 / manifests / init.pp
1 # = Class: apache2
2 #
3 # Standard apache config debian.org hosts
4 #
5 # == Sample Usage:
6 #
7 #   include apache2
8 #
9 # @param smaller_number_of_threads by default the worker config is geared towards
10 #                                  serving static/cheap content.  If the host is very
11 #                                  script heavy (say the bug tracking system), set this
12 #                                  to reduce the number of worker threads.
13 # @param rlimitnproc A resource limit for number of processes.  The default is usually fine.
14 # @param rlimitmem   A resource limit for memory usage.  The default is usually fine.
15 # @param public Whether this host's apache should be accessible from the public internet.
16 #               Sets appropriate firewall rules and optionally rate limits.
17 # @param mpm Which Multi-Processing Modules to use. Defaults to worker;
18 #            the alternative is prefork.
19 # @param rate_limit Rate limit incoming connections at the netfilter level.  If false,
20 #                   (and public is true), all incoming connections to the http
21 #                   and https ports get sent to the http chain, and accepted at
22 #                   ferm prio 90, so other things can be done to web traffic
23 #                   before that.
24 class apache2(
25   Boolean $smaller_number_of_threads = false,
26   Integer $rlimitnproc = 256,
27   Integer $rlimitmem = 192 * 1024 * 1024,
28   Boolean $public = true,
29   Enum['prefork','worker'] $mpm = 'worker',
30   Boolean $rate_limit = false,
31 ) {
32   include webserver
33
34   package { 'apache2':
35     ensure => installed,
36   }
37
38   service { 'apache2':
39     ensure  => running,
40     require => Package['apache2'],
41   }
42
43   apache2::module { 'reqtimeout': }
44   apache2::module { 'info': }
45   apache2::module { 'status': }
46   apache2::module { 'headers': }
47   apache2::module { 'macro': }
48
49   apache2::site { '00-default':
50     site    => 'default-debian.org',
51     content => template('apache2/default-debian.org.erb'),
52   }
53   apache2::site { 'xx-default-ssl':
54     site    => 'default-debian.org-ssl',
55     content => template('apache2/default-debian.org-ssl.erb'),
56   }
57
58   apache2::site { '000-default':
59     ensure => absent,
60   }
61
62   apache2::config { 'serve-cgi-bin':
63     ensure => absent,
64   }
65
66   if has_role('popcon') {
67     $memlimit = 512 * 1024 * 1024
68   } else {
69     $memlimit = $rlimitmem
70   }
71
72   apache2::config { 'resource-limits':
73     content => template('apache2/resource-limits.erb'),
74   }
75
76   apache2::config { 'security':
77     source => 'puppet:///modules/apache2/security',
78   }
79
80   apache2::config { 'logformat-privacy':
81     source => 'puppet:///modules/apache2/logformat-privacy',
82   }
83
84   apache2::config { 'local-serverinfo':
85     source => 'puppet:///modules/apache2/local-serverinfo',
86   }
87
88   apache2::config { 'server-status':
89     source => 'puppet:///modules/apache2/server-status',
90   }
91
92   apache2::config { 'puppet-ssl-macros':
93     source => 'puppet:///modules/apache2/puppet-ssl-macros',
94   }
95
96   apache2::config { 'puppet-ftp-macros':
97     source => 'puppet:///modules/apache2/puppet-ftp-macros',
98   }
99
100   apache2::config { 'puppet-config':
101     content => template('apache2/puppet-config.erb'),
102   }
103
104   apache2::config { 'headers':
105     source => 'puppet:///modules/apache2/headers',
106   }
107
108   apache2::config { 'disabled-service':
109     source => 'puppet:///modules/apache2/disabled-service',
110   }
111
112   apache2::module { 'mpm_event': ensure => absent }
113   apache2::module { 'mpm_worker' : ensure => ($mpm == 'worker' ) ? { true => 'present', default => absent } }
114   apache2::module { 'mpm_prefork': ensure => ($mpm == 'prefork') ? { true => 'present', default => absent } }
115
116   file { '/etc/apache2/mods-available/mpm_worker.conf':
117     content => template('apache2/mpm_worker.erb'),
118   }
119
120   file { '/etc/logrotate.d/apache2':
121     source => 'puppet:///modules/apache2/apache2.logrotate',
122   }
123
124   file { '/var/log/apache2':
125     ensure => directory,
126     mode   => '0755',
127   }
128   file { '/var/log/apache2/.nobackup':
129     mode    => '0644',
130     content => '',
131   }
132
133   munin::check { 'apache_accesses': }
134   munin::check { 'apache_processes': }
135   munin::check { 'apache_volume': }
136   munin::check { 'apache_servers': }
137   munin::check { 'ps_apache2':
138     script => 'ps_',
139   }
140   # The munin script needs this
141   package { 'libwww-perl':
142     ensure => installed,
143   }
144
145   if $public {
146     ferm::rule { 'dsa-http':
147       prio        => '23',
148       description => 'A web subchain',
149       domain      => '(ip ip6)',
150       rule        => 'proto tcp dport (http https 6081) jump http'
151     }
152
153     if $rate_limit {
154       include apache2::dynamic
155     } else {
156       ferm::rule { 'dsa-http-allow':
157         description => 'http subchain, allow everything',
158         prio        => '90',
159         chain       => 'http',
160         domain      => '(ip ip6)',
161         rule        => 'jump ACCEPT',
162       }
163     }
164   }
165
166   exec { 'service apache2 reload':
167     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
168     command     => 'service apache2 reload',
169     refreshonly => true,
170     require     =>  Package['apache2'],
171   }
172
173   apache2::config { 'puppet-ssl-key-pins':
174     content => template('apache2/ssl-key-pins.erb'),
175     notify  => Exec['service apache2 reload'],
176   }
177
178   apache2::config { 'local-scheduled-shutdown':
179     source => 'puppet:///modules/apache2/local-scheduled-shutdown',
180   }
181 }