Skip to content

Commit 6b8eb88

Browse files
authored
Php unix socket pr 1.x (#724)
* Moving cachetool adapter setup to the installer role and adding a test. * Updating cachetool documentation.
1 parent 4ded121 commit 6b8eb88

File tree

8 files changed

+49
-39
lines changed

8 files changed

+49
-39
lines changed

docs/roles/cache_clear/cache_clear-opcache.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Opcache
22

3-
Clear opcache.
3+
Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first.
44

55
<!--TOC-->
66
<!--ENDTOC-->
@@ -10,16 +10,11 @@ Clear opcache.
1010
```yaml
1111
---
1212
cache_clear_opcache:
13-
# Adapter string to use as argument.
14-
# eg.
15-
# --fcgi=127.0.0.1:9000
16-
# Leave blank to use /etc/cachetool.yml
17-
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
1813
# Bins to clear.
1914
clear_opcache: true
2015
clear_apcu: false
2116
clear_stat: true
22-
# cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined
17+
# cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined
2318

2419
```
2520

docs/roles/cli/cachetool.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user.
66
---
77
cachetool:
88
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.
9+
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
10+
# Adapter string to use as argument.
11+
# e.g.
12+
# --fcgi=127.0.0.1:9000
13+
# --fcgi=/var/run/php-fpm.sock
14+
# Provide an empty string to use /etc/cachetool.yml
15+
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
916

1017
```
1118

roles/cache_clear/cache_clear-opcache/README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Opcache
22

3-
Clear opcache.
3+
Clear opcache. You must have run the `cli/cachetool` role to install `cachetool` first.
44

55
<!--TOC-->
66
<!--ENDTOC-->
@@ -10,16 +10,11 @@ Clear opcache.
1010
```yaml
1111
---
1212
cache_clear_opcache:
13-
# Adapter string to use as argument.
14-
# eg.
15-
# --fcgi=127.0.0.1:9000
16-
# Leave blank to use /etc/cachetool.yml
17-
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
1813
# Bins to clear.
1914
clear_opcache: true
2015
clear_apcu: false
2116
clear_stat: true
22-
# cachetool_bin: "/path/to/cachetool.phar" # see _init for paths if undefined
17+
# cachetool_bin: "/path/to/cachetool.phar" # see _init for default paths if undefined
2318

2419
```
2520

roles/cache_clear/cache_clear-opcache/defaults/main.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,5 @@
11
---
22
cache_clear_opcache:
3-
# Adapter string to use as argument.
4-
# e.g.
5-
# --fcgi=127.0.0.1:9000
6-
# --fcgi=/var/run/php-fpm.sock
7-
# Provide an empty string to use /etc/cachetool.yml
8-
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
9-
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
103
# Bins to clear.
114
clear_opcache: true
125
clear_apcu: false

roles/cache_clear/cache_clear-opcache/tasks/main.yml

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
11
---
2-
- name: Get latest php installed
3-
ansible.builtin.shell:
4-
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'
5-
args:
6-
executable: /bin/bash
7-
register: _php_version
8-
9-
- name: Set cachetool adapter specified or default to a TCP/IP port.
10-
ansible.builtin.set_fact:
11-
_cachetool_adapter: "{{ cache_clear_opcache.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}"
12-
13-
- name: Override cachetool adapter to be a Unix socket if requested.
14-
ansible.builtin.set_fact:
15-
_cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock"
16-
when:
17-
- cache_clear_opcache.unix_socket
18-
- cache_clear_opcache.adapter is not defined
19-
202
# cachetool_bin is set in the _init role.
213
- name: Clear opcache.
224
ansible.builtin.command:

roles/cli/cachetool/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ Installs the `drush` command-line tool for the deploy user.
66
---
77
cachetool:
88
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.
9+
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
10+
# Adapter string to use as argument.
11+
# e.g.
12+
# --fcgi=127.0.0.1:9000
13+
# --fcgi=/var/run/php-fpm.sock
14+
# Provide an empty string to use /etc/cachetool.yml
15+
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.
916

1017
```
1118

roles/cli/cachetool/defaults/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
---
22
cachetool:
33
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.
4+
unix_socket: false # Set to true to use automatic detection of Unix socket as set by ce-provision
5+
# Adapter string to use as argument.
6+
# e.g.
7+
# --fcgi=127.0.0.1:9000
8+
# --fcgi=/var/run/php-fpm.sock
9+
# Provide an empty string to use /etc/cachetool.yml
10+
# adapter: "--fcgi=127.0.0.1:9081" # Leave commented to automatically detect the adapter based on PHP version.

roles/cli/cachetool/tasks/main.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,27 @@
8383
- deploy_operation == 'deploy'
8484
- cachetool.version is defined
8585
- cachetool.version | length > 0
86+
87+
# Set up cachetool adapter
88+
- name: Get latest PHP version installed.
89+
ansible.builtin.shell:
90+
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'
91+
args:
92+
executable: /bin/bash
93+
register: _php_version
94+
95+
- name: Set cachetool adapter specified or default to a TCP/IP port.
96+
ansible.builtin.set_fact:
97+
_cachetool_adapter: "{{ cachetool.adapter | default('--fcgi=127.0.0.1:90' + _php_version.stdout | replace('.','')) }}"
98+
99+
- name: Override cachetool adapter to be a Unix socket if requested.
100+
ansible.builtin.set_fact:
101+
_cachetool_adapter: "--fcgi=/var/run/php{{ _php_version.stdout | replace('.','') }}-fpm.sock"
102+
when:
103+
- cachetool.unix_socket
104+
- cachetool.adapter is not defined
105+
106+
# We want to fail early if cachetool is broken.
107+
- name: Ensure cachetool is working.
108+
ansible.builtin.command:
109+
cmd: "{{ cachetool_bin }} {{ _cachetool_adapter }} -n opcache:status"

0 commit comments

Comments
 (0)