#!/bin/bash

LOCATION="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

for f in $(find ${LOCATION} -mindepth 2 -maxdepth 3 -name docker-compose.yml); do
  pushd $(dirname $f) > /dev/null
  status=$(docker compose ps --format '{"name":"{{.Names}}","created":"{{.CreatedAt}}","elapsed":"{{.RunningFor}}","state":"{{.State}}","status":"{{.Status}}"}')
  popd > /dev/null
  if [ "${status}" ]; then
    echo $status
    if command -v bgsystemlog &> /dev/null
    then
      bgsystemlog -j streamline_emr -m "'${status}'"
    fi
  else
    echo "no services found"
  fi
done
echo "done."