rename one ferm block
[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('udd') {
67     $memlimit = 512 * 1024 * 1024
68   } elsif has_role('popcon') {
69     $memlimit = 512 * 1024 * 1024
70   } else {
71     $memlimit = $rlimitmem
72   }
73
74   apache2::config { 'resource-limits':
75     content => template('apache2/resource-limits.erb'),
76   }
77
78   apache2::config { 'security':
79     source => 'puppet:///modules/apache2/security',
80   }
81
82   apache2::config { 'logformat-privacy':
83     source => 'puppet:///modules/apache2/logformat-privacy',
84   }
85
86   apache2::config { 'local-serverinfo':
87     source => 'puppet:///modules/apache2/local-serverinfo',
88   }
89
90   apache2::config { 'server-status':
91     source => 'puppet:///modules/apache2/server-status',
92   }
93
94   apache2::config { 'puppet-ssl-macros':
95     source => 'puppet:///modules/apache2/puppet-ssl-macros',
96   }
97
98   apache2::config { 'puppet-ftp-macros':
99     source => 'puppet:///modules/apache2/puppet-ftp-macros',
100   }
101
102   apache2::config { 'puppet-config':
103     content => template('apache2/puppet-config.erb'),
104   }
105
106   apache2::config { 'headers':
107     source => 'puppet:///modules/apache2/headers',
108   }
109
110   apache2::config { 'disabled-service':
111     source => 'puppet:///modules/apache2/disabled-service',
112   }
113
114   apache2::module { 'mpm_event': ensure => absent }
115   apache2::module { 'mpm_worker' : ensure => ($mpm == 'worker' ) ? { true => 'present', default => absent } }
116   apache2::module { 'mpm_prefork': ensure => ($mpm == 'prefork') ? { true => 'present', default => absent } }
117
118   file { '/etc/apache2/mods-available/mpm_worker.conf':
119     content => template('apache2/mpm_worker.erb'),
120   }
121
122   file { '/etc/logrotate.d/apache2':
123     source => 'puppet:///modules/apache2/apache2.logrotate',
124   }
125
126   file { '/var/log/apache2':
127     ensure => directory,
128     mode   => '0755',
129   }
130   file { '/var/log/apache2/.nobackup':
131     mode    => '0644',
132     content => '',
133   }
134
135   munin::check { 'apache_accesses': }
136   munin::check { 'apache_processes': }
137   munin::check { 'apache_volume': }
138   munin::check { 'apache_servers': }
139   munin::check { 'ps_apache2':
140     script => 'ps_',
141   }
142   # The munin script needs this
143   package { 'libwww-perl':
144     ensure => installed,
145   }
146
147   if $public {
148     ferm::rule { 'dsa-http':
149       prio        => '23',
150       description => 'A web subchain',
151       domain      => '(ip ip6)',
152       rule        => 'proto tcp dport (http https 6081) jump http'
153     }
154
155     if $rate_limit {
156       include apache2::dynamic
157     } else {
158       ferm::rule { 'dsa-http-allow':
159         description => 'http subchain, allow everything',
160         prio        => '90',
161         chain       => 'http',
162         domain      => '(ip ip6)',
163         rule        => 'jump ACCEPT',
164       }
165     }
166   }
167
168   exec { 'service apache2 reload':
169     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
170     command     => 'service apache2 reload',
171     refreshonly => true,
172     require     =>  Package['apache2'],
173   }
174
175   apache2::config { 'puppet-ssl-key-pins':
176     content => template('apache2/ssl-key-pins.erb'),
177     notify  => Exec['service apache2 reload'],
178   }
179
180   apache2::config { 'local-scheduled-shutdown':
181     source => 'puppet:///modules/apache2/local-scheduled-shutdown',
182   }
183 }