Allow setting custom mpm and parameters
diff --git a/README.rst b/README.rst
index beb4b3e..2e41e81 100644
--- a/README.rst
+++ b/README.rst
@@ -84,6 +84,20 @@
address: 'git@repo1.domain.cz:impress/billometer.git'
revision: 'master'
+Tune settings of mpm_prefork
+
+.. code-block:: yaml
+
+ parameters:
+ apache:
+ mpm:
+ prefork:
+ max_clients: 250
+ servers:
+ min: 32
+ max: 64
+ max_requests: 4000
+
Example pillar
==============
diff --git a/apache/files/mpm/mpm_prefork.conf b/apache/files/mpm/mpm_prefork.conf
new file mode 100644
index 0000000..ab4c356
--- /dev/null
+++ b/apache/files/mpm/mpm_prefork.conf
@@ -0,0 +1,17 @@
+{%- from "apache/map.jinja" import server with context %}
+# prefork MPM
+# StartServers: number of server processes to start
+# MinSpareServers: minimum number of server processes which are kept spare
+# MaxSpareServers: maximum number of server processes which are kept spare
+# MaxRequestWorkers: maximum number of server processes allowed to start
+# MaxConnectionsPerChild: maximum number of requests a server process serves
+
+<IfModule mpm_prefork_module>
+ StartServers {{ server.mpm.prefork.servers.start }}
+ MinSpareServers {{ server.mpm.prefork.servers.spare.min }}
+ MaxSpareServers {{ server.mpm.prefork.servers.spare.max }}
+ MaxRequestWorkers {{ server.mpm.prefork.max_clients }}
+ MaxConnectionsPerChild {{ server.mpm.prefork.servers.max_requests }}
+</IfModule>
+
+# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
diff --git a/apache/server/service.sls b/apache/server/service.sls
index dc49394..44b7565 100644
--- a/apache/server/service.sls
+++ b/apache/server/service.sls
@@ -93,4 +93,39 @@
- require:
- service: apache_service_dead
+{%- for mpm_type, mpm in server.mpm.iteritems() %}
+
+{%- if mpm.enabled %}
+
+apache_mpm_{{ mpm_type }}_enable:
+ cmd.run:
+ - name: "a2enmod mpm_{{ mpm_type }}"
+ - creates: /etc/apache2/mods-enabled/mpm_{{ mpm_type }}.load
+ - require:
+ - file: apache_mpm_{{ mpm_type }}_config
+ - watch_in:
+ - service: apache_service
+
+apache_mpm_{{ mpm_type }}_config:
+ file.managed:
+ - name /etc/apache2/mods-available/mpm_{{ mpm_type }}.conf
+ - source: salt://apache/files/mpm/mpm_{{ mpm_type }}.conf
+ - template: jinja
+ - require:
+ - pkg: apache_packages
+ - watch_in:
+ - service: apache_service
+
+{%- else %}
+
+apache_mpm_{{ mpm_type }}_disable:
+ file.absent:
+ - name: /etc/apache2/mods-enabled/mpm_{{ mpm_type }}.load
+ - watch_in:
+ - service: apache_service
+
+{%- endif %}
+
+{%- endfor %}
+
{%- endif %}
diff --git a/metadata/service/server/single.yml b/metadata/service/server/single.yml
index 21f3319..0f2aef6 100644
--- a/metadata/service/server/single.yml
+++ b/metadata/service/server/single.yml
@@ -13,3 +13,21 @@
modules:
- ssl
- rewrite
+ mpm:
+ prefork:
+ enabled: true
+ servers:
+ start: 5
+ spare:
+ min: ${apache:server:mpm:servers:start}
+ max: 10
+ # Avoid memory leakage by restarting workers every x requests
+ max_requests: 0
+ # Should be 80% of server memory / average memory usage of one worker
+ max_clients: 150
+ # Should be same or more than max clients
+ limit: ${apache:server:mpm:max_clients}
+ event:
+ enabled: false
+ worker:
+ enabled: false