From 4bb9eb3870ae25482b020b786f6d757a9738d7cb Mon Sep 17 00:00:00 2001 From: phil Date: Sat, 25 Feb 2023 21:25:34 +0100 Subject: [PATCH] Introduce more variables --- defaults/main.yml | 5 +++++ tasks/php.yml | 19 ++++++------------- templates/systemd/php-fpm@.service | 16 ++++++++-------- {files => templates}/systemd/php-fpm@.socket | 6 ++++-- 4 files changed, 23 insertions(+), 23 deletions(-) rename {files => templates}/systemd/php-fpm@.socket (50%) diff --git a/defaults/main.yml b/defaults/main.yml index 06563be..11adcb6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,8 @@ --- php_fpm_log_dir: /var/log/phpfpm php_fpm_pool_dir: "/etc/php/{{ php_version.stdout }}/fpm/pool.d" +php_fpm_pool_config_file: "{{ php_fpm_pool_dir }}/%i.cfg" + +php_fpm_cpu_quota: "100%" +php_fpm_memory_high: "25%" +php_fpm_memory_max: "35%" diff --git a/tasks/php.yml b/tasks/php.yml index 9a02c93..19f51fe 100644 --- a/tasks/php.yml +++ b/tasks/php.yml @@ -39,21 +39,14 @@ when: "'php-fpm' in ansible_facts.packages" notify: reload php-fpm -- name: "PHP | Copy template for PHP-FPM systemd socket" - ansible.builtin.copy: - src: systemd/php-fpm@.socket - dest: /etc/systemd/system/php-fpm@.socket - mode: 0644 - notify: - - stop php-fpm-socket - - stop php-fpm-service - - start php-fpm-socket - -- name: "PHP | Copy template for PHP-FPM systemd service" +- name: "PHP | Copy template for PHP-FPM systemd service and socket" ansible.builtin.template: - src: systemd/php-fpm@.service - dest: /etc/systemd/system/php-fpm@.service + src: "systemd/{{ item }}" + dest: "/etc/systemd/system/{{ item }}" mode: 0644 + loop: + - php-fpm@.service + - php-fpm@.socket notify: - stop php-fpm-socket - stop php-fpm-service diff --git a/templates/systemd/php-fpm@.service b/templates/systemd/php-fpm@.service index 56d29ed..b488a48 100644 --- a/templates/systemd/php-fpm@.service +++ b/templates/systemd/php-fpm@.service @@ -1,6 +1,6 @@ # {{ ansible_managed }} # -# This service can be enabled for user. +# This service can be enabled for each user. # It uses a single php-fpm configuration file. # User-specific settings can be overridden via environment variables (see "FPM_SOCKET_PATH" below). @@ -11,14 +11,14 @@ After=network.target Requires=php-fpm@%i.socket [Service] -User=%i -Group=%i +User={{ php_fpm_user | default('%i') }} +Group={{ php_fpm_group | default('%i') }} Type=notify Environment="FPM_SOCKETS=/run/php/php-fpm-%i.sock=3" -Environment="FPM_ERROR_LOG={{ php_fpm_log_dir }}/%i.log" +Environment="FPM_ERROR_LOG={{ php_fpm_log_dir }}/{{ php_fpm_log_file | default('%i.log') }}" # this variable is used in the pool configuration file Environment="FPM_SOCKET_PATH=/run/php/php-fpm-%i.sock" -ExecStart=/usr/sbin/php-fpm{{ php_version.stdout }} --nodaemonize --fpm-config /etc/php/{{ php_version.stdout }}/fpm/pool.d/%i.cfg +ExecStart=/usr/sbin/php-fpm{{ php_version.stdout }} --nodaemonize --fpm-config {{ php_fpm_pool_config_file }} ExecReload=/bin/kill -USR2 $MAINPID KillMode=process Restart=on-failure @@ -51,9 +51,9 @@ RuntimeDirectory=php RuntimeDirectoryPreserve=yes # Resources -CPUQuota=100% -MemoryHigh=25% -MemoryMax=35% +CPUQuota={{ php_fpm_cpu_quota }} +MemoryHigh={{ php_fpm_memory_high }} +MemoryMax={{ php_fpm_memory_max }} [Install] WantedBy=multi-user.target diff --git a/files/systemd/php-fpm@.socket b/templates/systemd/php-fpm@.socket similarity index 50% rename from files/systemd/php-fpm@.socket rename to templates/systemd/php-fpm@.socket index 6b9313e..eb94ce3 100644 --- a/files/systemd/php-fpm@.socket +++ b/templates/systemd/php-fpm@.socket @@ -1,9 +1,11 @@ +# {{ ansible_managed }} + [Unit] After=network-online.target [Socket] -SocketUser=%i -SocketGroup=%i +SocketUser={{ php_fpm_socket_user | default('%i') }} +SocketGroup={{ php_fpm_socket_group | default('%i') }} SocketMode=0660 ListenStream=/run/php/php-fpm-%i.sock