From 652c3a5837340aa31fd9d90ac47ab75c209c6828 Mon Sep 17 00:00:00 2001
From: endika <endika.aldecoa@ehu.eus>
Date: Fri, 11 Sep 2020 15:19:52 +0200
Subject: [PATCH] Execute docker health commands with docker group

Fixes bug #1205

Change-Id: Iccf15a31c4925421820e25d7c0821e322955267a
Signed-off-by: endika <endika.aldecoa@ehu.eus>
(cherry picked from commit ae9807e262603fb9753f22a215c085605258953c)
---
 installers/osm_health.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/installers/osm_health.sh b/installers/osm_health.sh
index 0f7922a3..e7c8065e 100755
--- a/installers/osm_health.sh
+++ b/installers/osm_health.sh
@@ -54,7 +54,7 @@ while [ $time -le "$WAIT_TIME" ]; do
             exit 0
         fi
     else
-        if [ "$(docker ps | grep " ${STACK_NAME}_" | grep -i healthy | wc -l)" -ge "$NUM_SERVICES_WITH_HEALTH" ]; then
+        if [ "$(sg docker -c "docker ps" | grep " ${STACK_NAME}_" | grep -i healthy | wc -l)" -ge "$NUM_SERVICES_WITH_HEALTH" ]; then
             # all dockers are healthy now.
             # final sleep is needed until more health checks are added to validate system is ready to handle requests
             sleep $WAIT_FINAL
@@ -79,12 +79,12 @@ if [ -n "$KUBERNETES" ]; then
     done
 else
     echo "Not all Docker services are healthy"
-    docker ps | grep " ${STACK_NAME}_"
+    sg docker -c "docker ps" | grep " ${STACK_NAME}_"
     for S_WITH_HEALTH in $SERVICES_WITH_HEALTH ; do
-        docker ps | grep " ${STACK_NAME}_" | grep -i healthy | grep -q "_${S_WITH_HEALTH}."  && continue
+        sg docker -c "docker ps" | grep " ${STACK_NAME}_" | grep -i healthy | grep -q "_${S_WITH_HEALTH}."  && continue
         echo
         echo BEGIN LOGS of container ${S_WITH_HEALTH} not healthy
-        docker service logs ${STACK_NAME}_${S_WITH_HEALTH} 2>&1 | tail -n 100
+        sg docker -c "docker service logs ${STACK_NAME}_${S_WITH_HEALTH} 2>&1" | tail -n 100
         echo END LOGS of container ${S_WITH_HEALTH} not healthy
         echo
     done
-- 
GitLab