From 6b8eb88d973044276474f7f47fc9d9ce386949fe Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Thu, 17 Jul 2025 18:44:46 +0200 Subject: [PATCH 1/5] Php unix socket pr 1.x (#724) * Moving cachetool adapter setup to the installer role and adding a test. * Updating cachetool documentation. --- docs/roles/cache_clear/cache_clear-opcache.md | 9 ++----- docs/roles/cli/cachetool.md | 7 ++++++ .../cache_clear/cache_clear-opcache/README.md | 9 ++----- .../cache_clear-opcache/defaults/main.yml | 7 ------ .../cache_clear-opcache/tasks/main.yml | 18 -------------- roles/cli/cachetool/README.md | 7 ++++++ roles/cli/cachetool/defaults/main.yml | 7 ++++++ roles/cli/cachetool/tasks/main.yml | 24 +++++++++++++++++++ 8 files changed, 49 insertions(+), 39 deletions(-) diff --git a/docs/roles/cache_clear/cache_clear-opcache.md b/docs/roles/cache_clear/cache_clear-opcache.md index 267485f4..0dd8cfaf 100644 --- a/docs/roles/cache_clear/cache_clear-opcache.md +++ b/docs/roles/cache_clear/cache_clear-opcache.md @@ -1,6 +1,6 @@ # Opcache -Clear opcache. +Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first. @@ -10,16 +10,11 @@ Clear opcache. ```yaml --- cache_clear_opcache: - # Adapter string to use as argument. - # eg. - # --fcgi=127.0.0.1:9000 - # Leave blank to use /etc/cachetool.yml - # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. # Bins to clear. clear_opcache: true clear_apcu: false clear_stat: true - # cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined + # cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined ``` diff --git a/docs/roles/cli/cachetool.md b/docs/roles/cli/cachetool.md index 36d0a014..d3c5af0b 100644 --- a/docs/roles/cli/cachetool.md +++ b/docs/roles/cli/cachetool.md @@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user. --- cachetool: version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version. + unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision + # Adapter string to use as argument. + # e.g. + # --fcgi=127.0.0.1:9000 + # --fcgi=/var/run/php-fpm.sock + # Provide an empty string to use /etc/cachetool.yml + # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. ``` diff --git a/roles/cache_clear/cache_clear-opcache/README.md b/roles/cache_clear/cache_clear-opcache/README.md index 267485f4..0dd8cfaf 100644 --- a/roles/cache_clear/cache_clear-opcache/README.md +++ b/roles/cache_clear/cache_clear-opcache/README.md @@ -1,6 +1,6 @@ # Opcache -Clear opcache. +Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first. @@ -10,16 +10,11 @@ Clear opcache. ```yaml --- cache_clear_opcache: - # Adapter string to use as argument. - # eg. - # --fcgi=127.0.0.1:9000 - # Leave blank to use /etc/cachetool.yml - # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. # Bins to clear. clear_opcache: true clear_apcu: false clear_stat: true - # cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined + # cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined ``` diff --git a/roles/cache_clear/cache_clear-opcache/defaults/main.yml b/roles/cache_clear/cache_clear-opcache/defaults/main.yml index bf28c5b0..a9b9e92d 100644 --- a/roles/cache_clear/cache_clear-opcache/defaults/main.yml +++ b/roles/cache_clear/cache_clear-opcache/defaults/main.yml @@ -1,12 +1,5 @@ --- cache_clear_opcache: - # Adapter string to use as argument. - # e.g. - # --fcgi=127.0.0.1:9000 - # --fcgi=/var/run/php-fpm.sock - # Provide an empty string to use /etc/cachetool.yml - # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. - unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision # Bins to clear. clear_opcache: true clear_apcu: false diff --git a/roles/cache_clear/cache_clear-opcache/tasks/main.yml b/roles/cache_clear/cache_clear-opcache/tasks/main.yml index 56507c4a..ddf9fd07 100644 --- a/roles/cache_clear/cache_clear-opcache/tasks/main.yml +++ b/roles/cache_clear/cache_clear-opcache/tasks/main.yml @@ -1,22 +1,4 @@ --- -- name: Get latest php installed - ansible.builtin.shell: - cmd: 'set -o pipefail && ls -1 /etc/php/ | while read ver; do if [ -d "/etc/php/$ver/fpm" ]; then echo "$ver"; fi; done | tail -1' - args: - executable: /bin/bash - register: _php_version - -- name: Set cachetool adapter specified or default to a TCP/IP port. - ansible.builtin.set_fact: - _cachetool_adapter: "{{ cache_clear_opcache.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}" - -- name: Override cachetool adapter to be a Unix socket if requested. - ansible.builtin.set_fact: - _cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock" - when: - - cache_clear_opcache.unix_socket - - cache_clear_opcache.adapter is not defined - # cachetool_bin is set in the _init role. - name: Clear opcache. ansible.builtin.command: diff --git a/roles/cli/cachetool/README.md b/roles/cli/cachetool/README.md index 36d0a014..d3c5af0b 100644 --- a/roles/cli/cachetool/README.md +++ b/roles/cli/cachetool/README.md @@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user. --- cachetool: version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version. + unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision + # Adapter string to use as argument. + # e.g. + # --fcgi=127.0.0.1:9000 + # --fcgi=/var/run/php-fpm.sock + # Provide an empty string to use /etc/cachetool.yml + # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. ``` diff --git a/roles/cli/cachetool/defaults/main.yml b/roles/cli/cachetool/defaults/main.yml index 8b98934d..77c338ce 100644 --- a/roles/cli/cachetool/defaults/main.yml +++ b/roles/cli/cachetool/defaults/main.yml @@ -1,3 +1,10 @@ --- cachetool: version: "" # enter three-digit version number, e.g. "7.0.0", to install a specific version. If not specified, will be installed depending on the php version. + unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision + # Adapter string to use as argument. + # e.g. + # --fcgi=127.0.0.1:9000 + # --fcgi=/var/run/php-fpm.sock + # Provide an empty string to use /etc/cachetool.yml + # adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version. diff --git a/roles/cli/cachetool/tasks/main.yml b/roles/cli/cachetool/tasks/main.yml index c9855743..e7035c7c 100644 --- a/roles/cli/cachetool/tasks/main.yml +++ b/roles/cli/cachetool/tasks/main.yml @@ -83,3 +83,27 @@ - deploy_operation == 'deploy' - cachetool.version is defined - cachetool.version | length > 0 + +# Set up cachetool adapter +- name: Get latest PHP version installed. + ansible.builtin.shell: + cmd: 'set -o pipefail && ls -1 /etc/php/ | while read ver; do if [ -d "/etc/php/$ver/fpm" ]; then echo "$ver"; fi; done | tail -1' + args: + executable: /bin/bash + register: _php_version + +- name: Set cachetool adapter specified or default to a TCP/IP port. + ansible.builtin.set_fact: + _cachetool_adapter: "{{ cachetool.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}" + +- name: Override cachetool adapter to be a Unix socket if requested. + ansible.builtin.set_fact: + _cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock" + when: + - cachetool.unix_socket + - cachetool.adapter is not defined + +# We want to fail early if cachetool is broken. +- name: Ensure cachetool is working. + ansible.builtin.command: + cmd: "{{ cachetool_bin }} {{ _cachetool_adapter }} -n opcache:status" From dc7b24e3a5ec0083cb0f1ff7667941106db5f09a Mon Sep 17 00:00:00 2001 From: Greg Harvey Date: Thu, 17 Jul 2025 19:26:48 +0200 Subject: [PATCH 2/5] Php unix socket pr 1.x (#726) * Moving cachetool adapter setup to the installer role and adding a test. * Updating cachetool documentation. * Making sure _cachetool_adapter is always set. --- roles/_init/tasks/drupal7.yml | 2 +- roles/_init/tasks/drupal8.yml | 6 ++---- roles/cli/cachetool/tasks/main.yml | 25 ++++++++++++------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/roles/_init/tasks/drupal7.yml b/roles/_init/tasks/drupal7.yml index 3053c5c4..f6919125 100644 --- a/roles/_init/tasks/drupal7.yml +++ b/roles/_init/tasks/drupal7.yml @@ -11,7 +11,7 @@ import_role: name: cli/drush -- name: Ensure we have a cachetool binary. +- name: Ensure we have a cachetool binary and configuration. ansible.builtin.import_role: name: cli/cachetool when: install_php_cachetool diff --git a/roles/_init/tasks/drupal8.yml b/roles/_init/tasks/drupal8.yml index c254ffd6..afd1217b 100644 --- a/roles/_init/tasks/drupal8.yml +++ b/roles/_init/tasks/drupal8.yml @@ -11,9 +11,7 @@ ansible.builtin.set_fact: drush_live_bin: "{{ drush_live_bin | default('{{ live_symlink_dest }}/vendor/bin/drush') }}" -- name: Ensure we have a cachetool binary. +- name: Ensure we have a cachetool binary and configuration. ansible.builtin.import_role: name: cli/cachetool - when: - - install_php_cachetool - - deploy_operation == 'deploy' + when: install_php_cachetool diff --git a/roles/cli/cachetool/tasks/main.yml b/roles/cli/cachetool/tasks/main.yml index e7035c7c..d3a21cb2 100644 --- a/roles/cli/cachetool/tasks/main.yml +++ b/roles/cli/cachetool/tasks/main.yml @@ -1,17 +1,16 @@ --- -- name: Remove previous cachetool if exists. - ansible.builtin.file: - path: "{{ cachetool_bin }}" - state: absent - when: - - deploy_operation == 'deploy' +- name: Initial housekeeping tasks. + when: deploy_operation == 'deploy' + block: + - name: Remove previous cachetool if exists. + ansible.builtin.file: + path: "{{ cachetool_bin }}" + state: absent -- name: Ensure bin directory exists. - ansible.builtin.file: - path: "{{ cachetool_bin | dirname }}" - state: directory - when: - - deploy_operation == 'deploy' + - name: Ensure bin directory exists. + ansible.builtin.file: + path: "{{ cachetool_bin | dirname }}" + state: directory - name: Download cachetool depending on latest php version installed. # If not specified manually, according to https://github.com/gordalina/cachetool#compatibility when: @@ -84,7 +83,7 @@ - cachetool.version is defined - cachetool.version | length > 0 -# Set up cachetool adapter +# Set up cachetool adapter - needs to happen on every run so _cachetool_adapter is set. - name: Get latest PHP version installed. ansible.builtin.shell: cmd: 'set -o pipefail && ls -1 /etc/php/ | while read ver; do if [ -d "/etc/php/$ver/fpm" ]; then echo "$ver"; fi; done | tail -1' From e705aeec72dd857d242a0941e694ff45aa3dcbcb Mon Sep 17 00:00:00 2001 From: drazenCE <140631110+drazenCE@users.noreply.github.com> Date: Mon, 28 Jul 2025 16:32:05 +0200 Subject: [PATCH 3/5] Optional-drush-cr-before-import (#728) --- .../database_apply/database_apply-drupal8/tasks/main.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/roles/database_apply/database_apply-drupal8/tasks/main.yml b/roles/database_apply/database_apply-drupal8/tasks/main.yml index 1935ac79..7915d95f 100644 --- a/roles/database_apply/database_apply-drupal8/tasks/main.yml +++ b/roles/database_apply/database_apply-drupal8/tasks/main.yml @@ -108,6 +108,15 @@ msg: "{{ _drush_output }}" when: drupal.drush_verbose_output +- name: Clear cache before config import. + ansible.builtin.include_role: + name: "cache_clear/cache_clear-{{ project_type }}" + with_items: "{{ drupal.sites }}" + loop_control: + loop_var: site + when: + - drupal.clear_cache_before_config_import | default(false) + - name: Import configuration. ansible.builtin.command: cmd: "{{ drush_bin }} -l {{ site.folder }} -y {{ site.config_import_command }}" From d8029d998d9fab990e0ec720ccf79933c13222fe Mon Sep 17 00:00:00 2001 From: filip Date: Tue, 29 Jul 2025 09:30:42 +0200 Subject: [PATCH 4/5] skipping cachetool check when no fpm --- roles/cli/cachetool/tasks/main.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/roles/cli/cachetool/tasks/main.yml b/roles/cli/cachetool/tasks/main.yml index d3a21cb2..2b35a586 100644 --- a/roles/cli/cachetool/tasks/main.yml +++ b/roles/cli/cachetool/tasks/main.yml @@ -106,3 +106,5 @@ - name: Ensure cachetool is working. ansible.builtin.command: cmd: "{{ cachetool_bin }} {{ _cachetool_adapter }} -n opcache:status" + when: _php_version.stdout | length > 0 + From cae204b8b5799472abddb78d75b1ff863cd5eb71 Mon Sep 17 00:00:00 2001 From: filip Date: Tue, 29 Jul 2025 09:31:16 +0200 Subject: [PATCH 5/5] remove empty line --- roles/cli/cachetool/tasks/main.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/roles/cli/cachetool/tasks/main.yml b/roles/cli/cachetool/tasks/main.yml index 2b35a586..0c221115 100644 --- a/roles/cli/cachetool/tasks/main.yml +++ b/roles/cli/cachetool/tasks/main.yml @@ -107,4 +107,3 @@ ansible.builtin.command: cmd: "{{ cachetool_bin }} {{ _cachetool_adapter }} -n opcache:status" when: _php_version.stdout | length > 0 -