Skip to content

Commit

Permalink
[FLINK-17470] Send sigkill to hanging processes in standalone scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
rmetzger committed Nov 16, 2020
1 parent 4e74e08 commit 30ae028
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions flink-dist/src/main/flink-bin/bin/flink-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ out="${FLINK_LOG_PREFIX}.out"

log_setting=("-Dlog.file=${log}" "-Dlog4j.configuration=file:${FLINK_CONF_DIR}/log4j.properties" "-Dlog4j.configurationFile=file:${FLINK_CONF_DIR}/log4j.properties" "-Dlogback.configurationFile=file:${FLINK_CONF_DIR}/logback.xml")

function guaranteed_kill {
to_stop_pid=$1
daemon=$2

# send sigterm for graceful shutdown
kill $to_stop_pid
# wait 10 seconds for process to stop. By default, Flink kills the JVM 5 seconds after sigterm.
timeout 10 tail --pid=$to_stop_pid -f /dev/null
if [ "$?" -eq 124 ]; then
echo "Daemon $daemon didn't stop within 10 seconds. Killing it."
# send sigkill
kill -9 $to_stop_pid
fi
}

case $STARTSTOP in

(start)
Expand Down Expand Up @@ -142,7 +157,7 @@ case $STARTSTOP in

if kill -0 $to_stop > /dev/null 2>&1; then
echo "Stopping $DAEMON daemon (pid: $to_stop) on host $HOSTNAME."
kill $to_stop
guaranteed_kill $to_stop $DAEMON
else
echo "No $DAEMON daemon (pid: $to_stop) is running anymore on $HOSTNAME."
fi
Expand All @@ -159,7 +174,7 @@ case $STARTSTOP in
while read to_stop; do
if kill -0 $to_stop > /dev/null 2>&1; then
echo "Stopping $DAEMON daemon (pid: $to_stop) on host $HOSTNAME."
kill $to_stop
guaranteed_kill $to_stop $DAEMON
else
echo "Skipping $DAEMON daemon (pid: $to_stop), because it is not running anymore on $HOSTNAME."
fi
Expand Down

0 comments on commit 30ae028

Please sign in to comment.