Skip to content

Commit 62f8c24

Browse files
authored
Merge pull request #102 from usabilla/php-fpm/translate-signals
PHP-FPM translate Kill Signals
2 parents eee3121 + 15c6f8e commit 62f8c24

File tree

5 files changed

+56
-11
lines changed

5 files changed

+56
-11
lines changed

Dockerfile-fpm

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ RUN set -x \
99

1010
# Install docker help scripts
1111
COPY src/php/utils/docker/ /usr/local/bin/
12+
COPY src/php/utils/install-* /usr/local/bin/
1213

1314
# Install PHP extensions
1415
RUN apk add --no-cache --virtual .phpize-deps $PHPIZE_DEPS \
@@ -32,17 +33,15 @@ COPY src/gpg /usr/local/etc/gpg
3233
COPY src/php/conf/ /usr/local/etc/php/conf.d/
3334
COPY src/php/fpm/conf/*.conf /usr/local/etc/php-fpm.d/
3435

35-
# Install shush
36-
COPY src/php/utils/install-shush /usr/local/bin/
37-
RUN install-shush && rm -rf /usr/local/bin/install-shush
38-
39-
# Install composer
40-
COPY src/php/utils/install-composer /usr/local/bin/
41-
RUN install-composer && rm -rf /usr/local/bin/install-composer
36+
# Install shush, dumb-init and composer
37+
RUN install-shush && rm -f /usr/local/bin/install-shush \
38+
&& install-dumb-init && rm -f /usr/local/bin/install-dumb-init \
39+
&& install-composer && rm -f /usr/local/bin/install-composer
4240

4341
STOPSIGNAL SIGTERM
4442

45-
CMD ["/usr/local/bin/shush", "exec", "php-fpm", "--force-stderr"]
43+
ENTRYPOINT [ "docker-php-entrypoint-init" ]
44+
CMD ["--force-stderr"]
4645

4746
# Base images don't need healthcheck since they are not running applications
4847
# this can be overriden in the child images
@@ -56,6 +55,3 @@ FROM fpm as fpm-dev
5655
# Install Xdebug and development specific configuration
5756
RUN docker-php-dev-mode xdebug \
5857
&& docker-php-dev-mode config
59-
60-
# Change entrypoint back to the default because we don't need shush in development
61-
CMD ["docker-php-entrypoint", "--force-stderr"]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/sh
2+
set -e
3+
4+
# first arg is `-f` or `--some-option` or if it's empty
5+
if [ -z "$1" ] || [ "${1#-}" != "$1" ]; then
6+
set -- php-fpm "$@"
7+
fi
8+
9+
if [ "$1" = php-fpm ]; then
10+
if env | grep -E "^KMS_ENCRYPTED"; then
11+
set -- shush exec -- "$@"
12+
fi
13+
14+
# Rewrite SIGINT to SIGQUIT
15+
# Rewrite SIGTERM to SIGQUIT
16+
# Rewrite SIGHUP to SIGUSR2
17+
set -- dumb-init --rewrite 2:3 --rewrite 15:3 --rewrite 1:17 -- "$@"
18+
fi
19+
20+
exec "$@"

src/php/utils/install-dumb-init

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
set -xeu
4+
5+
VERSION="1.2.2"
6+
7+
curl -sL -o /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v"$VERSION"/dumb-init_"$VERSION"_amd64
8+
9+
chmod +x /usr/local/bin/dumb-init
10+
11+
dumb-init --version
12+
13+
RESULT=$?
14+
15+
exit $RESULT
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
3+
4+
@pytest.mark.php_fpm_exec
5+
def test_php_fpm_exec_has_dumb_init(host):
6+
php_fpm_exec = host.run("ps 1")
7+
8+
assert "dumb-init" in php_fpm_exec.stdout
9+
assert "--rewrite 2:3" in php_fpm_exec.stdout
10+
assert "--rewrite 15:3" in php_fpm_exec.stdout
11+
assert "--rewrite 1:17" in php_fpm_exec.stdout
12+
13+
assert "shush" not in php_fpm_exec.stdout

test/container/php/test_helper_scripts.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def test_php_images_contain_helper_scripts(host):
1111
"/usr/local/bin/docker-php-ext-pdo-pgsql",
1212
"/usr/local/bin/docker-php-ext-rdkafka",
1313
"/usr/local/bin/docker-php-entrypoint",
14+
"/usr/local/bin/docker-php-entrypoint-init",
1415
"/usr/local/bin/php-fpm-healthcheck",
1516
]
1617

0 commit comments

Comments
 (0)