From 0e6b78af94c517aa230ee8f66e63443a1f222bd0 Mon Sep 17 00:00:00 2001 From: Sean Reifschneider Date: Thu, 15 Oct 2015 10:52:08 -0600 Subject: [PATCH] Fix for init script for other procs with "telegraf" The init script fails if another process has the word "telegraf" in it, for example if you aren running "vi /etc/opt/telegraf/telegraf.conf" or "tail -f /var/log/telegraf/telegraf.log". This is because the "-f" flag to "pgrep" will show processes with the search string anywhere in the command-line. This patch turns it around and gets the "ps" output for the process in the pidfile, and if that line has "telegraf" in it, it considers it to be running. --- scripts/init.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/init.sh b/scripts/init.sh index d65639674..a3b704e2e 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -59,14 +59,17 @@ function pidofproc() { echo "Expected three arguments, e.g. $0 -p pidfile daemon-name" fi - pid=`pgrep -f $3` + if [ ! -f "$2" ]; then + return 1 + fi + local pidfile=`cat $2` if [ "x$pidfile" == "x" ]; then return 1 fi - if [ "x$pid" != "x" -a "$pidfile" == "$pid" ]; then + if ps --pid "$pidfile" | grep -q $(basename $3); then return 0 fi