Skip to content

Commit e21810a

Browse files
committed
Perform graceful stops on PHP-FPM
The default signal used by docker to stop a container is SIGTERM and that signal is understood by PHP-FPM as immediate termination. This means that `php-fpm` won't wait for in-flight requests to finish before of stopping the workers and main process. This behaviour is quite undesired for production environments and should be avoided as much as possible. This implementation is meant to be extremely simple and only address the stop signal used when running `docker stop`. `php-fpm` signal choices are somewhat peculiar (`SIGUSR2` for example) and if we want to "fix" them we would have to use a tool (e.g.: `dumb-init`). More info: - https://linux.die.net/man/8/php-fpm - https://docs.docker.com/engine/reference/builder/#stopsignal - https://github.com/Yelp/dumb-init - usabilla/php-docker-template#102
1 parent cf02ea0 commit e21810a

File tree

11 files changed

+66
-0
lines changed

11 files changed

+66
-0
lines changed

7.1/alpine3.8/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,11 @@ RUN set -ex \
213213
} | tee php-fpm.d/zz-docker.conf
214214

215215
EXPOSE 9000
216+
217+
# Override stop signal to stop process gracefully
218+
#
219+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
220+
STOPSIGNAL SIGQUIT
221+
216222
CMD ["php-fpm"]
217223
##</autogenerated>##

7.1/alpine3.9/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,5 +213,11 @@ RUN set -ex \
213213
} | tee php-fpm.d/zz-docker.conf
214214

215215
EXPOSE 9000
216+
217+
# Override stop signal to stop process gracefully
218+
#
219+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
220+
STOPSIGNAL SIGQUIT
221+
216222
CMD ["php-fpm"]
217223
##</autogenerated>##

7.1/jessie/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,11 @@ RUN set -ex \
239239
} | tee php-fpm.d/zz-docker.conf
240240

241241
EXPOSE 9000
242+
243+
# Override stop signal to stop process gracefully
244+
#
245+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
246+
STOPSIGNAL SIGQUIT
247+
242248
CMD ["php-fpm"]
243249
##</autogenerated>##

7.1/stretch/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,11 @@ RUN set -ex \
239239
} | tee php-fpm.d/zz-docker.conf
240240

241241
EXPOSE 9000
242+
243+
# Override stop signal to stop process gracefully
244+
#
245+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
246+
STOPSIGNAL SIGQUIT
247+
242248
CMD ["php-fpm"]
243249
##</autogenerated>##

7.2/alpine3.8/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,11 @@ RUN set -ex \
222222
} | tee php-fpm.d/zz-docker.conf
223223

224224
EXPOSE 9000
225+
226+
# Override stop signal to stop process gracefully
227+
#
228+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
229+
STOPSIGNAL SIGQUIT
230+
225231
CMD ["php-fpm"]
226232
##</autogenerated>##

7.2/alpine3.9/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,11 @@ RUN set -ex \
222222
} | tee php-fpm.d/zz-docker.conf
223223

224224
EXPOSE 9000
225+
226+
# Override stop signal to stop process gracefully
227+
#
228+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
229+
STOPSIGNAL SIGQUIT
230+
225231
CMD ["php-fpm"]
226232
##</autogenerated>##

7.2/stretch/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,11 @@ RUN set -ex \
261261
} | tee php-fpm.d/zz-docker.conf
262262

263263
EXPOSE 9000
264+
265+
# Override stop signal to stop process gracefully
266+
#
267+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
268+
STOPSIGNAL SIGQUIT
269+
264270
CMD ["php-fpm"]
265271
##</autogenerated>##

7.3/alpine3.8/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,11 @@ RUN set -ex \
224224
} | tee php-fpm.d/zz-docker.conf
225225

226226
EXPOSE 9000
227+
228+
# Override stop signal to stop process gracefully
229+
#
230+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
231+
STOPSIGNAL SIGQUIT
232+
227233
CMD ["php-fpm"]
228234
##</autogenerated>##

7.3/alpine3.9/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,11 @@ RUN set -ex \
224224
} | tee php-fpm.d/zz-docker.conf
225225

226226
EXPOSE 9000
227+
228+
# Override stop signal to stop process gracefully
229+
#
230+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
231+
STOPSIGNAL SIGQUIT
232+
227233
CMD ["php-fpm"]
228234
##</autogenerated>##

7.3/stretch/fpm/Dockerfile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,11 @@ RUN set -ex \
263263
} | tee php-fpm.d/zz-docker.conf
264264

265265
EXPOSE 9000
266+
267+
# Override stop signal to stop process gracefully
268+
#
269+
# https://github.com/php/php-src/blob/17baa87faddc2550def3ae7314236826bc1b1398/sapi/fpm/php-fpm.8.in#L163
270+
STOPSIGNAL SIGQUIT
271+
266272
CMD ["php-fpm"]
267273
##</autogenerated>##

0 commit comments

Comments
 (0)