Commit ba9c4311 authored by nimrod's avatar nimrod
Browse files

- Change of tactic for managing (multiple) pools. The main php-fpm.conf

is generated from a template and includes a pools directory. Pool
templates are globbed and added. Assertsions and documentation updated
accordingly.
- Added ping and status pages, tests are required.
- Validate config before restarting service (won't end up with a faulty
config and an offline service).
parent 08098467
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -4,7 +4,9 @@ PHP-FPM
.. image:: https://travis-ci.org/adarnimrod/php-fpm.svg?branch=master
    :target: https://travis-ci.org/adarnimrod/php-fpm

Provision PHP FastCGI (FPM).
Provision PHP FastCGI (FPM). Configuration of pools is done by placing templates
inside :code:`templates/php-fpm/pools/` either inside the role or relative to
the playbook.

Requirements
------------
@@ -63,6 +65,5 @@ at: https://www.shore.co.il/git/.
TODO
----

- Configure pool.
- Status page.
- Ping page.
+18 −0
Original line number Diff line number Diff line
@@ -3,3 +3,21 @@

php_fpm_global_config:
    error_log: syslog
    pid: '/var/run/{{ php_fpm_service[ansible_os_family] }}.pid'

php_fpm_www_pool_config:
    user: '{{ php_fpm_user[ansible_os_family] }}'
    group: '{{ php_fpm_user[ansible_os_family] }}'
    listen: '{{ php_fpm_listen_socket[ansible_os_family] }}'
    listen.owner: '{{ php_fpm_user[ansible_os_family] }}'
    listen.group: '{{ php_fpm_user[ansible_os_family] }}'
    listen.mode: '0660'
    pm: dynamic
    pm.max_children: 5
    pm.start_servers: 2
    pm.min_spare_servers: 1
    pm.max_spare_servers: 3
    pm.status_path: /status
    ping.path: /ping
    chdir: /
    chroot: '{{ php_fpm_chroot[ansible_os_family]|default(omit) }}'
+34 −6
Original line number Diff line number Diff line
@@ -8,9 +8,13 @@
        - ansible_os_family in php_fpm_www_user
        - ansible_os_family in php_fpm_conf
        - ansible_os_family in php_fpm_listen_socket
        - ansible_os_family in php_fpm_validate_config
        - ansible_os_family in php_fpm_pools_dir
        - ansible_os_family in php_fpm_user
        - ansible_distribution_release in ['6.0', '5.9', 'jessie', 'trusty']
        - ansible_os_family != 'OpenBSD' or ansible_distribution_release in php_fpm_pkg_version
        - php_fpm_global_config is iterable
        - php_fpm_www_pool_config is iterable

- name: APT install
  when: ansible_pkg_mgr == 'apt'
@@ -26,17 +30,41 @@
      name: '{{ php_fpm_pkg_version[ansible_distribution_release] }}'
      state: present

- name: Create pools directory
  file:
      path: '{{ php_fpm_pools_dir[ansible_os_family] }}'
      owner: root
      group: 0
      mode: 0o0755
      state: directory

- name: Copy pool templates
  with_fileglob:
  - '{{ role_path }}/templates/php-fpm/pools/*.conf'
  - '{{ playbook_dir }}/templates/php-fpm/pools/*.conf'
  template:
      src: '{{ item }}'
      dest: '{{ php_fpm_pools_dir[ansible_os_family] }}/{{ item|basename }}'
      owner: root
      group: 0
      mode: 0o0644
  notify:
  - Restart PHP-FPM

- name: Global config
  with_dict: '{{ php_fpm_global_config }}'
  ini_file:
  template:
      dest: '{{ php_fpm_conf[ansible_os_family] }}'
      section: global
      option: '{{ item.key }}'
      value: '{{ item.value }}'
      state: present
      src: php-fpm.conf
      owner: root
      group: 0
      mode: 0o0644
  notify:
      - Restart PHP-FPM

- name: Verify config
  command: '{{ php_fpm_validate_config[ansible_os_family] }}'
  changed_when: False

- name: Enable service
  service:
      name: '{{ php_fpm_service[ansible_os_family] }}'

templates/php-fpm.conf

0 → 100644
+5 −0
Original line number Diff line number Diff line
[global]
{% for key, value in php_fpm_global_config.iteritems() %}
{{ key }} = {{ value }}
{% endfor %}
include = {{ php_fpm_pools_dir[ansible_os_family] }}/*.conf
+4 −0
Original line number Diff line number Diff line
[www]
{% for key, value in php_fpm_www_pool_config.iteritems() %}
{{ key }} = {{ value }}
{% endfor %}
Loading