Commit 86aa3824 authored by nimrod's avatar nimrod
Browse files

- Global configuration handling.

- Decided against file globbing config, would be convoluted for this
case.
- Decided to stick with Unix socket instead of TCP port (can't have them
both for the same pool).
- Flushing handlers and waiting for service to come online.
- Logging to syslog.
- Better assertions.
- Added test for changes.
- Updated TODO list (didn't have to set user as web server, comes
correct by default).
parent 9ba6f566
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -63,11 +63,7 @@ at: https://www.shore.co.il/git/.
TODO
----

- Configuration directory, include file globbing.
- Listen to TCP and Unix sockets.
- Log to syslog.
- Configure pool.
- Status page.
- Ping page.
- Flush handlers, wait for service to come up.
- Test PHP script with Nginx.
- Run as web server user.
+3 −0
Original line number Diff line number Diff line
---
# defaults file for php-fpm

php_fpm_global_config:
    error_log: syslog
+5 −0
Original line number Diff line number Diff line
---
# handlers file for php-fpm

- name: Restart PHP-FPM
  service:
      name: '{{ php_fpm_service[ansible_os_family] }}'
      state: restarted
+22 −0
Original line number Diff line number Diff line
@@ -5,7 +5,12 @@
  assert:
    that:
        - ansible_os_family in php_fpm_service
        - ansible_os_family in php_fpm_www_user
        - ansible_os_family in php_fpm_conf
        - ansible_os_family in php_fpm_listen_socket
        - 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

- name: APT install
  when: ansible_pkg_mgr == 'apt'
@@ -21,8 +26,25 @@
      name: '{{ php_fpm_pkg_version[ansible_distribution_release] }}'
      state: present

- name: Global config
  with_dict: '{{ php_fpm_global_config }}'
  ini_file:
      dest: '{{ php_fpm_conf[ansible_os_family] }}'
      section: global
      option: '{{ item.key }}'
      value: '{{ item.value }}'
      state: present
  notify:
      - Restart PHP-FPM

- name: Enable service
  service:
      name: '{{ php_fpm_service[ansible_os_family] }}'
      state: started
      enabled: yes

- meta: flush_handlers

- name: Wait for service to come up
  wait_for:
      path: '{{ php_fpm_listen_socket[ansible_os_family] }}'
+9 −1
Original line number Diff line number Diff line
@@ -3,12 +3,20 @@ from testinfra.utils.ansible_runner import AnsibleRunner
testinfra_hosts = AnsibleRunner('.molecule/ansible_inventory').get_hosts('all')


def test_php_fpm_service(Service, SystemInfo):
def test_php_fpm_service(Service, SystemInfo, File):
    if SystemInfo.type == 'openbsd':
        service = Service('php56_fpm')
        socket = File('/var/www/run/php-fpm.sock')
        user = 'www'
    elif SystemInfo.type == 'linux' and SystemInfo.distribution in ['debian',
                                                                    'ubuntu']:
        service = Service('php5-fpm')
        socket = File('/var/run/php5-fpm.sock')
        user = 'www-data'
    assert socket.is_socket
    assert socket.mode == 0o0660
    assert socket.user == user
    assert socket.group == user
    assert service.is_running
    try:
        assert service.is_enabled
Loading