From df8b58b46a3507707bcafe6c42443b9d767b7cca Mon Sep 17 00:00:00 2001 From: Emilien Mantel Date: Wed, 22 Nov 2017 17:02:51 +0100 Subject: [PATCH] Manages status/ping path in FPM pools --- templates/etc/__php__/fpm/pool.d/pool.conf.j2 | 14 +++++++- tests/templates/site.j2 | 23 ++++++++++++ tests/test.yml | 35 ++++++++++++++++--- 3 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 tests/templates/site.j2 diff --git a/templates/etc/__php__/fpm/pool.d/pool.conf.j2 b/templates/etc/__php__/fpm/pool.d/pool.conf.j2 index f483259..eec303f 100644 --- a/templates/etc/__php__/fpm/pool.d/pool.conf.j2 +++ b/templates/etc/__php__/fpm/pool.d/pool.conf.j2 @@ -231,7 +231,11 @@ pm.max_spare_servers = {{ item.pm_max_spare_servers }} ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set -;pm.status_path = /status +{% if item.status_path is defined %} +pm.status_path = {{ item.status_path }} +{% else %} +;pm.status.path = /status +{% endif %} ; The ping URI to call the monitoring page of FPM. If this value is not set, no ; URI will be recognized as a ping page. This could be used to test from outside @@ -243,12 +247,20 @@ pm.max_spare_servers = {{ item.pm_max_spare_servers }} ; anything, but it may not be a good idea to use the .php extension or it ; may conflict with a real PHP file. ; Default Value: not set +{% if item.ping_path is defined %} +ping.path = {{ item.ping_path }} +{% else %} ;ping.path = /ping +{% endif %} ; This directive may be used to customize the response of a ping request. The ; response is formatted as text/plain with a 200 response code. ; Default Value: pong +{% if item.ping_response is defined %} +ping.response = {{ item.ping_response }} +{% else %} ;ping.response = pong +{% endif %} ; The access log file ; Default: not set diff --git a/tests/templates/site.j2 b/tests/templates/site.j2 new file mode 100644 index 0000000..84203c3 --- /dev/null +++ b/tests/templates/site.j2 @@ -0,0 +1,23 @@ +server { + server_name {{ vhost }}; + + root /var/www; + +{% if php_fpm_poold.0.status_path is defined %} + location = {{ php_fpm_poold.0.status_path }} { + include {{ nginx_include }}; + fastcgi_pass unix:{{ php_default_fpm_sock }}; + } +{% endif %} +{% if php_fpm_poold.0.ping_path is defined %} + location = {{ php_fpm_poold.0.ping_path }} { + include {{ nginx_include }}; + fastcgi_pass unix:{{ php_default_fpm_sock }}; + } +{% endif %} + + location ~ \.php$ { + include {{ nginx_include }}; + fastcgi_pass unix:{{ php_default_fpm_sock }}; + } +} diff --git a/tests/test.yml b/tests/test.yml index cce5a5f..81a7034 100644 --- a/tests/test.yml +++ b/tests/test.yml @@ -10,6 +10,17 @@ display_errors: 'Off' php_ini_cli: error_reporting: 'E_ALL' + php_fpm_poold: + - pool_name: 'www' + listen: '{{ php_default_fpm_sock }}' + pm: 'dynamic' + pm_max_children: 250 + pm_start_servers: 10 + pm_min_spare_servers: 10 + pm_max_spare_servers: 20 + status_path: '/status' + ping_path: '/ping' + ping_response: 'ok' pre_tasks: @@ -45,10 +56,16 @@ tasks: - - name: COPY | Vhost - copy: > - dest=/etc/nginx/sites-enabled/{{ vhost }} - content='server { server_name {{ vhost }}; root /var/www; location ~ \.php$ { include {{ nginx_include }}; fastcgi_pass unix:{{ php_default_fpm_sock }}; } }' + - name: TEMPLATE | Nginx site config + template: + src: templates/site.j2 + dest: /etc/nginx/sites-enabled/{{ vhost }} + notify: reload nginx + + - name: FILE | Delete default site + file: + path: /etc/nginx/sites-enabled/default + state: absent notify: reload nginx handlers: @@ -80,3 +97,13 @@ changed_when: false register: c failed_when: c.stdout == '' + + - name: URI | Check ping + uri: + url: "http://localhost{{ php_fpm_poold.0.ping_path }}" + when: php_fpm_poold.0.ping_path is defined + + - name: URI | Check status + uri: + url: "http://localhost{{ php_fpm_poold.0.status_path }}" + when: php_fpm_poold.0.status_path is defined