Skip to content

Commit 932fbc0

Browse files
committed
dynamic pool config
1 parent 3fa0dc8 commit 932fbc0

File tree

3 files changed

+17
-19
lines changed

3 files changed

+17
-19
lines changed

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ PHPFPM_POOL_API_GROUP=www-data
196196

197197
Each pool will be configured in `/etc/php.../pools.d/<poolname>.conf` inside the container.
198198

199+
If no pool is defined then a default `www` pool will be created with the following default settings
200+
199201
Default pool settings:
202+
200203
| Variable | Description | Default |
201204
| --------------------------------------------- | ---------------------------------- | ----------------------------------- |
202205
| `PHPFPM_POOL_DEFAULT_LISTEN_UNIX_GROUP` | Default UNIX group for pool | `${NGINX_GROUP}` |
@@ -337,11 +340,11 @@ For Xdebug 3 (php >= 7.2) you should set:
337340

338341
## Users and Groups
339342

340-
| Type | Name | ID |
341-
| ----- | --------------- | ---- |
342-
| User | `php` | `9000` |
343-
| Group | `php` | `9000` |
344-
| Group | `www-data` | `82` |
343+
| Type | Name | ID |
344+
| ----- | ---------- | ------ |
345+
| User | `php` | `9000` |
346+
| Group | `php` | `9000` |
347+
| Group | `www-data` | `82` |
345348

346349
### Networking
347350

rootfs/container/functions/20-php-fpm

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,19 @@ phpfpm_configure_nginx() {
104104

105105
phpfpm_configure_nginx_php() {
106106
local nginxphpconf_value
107-
if [ -v NGINX_${site^^}_PHP_UPSTREAM ] ; then
107+
if [ -v NGINX_${site^^}_PHP_UPSTREAM ]; then
108108
nginxphpconf_value="$(set -o posix ; set | grep "NGINX_${site^^}_PHP_UPSTREAM=" | cut -d = -f 2)"
109109
else
110-
if [ -n "${PHPFPM_POOL_WWW_LISTEN_TYPE}" ]; then
111-
nginxphpconf_value=www
112-
ln -sf /etc/nginx/snippets/server.available/php-fpm/www.conf /etc/nginx/snippets/server.available/php-fpm.conf
113-
else
114-
nginxphpconf_value="$(set -o posix ; set | sort | grep "^PHPFPM_POOL_.*" | sed -n "s/^PHPFPM_POOL_\([^_]*\)_.*$/\1/p" | sed -e "/^DEFAULT/d" | uniq)"
115-
ln -sf /etc/nginx/snippets/server.available/php-fpm/${nginxphpconf_value}.conf /etc/nginx/snippets/server.available/php-fpm.conf
110+
nginxphpconf_value=www
116111
fi
112+
ln -sf /etc/nginx/snippets/server.available/php-fpm/${nginxphpconf_value}.conf /etc/nginx/snippets/server.available/php-fpm.conf
117113

118114
if [ -f "${site_path}" ] && [ -f /etc/nginx/snippets/server.available/php-fpm/"${nginxphpconf_value}".conf ]; then
119115
sed -i \
120116
-e "s|include /etc/nginx/snippets/server.available/php-fpm.*;|include /etc/nginx/snippets/server.available/php-fpm/${nginxphpconf_value}.conf;|g" \
121-
"${site_path}"
122-
fi
117+
"${site_path}"
118+
PHP_UPSTREAM=${nginxphpconf_value}
119+
update_template "${site_path}" PHP_UPSTREAM
123120
fi
124121
}
125122

@@ -165,15 +162,12 @@ EOF
165162
echo " server ${_php_fpm_upstream_host_socket_prefix}${_php_fpm_upstream} $(set -o posix ; set | grep -oE "^PHPFPM_UPSTREAM_${1^^}_OPTIONS=" | cut -d = -f2-);" | silent tee -a /etc/nginx/snippets/upstream.available/upstream-phpfpm-${1,,}.conf
166163
done
167164
echo "}" | silent tee -a /etc/nginx/snippets/upstream.available/upstream-phpfpm-${1,,}.conf
168-
set +x
169165
sed -i \
170166
-e "/# Do not delete - Upstream Configuration/a\ \ \ \ include \/etc\/nginx\/snippets\/upstream.available\/upstream-phpfpm-${1,,}.conf;" \
171167
-e "/# Do not delete - Upstream Configuration/a\ \ \ \ ### PHP-FPM Multiple Handlers configuration" \
172168
/etc/nginx/nginx.conf
173-
set +x
174169
}
175170

176-
177171
phpfpm_configure_pools() {
178172
local _phpfpm_pools
179173
local _phpfpm_pool_vars
@@ -191,6 +185,7 @@ phpfpm_configure_pools() {
191185

192186
if [ "$(set -o posix ; set | sort | grep "^PHPFPM_POOL_.*" | sed -n "s/^PHPFPM_POOL_\([^_]*\)_.*$/\1/p" | uniq | wc -l)" -eq 1 ] ; then
193187
export PHPFPM_POOL_WWW_LISTEN_TYPE="${PHPFPM_POOL_DEFAULT_LISTEN_TYPE}"
188+
## TODO - need to find a way to dynamically set this in nginx /sites.enabled or other file - NGINX_SITE_... PHPFPM_POOL_NGINX_SITE?
194189
fi
195190

196191
for phpfpm_pool in $(set -o posix ; set | sort | grep "^PHPFPM_POOL_.*_LISTEN_TYPE" | sed -n "s/^PHPFPM_POOL_\([^_]*\)_.*$/\1/p" | sed "/^DEFAULT/d" ) ; do
@@ -398,7 +393,7 @@ phpfpm_configure_site_default() {
398393

399394
### Populate your custom directives here
400395
location ~ \.php(/|\$) {
401-
include /etc/nginx/snippets/server.available/php-fpm.conf;
396+
include /etc/nginx/snippets/server.available/php-fpm/${PHP_UPSTREAM}.conf;
402397
fastcgi_split_path_info ^(.+?\.php)(/.+)\$;
403398
fastcgi_param PATH_INFO \$fastcgi_path_info;
404399
fastcgi_index index.php;

rootfs/container/init/init.d/20-php-fpm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ case "${PHPFPM_CONTAINER_MODE,,}" in
4040
;;
4141
esac
4242

43-
if [ ! -f "/container/state/restart" ] ; then
43+
if check_container_restarted; then
4444
#phpfpm_bootstrap_filesystem
4545
phpfpm_bootstrap
4646
phpfpm_configure_logging

0 commit comments

Comments
 (0)