Skip to content

Commit 9bf37f7

Browse files
fix: improve Graceful Shutdown & its Java example
1 parent 7a14d1b commit 9bf37f7

10 files changed

+28
-6
lines changed

.env.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["./shared/nginx-error-logs:/var/log/ngin
6161
# Check if the host folder or file exists
6262
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
6363

64+
DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD=40s
65+
6466
NGINX_CLIENT_MAX_BODY_SIZE=50M
6567

6668
# Format : docker-compose-${project_name}-original-ready.yml

.env.example.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
DOCKER_COMPOSE_ENVIRONMENT={"TZ":"Asia/Seoul"}
4545
# This goes with "docker build ... in the 'run.sh' script file", and the command always contain "HOST_IP" and "APP_ENV" above.
4646
# docker exec -it CONTAINER_NAME cat /var/log/env_build_args.log
47-
DOCKER_BUILD_ARGS={"DOCKER_BUILDKIT":"1","PROJECT_ROOT_IN_CONTAINER":"/var/www/server/spring-sample-h-auth","FILE_STORAGE_ROOT_IN_CONTAINER":"/var/www/files","APP_ENV":"production"}
47+
DOCKER_BUILD_ARGS={"DOCKER_BUILDKIT":"1","PROJECT_ROOT_IN_CONTAINER":"/var/www/server/spring-sample-h-auth","FILE_STORAGE_ROOT_IN_CONTAINER":"/var/www/files","APP_ENV":"production","JVM_XMS":"1024","JVM_XMX":"2048"}
4848
DOCKER_BUILD_LABELS=["foo=happy","bar=sad"]
4949
# For Mac like, EX. DOCKER_BUILD_ADDITIONAL_RAW_PARAMS=--platform linux/amd64
5050
DOCKER_BUILD_ADDITIONAL_RAW_PARAMS=--platform linux/amd64
@@ -54,6 +54,8 @@
5454
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["./shared/nginx-error-logs:/var/log/nginx"]
5555
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5656

57+
DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD=40s
58+
5759
NGINX_CLIENT_MAX_BODY_SIZE=50M
5860

5961
USE_MY_OWN_APP_YML=false

.env.example.java.commercial.ssl.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ DOCKER_COMPOSE_SELECTIVE_VOLUMES=["/var/web/files/spring-sample-h-auth:/var/www/
5454
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["/var/web/files/nginx/spring-sample-h-auth/logs:/var/log/nginx"]
5555
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5656

57+
DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD=40s
58+
5759
NGINX_CLIENT_MAX_BODY_SIZE=50M
5860

5961
USE_MY_OWN_APP_YML=false

.env.example.node

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=[]
4949
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5050
DOCKER_COMPOSE_SELECTIVE_VOLUMES=[]
5151

52+
DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD=40s
53+
5254
NGINX_CLIENT_MAX_BODY_SIZE=50M
5355

5456
USE_MY_OWN_APP_YML=false

.env.example.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
DOCKER_COMPOSE_NGINX_SELECTIVE_VOLUMES=["./shared/nginx-error-logs:/var/log/nginx"]
5656
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
5757

58+
DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD=40s
59+
5860
NGINX_CLIENT_MAX_BODY_SIZE=50M
5961

6062
USE_MY_OWN_APP_YML=false

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,11 @@ GOOD_APP_HEALTH_CHECK_PATTERN=UP
288288
DOCKER_COMPOSE_SELECTIVE_VOLUMES=["/my-host/files/:/in-container/files", "/my-host/java-spring-project/src/main/resources:/in-container/java-spring-project/src/main/resources"]
289289
# Check if the host folder or file exists
290290
DOCKER_COMPOSE_HOST_VOLUME_CHECK=false
291+
292+
# Currently, a graceful shutdown example is only provided for the Java sample. To enable graceful termination, make sure to handle SIGTERM in both your application and the Dockerfile.
293+
# Refer to "docker-compose-app-original.yml" which uses this property.
294+
DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD=40s
295+
291296
# If APP_ENV is set to 'local', as specified in 'docker-compose-app-original.yml', synchronize your entire project as follows: "HOST_ROOT_LOCATION:PROJECT_LOCATION".
292297
# [IMPORTANT] If this is set to true, Nginx will be restarted, resulting in a short downtime.
293298
# This option should be used when upgrading the Runner. See the "Upgrade" section below.

docker-compose-app-original.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ services:
1919
# If the process does not terminate within this grace period,
2020
# Docker sends a SIGKILL signal to terminate the process forcibly.
2121
stop_signal: SIGTERM
22-
stop_grace_period: 40s
22+
stop_grace_period: ${DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD}
2323
${PROJECT_NAME}-green:
2424
container_name: ${PROJECT_NAME}-green
2525
stdin_open: true
@@ -36,7 +36,7 @@ services:
3636
- .env
3737
volumes: []
3838
stop_signal: SIGTERM
39-
stop_grace_period: 40s
39+
stop_grace_period: ${DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD}
4040
networks:
4141
dbgr-net:
4242
external:

docker-stack-app-original-blue.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ services:
1313
replicas: 2
1414
networks:
1515
- dbgr-net
16+
stop_signal: SIGTERM
17+
stop_grace_period: ${DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD}
1618
networks:
1719
dbgr-net:
1820
external: true

docker-stack-app-original-green.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ services:
1313
replicas: 2
1414
networks:
1515
- dbgr-net
16+
stop_signal: SIGTERM
17+
stop_grace_period: ${DOCKER_COMPOSE_STOP_GRACEFUL_SHUTDOWN_PERIOD}
1618
networks:
1719
dbgr-net:
1820
external: true

samples/spring-sample-h-auth/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ WORKDIR $PROJECT_ROOT_IN_CONTAINER
2424
RUN cp $PROJECT_ROOT_IN_CONTAINER/target/*.jar /app.jar
2525

2626
RUN ln -s $PROJECT_ROOT_IN_CONTAINER/.docker/entrypoint/run-app.sh /run-app.sh
27+
RUN chmod 755 /run-app.sh
2728

2829
# dumb-init added!
29-
RUN apk --no-cache add curl bash dumb-init
30+
RUN apk update && apk add --no-cache bash curl dumb-init
3031

3132
# dumb-init : https://engineeringblog.yelp.com/2016/01/dumb-init-an-init-for-docker.html
32-
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/my/script"]
33+
##ENTRYPOINT ["/usr/bin/dumb-init", "--", "/my/script"]
3334

3435
ENV PROJECT_ROOT_IN_CONTAINER=$PROJECT_ROOT_IN_CONTAINER
3536
ENV FILE_STORAGE_ROOT_IN_CONTAINER=$FILE_STORAGE_ROOT_IN_CONTAINER
3637
ENV JVM_XMS=$JVM_XMS
3738
ENV JVM_XMX=$JVM_XMX
3839

39-
ENTRYPOINT sh /run-app.sh $PROJECT_ROOT_IN_CONTAINER $FILE_STORAGE_ROOT_IN_CONTAINER $JVM_XMS $JVM_XMX && /bin/sh
40+
#ENTRYPOINT ["/usr/bin/dumb-init", "--", "/my/script"]
41+
#ENTRYPOINT sh /run-app.sh $PROJECT_ROOT_IN_CONTAINER $FILE_STORAGE_ROOT_IN_CONTAINER $JVM_XMS $JVM_XMX && /bin/sh
42+
ENTRYPOINT ["/usr/bin/dumb-init", "--", "sh", "-c", "/run-app.sh $PROJECT_ROOT_IN_CONTAINER $FILE_STORAGE_ROOT_IN_CONTAINER $JVM_XMS $JVM_XMX && exec /bin/sh"]

0 commit comments

Comments
 (0)