d998e881863c6f086bc41d0f4f8f4acbfb75c46f
[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 class apache2(
18   Boolean $smaller_number_of_threads = false,
19   Integer $rlimitnproc = 256,
20   Integer $rlimitmem = 192 * 1024 * 1024,
21   Boolean $public = true,
22 ) {
23   include webserver
24
25   package { 'apache2':
26     ensure => installed,
27   }
28
29   service { 'apache2':
30     ensure  => running,
31     require => Package['apache2'],
32   }
33
34   apache2::module { 'reqtimeout': }
35   apache2::module { 'info': }
36   apache2::module { 'status': }
37   apache2::module { 'headers': }
38   apache2::module { 'macro': }
39
40   apache2::site { '00-default':
41     site    => 'default-debian.org',
42     content => template('apache2/default-debian.org.erb'),
43   }
44   apache2::site { 'xx-default-ssl':
45     site    => 'default-debian.org-ssl',
46     content => template('apache2/default-debian.org-ssl.erb'),
47   }
48
49   apache2::site { '000-default':
50     ensure => absent,
51   }
52
53   apache2::config { 'serve-cgi-bin':
54     ensure => absent,
55   }
56
57   if has_role('udd') {
58     $memlimit = 512 * 1024 * 1024
59   } elsif has_role('popcon') {
60     $memlimit = 512 * 1024 * 1024
61   } elsif has_role('qamaster') {
62     $memlimit = 300 * 1024 * 1024
63   } else {
64     $memlimit = $rlimitmem
65   }
66
67   apache2::config { 'resource-limits':
68     content => template('apache2/resource-limits.erb'),
69   }
70
71   apache2::config { 'security':
72     source => 'puppet:///modules/apache2/security',
73   }
74
75   apache2::config { 'logformat-privacy':
76     source => 'puppet:///modules/apache2/logformat-privacy',
77   }
78
79   apache2::config { 'local-serverinfo':
80     source => 'puppet:///modules/apache2/local-serverinfo',
81   }
82
83   apache2::config { 'server-status':
84     source => 'puppet:///modules/apache2/server-status',
85   }
86
87   apache2::config { 'puppet-ssl-macros':
88     source => 'puppet:///modules/apache2/puppet-ssl-macros',
89   }
90
91   apache2::config { 'puppet-ftp-macros':
92     source => 'puppet:///modules/apache2/puppet-ftp-macros',
93   }
94
95   apache2::config { 'puppet-config':
96     content => template('apache2/puppet-config.erb'),
97   }
98
99   apache2::config { 'headers':
100     source => 'puppet:///modules/apache2/headers',
101   }
102
103   apache2::config { 'disabled-service':
104     source => 'puppet:///modules/apache2/disabled-service',
105   }
106
107   apache2::module { 'mpm_event': ensure => absent }
108   if has_role('apache_prefork') {
109     apache2::module { 'mpm_worker': ensure => absent }
110     apache2::module { 'mpm_prefork': }
111   } else {
112     apache2::module { 'mpm_prefork': ensure => absent }
113     apache2::module { 'mpm_worker': }
114   }
115   file { '/etc/apache2/mods-available/mpm_worker.conf':
116     content => template('apache2/mpm_worker.erb'),
117   }
118
119   file { '/etc/logrotate.d/apache2':
120     source => 'puppet:///modules/apache2/apache2.logrotate',
121   }
122
123   file { '/var/log/apache2':
124     ensure => directory,
125     mode   => '0755',
126   }
127   file { '/var/log/apache2/.nobackup':
128     mode    => '0644',
129     content => '',
130   }
131
132   munin::check { 'apache_accesses': }
133   munin::check { 'apache_processes': }
134   munin::check { 'apache_volume': }
135   munin::check { 'apache_servers': }
136   munin::check { 'ps_apache2':
137     script => 'ps_',
138   }
139   # The munin script needs this
140   package { 'libwww-perl':
141     ensure => installed,
142   }
143
144   if $public {
145     if has_role('apache_ratelimited') {
146       include apache2::dynamic
147     } else {
148       ferm::rule { 'dsa-http':
149         domain      => '(ip ip6)',
150         prio        => '23',
151         description => 'Allow web access',
152         rule        => '&SERVICE(tcp, (http https))'
153       }
154     }
155   }
156
157   exec { 'service apache2 reload':
158     path        => '/usr/bin:/usr/sbin:/bin:/sbin',
159     command     => 'service apache2 reload',
160     refreshonly => true,
161     require     =>  Package['apache2'],
162   }
163
164   apache2::config { 'puppet-ssl-key-pins':
165     content => template('apache2/ssl-key-pins.erb'),
166     notify  => Exec['service apache2 reload'],
167   }
168
169   apache2::config { 'local-scheduled-shutdown':
170     source => 'puppet:///modules/apache2/local-scheduled-shutdown',
171   }
172 }