From bc4ce78e31bae76292bb8cc222e113f25ff1bbd8 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 24 Oct 2016 18:03:29 +0200 Subject: [PATCH] library/roles/php-fpm: Set defaults when possible into the php-fpm-pool template. --- php-fpm/defaults/main.yml | 10 ++-- php-fpm/templates/php-fpm-pool.conf.j2 | 66 ++++++++++---------------- 2 files changed, 29 insertions(+), 47 deletions(-) diff --git a/php-fpm/defaults/main.yml b/php-fpm/defaults/main.yml index 46bdaf28..323bd10d 100644 --- a/php-fpm/defaults/main.yml +++ b/php-fpm/defaults/main.yml @@ -43,9 +43,9 @@ phpfpm_default_listen: "127.0.0.1:9000" phpfpm_default_allowed_clients: "127.0.0.1" phpfpm_default_pm: "dynamic" phpfpm_default_pm_max_children: "50" -phpfpm_default_pm_start_servers: "3" -phpfpm_default_pm_min_spare_servers: "1" -phpfpm_default_pm_max_spare_servers: "10" +phpfpm_default_pm_start_servers: "8" +phpfpm_default_pm_min_spare_servers: "5" +phpfpm_default_pm_max_spare_servers: "12" phpfpm_default_pm_max_requests: "10000" phpfpm_default_pm_status_enabled: False phpfpm_default_pm_status_path: "/status" @@ -55,9 +55,9 @@ phpfpm_default_ping_response: '{{ phpfpm_default_pool_name }}' phpfpm_default_display_errors: "off" phpfpm_default_log_errors: "on" phpfpm_default_memory_limit: "64M" -phpfpm_default_request_terminate_timeout: "60s" +phpfpm_default_request_terminate_timeout: "240s" phpfpm_default_slowlog_timeout: "20s" -phpfpm_default_rlimit_files: "1024" +phpfpm_default_rlimit_files: "4096" phpfpm_default_extensions: ".php" phpfpm_default_context: '/' phpfpm_default_session_handler: 'files' diff --git a/php-fpm/templates/php-fpm-pool.conf.j2 b/php-fpm/templates/php-fpm-pool.conf.j2 index 8501c125..fa69aca0 100644 --- a/php-fpm/templates/php-fpm-pool.conf.j2 +++ b/php-fpm/templates/php-fpm-pool.conf.j2 @@ -1,5 +1,5 @@ ; Start a new pool named 'www'. -[{{ item.pool_name }}] +[{{ item.pool_name | default('www') }}] ; The address on which to accept FastCGI requests. ; Valid syntaxes are: @@ -9,7 +9,7 @@ ; specific port; ; '/path/to/unix/socket' - to listen on a unix socket. ; Note: This value is mandatory. -listen = {{ item.listen }} +listen = {{ item.listen | default ('127.0.0.1:9000') }} ; Set listen(2) backlog. A value of '-1' means unlimited. ; Default Value: -1 @@ -21,7 +21,7 @@ listen = {{ item.listen }} ; must be separated by a comma. If this value is left blank, connections will be ; accepted from any ip address. ; Default Value: any -listen.allowed_clients = {{ item.allowed_clients }} +listen.allowed_clients = {{ item.allowed_clients | default ('127.0.0.1') }} ; Set permissions for unix socket, if one is used. In Linux, read/write ; permissions must be set in order to allow connections from a web server. Many @@ -36,9 +36,9 @@ listen.allowed_clients = {{ item.allowed_clients }} ; Note: The user is mandatory. If the group is not set, the default user's group ; will be used. ; RPM: apache Choosed to be able to access some dir as httpd -user = {{ item.user }} +user = {{ item.user | default('www-data') }} ; RPM: Keep a group allowed to write in log dir. -group = {{ item.group }} +group = {{ item.group | default('www-data') }} ; Choose how the process manager will control the number of child processes. ; Possible Values: @@ -57,7 +57,7 @@ group = {{ item.group }} ; of 'idle' processes is greater than this ; number then some children will be killed. ; Note: This value is mandatory. -pm = {{ item.pm }} +pm = {{ item.pm | default('dynamic') }} ; The number of child processes to be created when pm is set to 'static' and the ; maximum number of child processes to be created when pm is set to 'dynamic'. @@ -67,28 +67,28 @@ pm = {{ item.pm }} ; CGI. ; Note: Used when pm is set to either 'static' or 'dynamic' ; Note: This value is mandatory. -pm.max_children = {{ item.pm_max_children }} +pm.max_children = {{ item.pm_max_children | default('50') }} ; The number of child processes created on startup. ; Note: Used only when pm is set to 'dynamic' ; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2 -pm.start_servers = {{ item.pm_start_servers }} +pm.start_servers = {{ item.pm_start_servers | default('3') }} ; The desired minimum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.min_spare_servers = {{ item.pm_min_spare }} +pm.min_spare_servers = {{ item.pm_min_spare | default('1') }} ; The desired maximum number of idle server processes. ; Note: Used only when pm is set to 'dynamic' ; Note: Mandatory when pm is set to 'dynamic' -pm.max_spare_servers = {{ item.pm_max_spare }} +pm.max_spare_servers = {{ item.pm_max_spare | default('10') }} ; The number of requests each child process should execute before respawning. ; This can be useful to work around memory leaks in 3rd party libraries. For ; endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. ; Default Value: 0 -pm.max_requests = {{ item.pm_max_requests }} +pm.max_requests = {{ item.pm_max_requests | default('10000') }} ; The URI to view the FPM status page. If this value is not set, no URI will be ; recognized as a status page. By default, the status page shows the following @@ -119,7 +119,7 @@ pm.max_requests = {{ item.pm_max_requests }} ; may conflict with a real PHP file. ; Default Value: not set {% if item.pm_status_enabled %} -pm.status_path = {{ item.pm_status_path }} +pm.status_path = {{ item.pm_status_path | default('/status') }} {% endif %} ; The ping URI to call the monitoring page of FPM. If this value is not set, no @@ -133,14 +133,14 @@ pm.status_path = {{ item.pm_status_path }} ; may conflict with a real PHP file. ; Default Value: not set {% if item.ping_enabled %} -ping.path = {{ item.ping_path }} +ping.path = {{ item.ping_path | default('/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_enabled %} -ping.response = {{ item.ping_response }} +ping.response = {{ item.ping_response | default('www') }} {% endif %} access.log = /var/log/php-fpm/$pool-access.log @@ -205,17 +205,13 @@ access.log = /var/log/php-fpm/$pool-access.log ; does not stop script execution for some reason. A value of '0' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 -{% if item.req_term_timeout is defined %} -request_terminate_timeout = {{ item.req_term_timeout }} -{% else %} -request_terminate_timeout = {{ phpfpm_default_request_terminate_timeout }} -{% endif %} +request_terminate_timeout = {{ item.req_term_timeout | default('240s') }} ; The timeout for serving a single request after which a PHP backtrace will be ; dumped to the 'slowlog' file. A value of '0s' means 'off'. ; Available units: s(econds)(default), m(inutes), h(ours), or d(ays) ; Default Value: 0 -request_slowlog_timeout = {{ item.slowlog_timeout }} +request_slowlog_timeout = {{ item.slowlog_timeout | default('20s') }} ; The log file for slow requests ; Default Value: not set @@ -224,7 +220,7 @@ slowlog = /var/log/php-fpm/$pool-slow.log ; Set open file descriptor rlimit. ; Default Value: system defined value -rlimit_files = {{ item.rlimit_files }} +rlimit_files = {{ item.rlimit_files | default('4096') }} ; Set max core size rlimit. ; Possible Values: 'unlimited' or an integer greater or equal to 0 @@ -254,7 +250,7 @@ catch_workers_output = yes ; exectute php code. ; Note: set an empty value to allow all extensions. ; Default Value: .php -security.limit_extensions = {{ item.php_extensions }} +security.limit_extensions = {{ item.php_extensions | default('.php') }} ; Pass environment variables like LD_LIBRARY_PATH. All $VARIABLEs are taken from ; the current environment. @@ -282,28 +278,14 @@ security.limit_extensions = {{ item.php_extensions }} ; Default Value: nothing is defined by default except the values in php.ini and ; specified at startup with the -d argument ;php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f www@my.domain.com -php_flag[display_errors] = {{ item.display_errors }} +php_flag[display_errors] = {{ item.display_errors | default('off') }} php_admin_value[error_log] = {{ phpfpm_logdir }}/$pool-error.log -php_admin_flag[log_errors] = {{ item.log_errors }} -php_admin_value[memory_limit] = {{ item.memory_limit }} -{% if item.upload_max_filesize is defined %} -php_admin_value[upload_max_filesize] = {{ item.upload_max_filesize }} -{% endif %} +php_admin_flag[log_errors] = {{ item.log_errors | default('on') }} +php_admin_value[memory_limit] = {{ item.memory_limit | default('64M') }} +php_admin_value[upload_max_filesize] = {{ item.upload_max_filesize | default('100M') }} ; Set session path to a directory owned by process user -{% if item.session_save_handler is defined %} -php_value[session.save_handler] = '{{ item.session_save_handler }}' -{% else %} -php_value[session.save_handler] = '{{ phpfpm_default_session_handler }}' -{% endif %} -{% if item.session_save_path is defined %} -php_value[session.save_path] = '{{ item.session_save_path }}' -{% else %} -{% if phpfpm_session_save_path is defined %} -php_value[session.save_path] = '{{ phpfpm_session_save_path }}' -{% else %} -php_value[session.save_path] = '{{ phpfpm_default_session_prefix }}/{{ item.pool_name }}' -{% endif %} -{% endif %} +php_value[session.save_handler] = '{{ item.session_save_handler | default('files') }}' +php_value[session.save_path] = '{{ item.session_save_path | default('/var/lib/php/www') }}' {% if item.define_custom_variables is defined and item.define_custom_variables %} {% for php_var in phpfpm_php_variables %} php_value[{{ php_var.prop }}] = {{ php_var.value }}