From 8bc8db6495433599af6d500546086e3156e3711e Mon Sep 17 00:00:00 2001 From: Ryan Bak Date: Thu, 8 Dec 2016 13:34:16 -0700 Subject: [PATCH] Check status on agent stop and wait if not stopped Waits up to 10 seconds for shutdowns to complete before returning. Helps ensure restarts will actually start. Allows us to remove the old 1 second sleep between start and stop, which was not always necessary and not always enough. Change-Id: I45c30cf2ffa29a77ee30b2b20b87519f32ee0b61 --- packaging/monasca-agent.init.template | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packaging/monasca-agent.init.template b/packaging/monasca-agent.init.template index 41494253..842b117c 100755 --- a/packaging/monasca-agent.init.template +++ b/packaging/monasca-agent.init.template @@ -111,11 +111,20 @@ case "$1" in ;; stop) - echo "Stopping $DESC (stopping supervisord)" "$NAME" if [ -e $SUPERVISOR_PIDFILE ]; then - kill `cat $SUPERVISOR_PIDFILE` + kill `cat $SUPERVISOR_PIDFILE` + retries=10 + until ! check_status > /dev/null; do + if [ $retries -le 1 ]; then + echo "Timeout hit while waiting for agent to stop" + break + else + retries=$(($retries - 1)) + sleep 1 + fi + done else - echo "Pid file $SUPERVISOR_PIDFILE not found, nothing to stop" + echo "Pid file $SUPERVISOR_PIDFILE not found, nothing to stop" fi exit $? @@ -141,7 +150,6 @@ case "$1" in restart|force-reload) $0 stop - sleep 1 $0 start ;;