Add termination timeout to run_app_paas.sh

This commit is contained in:
bandesz
2017-02-28 17:38:34 +00:00
parent 70a239b023
commit b453dd59d0

View File

@@ -2,6 +2,8 @@
set -e -o pipefail set -e -o pipefail
TERMINATE_TIMEOUT=30
function check_params { function check_params {
if [ -z "${NOTIFY_APP_NAME}" ]; then if [ -z "${NOTIFY_APP_NAME}" ]; then
echo "You must set NOTIFY_APP_NAME" echo "You must set NOTIFY_APP_NAME"
@@ -38,11 +40,18 @@ EOF
function on_exit { function on_exit {
echo "Terminating application process with pid ${APP_PID}" echo "Terminating application process with pid ${APP_PID}"
kill ${APP_PID} || true kill ${APP_PID} || true
n=0
while (kill -0 ${APP_PID} 2&>/dev/null); do while (kill -0 ${APP_PID} 2&>/dev/null); do
echo "Application is still running.." echo "Application is still running.."
sleep 1 sleep 1
let n=n+1
if [ "$n" -ge "$TERMINATE_TIMEOUT" ]; then
echo "Timeout reached, killing process with pid ${APP_PID}"
kill -9 ${APP_PID} || true
break
fi
done done
echo "Application process exited, waiting 10 seconds" echo "Application process terminated, waiting 10 seconds"
sleep 10 sleep 10
echo "Terminating remaining subprocesses.." echo "Terminating remaining subprocesses.."
kill 0 kill 0