From 89d2393ea9fa977946ba34b6b9b3b279f830b64c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Jeanneret?= Date: Wed, 27 Mar 2019 08:58:24 +0100 Subject: [PATCH] Silent file descriptor checks In order to avoid spam in journald, we just get the exit code and let the checker output the error message. Also, correct how we retrieve process in the healthcheck_port and _listen functions. "ss" doesn't allow to match some processes, like "neutron-l3-agent". We therefore use the PID instead, provided by "pgrep". The "-d" option of pgrep allow to prepare its output for the "grep -E", preventing any need of a loop. Change-Id: I1555a9b79c954e646fe9ae35272231c581cea03e Closes-Bug: #1821782 Closes-Bug: #1821856 (cherry picked from commit 5312bf19c8f820ac65514885aebdc2dc4776d72d) --- healthcheck/common.sh | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/healthcheck/common.sh b/healthcheck/common.sh index c4cc280e7..735453c30 100644 --- a/healthcheck/common.sh +++ b/healthcheck/common.sh @@ -14,31 +14,21 @@ healthcheck_curl () { healthcheck_port () { process=$1 - # ss truncate command name to 15 characters and this behaviour - # cannot be disabled - if [ ${#process} -gt 15 ] ; then - process=${process:0:15} - fi - shift 1 args=$@ ports=${args// /|} - ss -ntp | awk '{print $5,"-",$6}' | egrep ":($ports)" | grep "$process" + pids=$(pgrep -d '|' -f $process) + ss -ntp | grep -qE ":($ports).*,pid=($pids)," } healthcheck_listen () { process=$1 - # ss truncate command name to 15 characters and this behaviour - # cannot be disabled - if [ ${#process} -gt 15 ] ; then - process=${process:0:15} - fi - shift 1 args=$@ ports=${args// /|} - ss -lnp | awk '{print $5,"-",$7}' | egrep ":($ports)" | grep "$process" + pids=$(pgrep -d '|' -f $process) + ss -lnp | grep -qE ":($ports).*,pid=($pids)," } healthcheck_socket () { @@ -48,9 +38,9 @@ healthcheck_socket () { # lsof truncate command name to 15 characters and this behaviour # cannot be disabled if [ ${#process} -gt 15 ] ; then - process=${process:0:15} + process=${process:0:15} fi - lsof -Fc -Ua $socket | grep "c$process" + lsof -Fc -Ua $socket | grep -q "c$process" } healthcheck_file_modification () {