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