From c12eecc90e70001a7cdc6324d7018754937c1563 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Wed, 26 Dec 2018 18:54:50 -0800 Subject: [PATCH] Signal telegraf process until it exits (#5169) --- agent/agent.go | 1 + scripts/init.sh | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/agent/agent.go b/agent/agent.go index 40ec24456..ec9aa7f32 100644 --- a/agent/agent.go +++ b/agent/agent.go @@ -134,6 +134,7 @@ func (a *Agent) Run(ctx context.Context) error { return err } + log.Printf("D! [agent] Stopped Successfully") return nil } diff --git a/scripts/init.sh b/scripts/init.sh index 668dc549e..67236d8c7 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -152,11 +152,17 @@ case $1 in if [ -e $pidfile ]; then pidofproc -p $pidfile $daemon > /dev/null 2>&1 && status="0" || status="$?" if [ "$status" = 0 ]; then - if killproc -p $pidfile SIGTERM && /bin/rm -rf $pidfile; then - log_success_msg "$name process was stopped" - else - log_failure_msg "$name failed to stop service" - fi + # periodically signal until process exists + while true; do + if ! pidofproc -p $pidfile $daemon > /dev/null; then + break + fi + killproc -p $pidfile SIGTERM 2>&1 >/dev/null + sleep 2 + done + + log_success_msg "$name process was stopped" + rm -f $pidfile fi else log_failure_msg "$name process is not running"