Skip to content

Commit

Permalink
MID-8490: add SIG handling to midpoint.sh - to pass signal to the chi…
Browse files Browse the repository at this point in the history
…ld process /shell/
  • Loading branch information
cz-help committed Oct 2, 2023
1 parent 89ead92 commit 0d04ef1
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions dist/src/main/bin/midpoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,37 @@ ENV_MAP_PREFIX="MP_SET_"
ENV_UNMAP_PREFIX="MP_UNSET_"

######################

# Handling SIGnals
######################
#
# Without this definition the signal received by bash (script) is silently
# ignored - not passed to child processes.
#
######################
_sigterm() {
echo " :SIGNAL PROCESSING: Receiving SIGTERM signal! Passing to the midPoint instance." >&2
if [ -s "${PID_FILE}" ]
then
kill -TERM $(cat "${PID_FILE}") 2>/dev/null
else
echo "Unfortunatelly the PID file is empty..." >&2
fi
}

trap _sigterm SIGTERM

_sigkill() {
echo " : SIGNAL PROCESSING: Receiving SIGKILL signal! Passing to the midPoint instance." >&2
if [ -s "${PID_FILE}" ]
then
kill -KILL $(cat "${PID_FILE}") 2>/dev/null
else
echo "Unfortunatelly the PID file is empty..." >&2
fi
}

trap _sigkill SIGKILL
######################
set -eu

if [[ -z ${1:-} ]]; then
Expand Down Expand Up @@ -426,14 +456,22 @@ if [[ "$1" == "container" ]]; then
if [ "${1:-}" = "" ]; then
eval "\"${_RUNJAVA}\"" \
${JAVA_OPTS} \
-jar "\"${BASE_DIR}/lib/midpoint.jar\"" 2>&1
-jar "\"${BASE_DIR}/lib/midpoint.jar\"" "&" 2>&1
else
eval "\"${_RUNJAVA}\"" \
${JAVA_OPTS} \
-jar "\"${BASE_DIR}/lib/midpoint.jar\"" \
"$@" 2>&1
"$@" "&" 2>&1
fi

if [[ -n "${PID_FILE}" ]]; then
echo $! >"${PID_FILE}"
wait $(cat ${PID_FILE})
else
wait $!
fi

echo "The midPoint process has been terminated..." >&2
fi
# ----- Execute The Requested Command -----------------------------------------

Expand Down

0 comments on commit 0d04ef1

Please sign in to comment.