Introduce more variables

This commit is contained in:
phil 2023-02-25 21:25:34 +01:00
parent cfdc088844
commit 4bb9eb3870
4 changed files with 23 additions and 23 deletions

View file

@ -1,3 +1,8 @@
--- ---
php_fpm_log_dir: /var/log/phpfpm php_fpm_log_dir: /var/log/phpfpm
php_fpm_pool_dir: "/etc/php/{{ php_version.stdout }}/fpm/pool.d" 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%"

View file

@ -39,21 +39,14 @@
when: "'php-fpm' in ansible_facts.packages" when: "'php-fpm' in ansible_facts.packages"
notify: reload php-fpm notify: reload php-fpm
- name: "PHP | Copy template for PHP-FPM systemd socket" - name: "PHP | Copy template for PHP-FPM systemd service and 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"
ansible.builtin.template: ansible.builtin.template:
src: systemd/php-fpm@.service src: "systemd/{{ item }}"
dest: /etc/systemd/system/php-fpm@.service dest: "/etc/systemd/system/{{ item }}"
mode: 0644 mode: 0644
loop:
- php-fpm@.service
- php-fpm@.socket
notify: notify:
- stop php-fpm-socket - stop php-fpm-socket
- stop php-fpm-service - stop php-fpm-service

View file

@ -1,6 +1,6 @@
# {{ ansible_managed }} # {{ 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. # It uses a single php-fpm configuration file.
# User-specific settings can be overridden via environment variables (see "FPM_SOCKET_PATH" below). # 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 Requires=php-fpm@%i.socket
[Service] [Service]
User=%i User={{ php_fpm_user | default('%i') }}
Group=%i Group={{ php_fpm_group | default('%i') }}
Type=notify Type=notify
Environment="FPM_SOCKETS=/run/php/php-fpm-%i.sock=3" 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 # this variable is used in the pool configuration file
Environment="FPM_SOCKET_PATH=/run/php/php-fpm-%i.sock" 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 ExecReload=/bin/kill -USR2 $MAINPID
KillMode=process KillMode=process
Restart=on-failure Restart=on-failure
@ -51,9 +51,9 @@ RuntimeDirectory=php
RuntimeDirectoryPreserve=yes RuntimeDirectoryPreserve=yes
# Resources # Resources
CPUQuota=100% CPUQuota={{ php_fpm_cpu_quota }}
MemoryHigh=25% MemoryHigh={{ php_fpm_memory_high }}
MemoryMax=35% MemoryMax={{ php_fpm_memory_max }}
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View file

@ -1,9 +1,11 @@
# {{ ansible_managed }}
[Unit] [Unit]
After=network-online.target After=network-online.target
[Socket] [Socket]
SocketUser=%i SocketUser={{ php_fpm_socket_user | default('%i') }}
SocketGroup=%i SocketGroup={{ php_fpm_socket_group | default('%i') }}
SocketMode=0660 SocketMode=0660
ListenStream=/run/php/php-fpm-%i.sock ListenStream=/run/php/php-fpm-%i.sock