From 782592e612b10922d5ed84053a82145ddea2623b Mon Sep 17 00:00:00 2001 From: Yasassri Ratnayake Date: Fri, 1 Oct 2021 07:40:32 +0530 Subject: [PATCH] Gracefully handle SIGTERM by trapping the signal --- dockerfiles/alpine/apim/docker-entrypoint.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/dockerfiles/alpine/apim/docker-entrypoint.sh b/dockerfiles/alpine/apim/docker-entrypoint.sh index 2bf2dcfc..eab13340 100755 --- a/dockerfiles/alpine/apim/docker-entrypoint.sh +++ b/dockerfiles/alpine/apim/docker-entrypoint.sh @@ -65,9 +65,19 @@ test -d ${artifact_volume} && [[ "$(ls -A ${artifact_volume})" ]] && cp -RL ${ar echo "Start WSO2 Carbon server" >&2 if [[ -z "${PROFILE_NAME}" ]] then + # Trapping Kill Signals and killing the leaf process + trap 'echo kill signal received!; kill -TERM $(tr -d "\0" < ${WSO2_SERVER_HOME}/wso2carbon.pid); wait' TERM INT # start the server with the provided startup arguments - sh ${WSO2_SERVER_HOME}/bin/api-manager.sh "$@" + ${WSO2_SERVER_HOME}/bin/api-manager.sh "$@" & + # Waiting for the Subprocess to finish + PID=$! + wait $PID else + # Trapping Kill Signals and killing the leaf process + trap 'echo kill signal received!; kill -TERM $(tr -d "\0" < ${WSO2_SERVER_HOME}/wso2carbon.pid); wait' TERM INT # start the server with the specified profile and provided startup arguments - sh ${WSO2_SERVER_HOME}/bin/api-manager.sh -Dprofile=${PROFILE_NAME} "$@" + sh ${WSO2_SERVER_HOME}/bin/api-manager.sh -Dprofile=${PROFILE_NAME} "$@" & + # Waiting for the Subprocess to finish + PID=$! + wait $PID fi