#!/bin/sh

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'

exitStatus=0

if systemctl --quiet is-active identityman ; then
   echo -e "${GREEN}identity manager${NC}"
else
   echo -e "${RED}identity manager${NC}"
   exitStatus=1
fi
#if systemctl --quiet is-active cloudmon ; then
#   echo -e "${GREEN}cloud monitor${NC}"
#else
#   echo -e "${RED}cloud monitor${NC}"
#   exitStatus=1
#fi
if systemctl --quiet is-active tunnelmon ; then
   echo -e "${GREEN}tunnel monitor${NC}"
else
   echo -e "${RED}tunnel monitor${NC}"
   exitStatus=1
fi
if systemctl --quiet is-active probemon ; then
   echo -e "${GREEN}probe monitor${NC}"
else
   echo -e "${RED}probe monitor${NC}"
   exitStatus=1
fi
if systemctl --quiet is-active submit-server ; then
   echo -e "${GREEN}submit server${NC}"
else
   echo -e "${RED}submit server${NC}"
   exitStatus=1
fi
if [ -e /etc/systemd/system/jobmon.service ] ; then
   if systemctl --quiet is-active jobmon ; then
      echo -e "${GREEN}job monitor${NC}"
   else
      echo -e "${RED}job monitor${NC}"
      exitStatus=1
   fi
   if systemctl --quiet is-active jobpro ; then
      echo -e "${GREEN}job processor${NC}"
   else
      echo -e "${RED}job processor${NC}"
      exitStatus=1
   fi
   if systemctl --quiet is-active jobstageinput ; then
      echo -e "${GREEN}job input stager${NC}"
   else
      echo -e "${RED}job input stager${NC}"
      exitStatus=1
   fi
   if systemctl --quiet is-active jobexe ; then
      echo -e "${GREEN}job executer${NC}"
   else
      echo -e "${RED}job executer${NC}"
      exitStatus=1
   fi
   if systemctl --quiet is-active jobmetrics ; then
      echo -e "${GREEN}job metrics${NC}"
   else
      echo -e "${RED}job metrics${NC}"
      exitStatus=1
   fi
   if systemctl --quiet is-active jobcachesimtools ; then
      echo -e "${GREEN}job simtool caching${NC}"
   else
      echo -e "${RED}job simtool caching${NC}"
      exitStatus=1
   fi
else
   if systemctl --quiet is-active jobmon ; then
      echo -e "${GREEN}job monitor${NC}"
   else
      echo -e "${RED}job monitor${NC}"
      exitStatus=1
   fi
fi

if [ -e /etc/init.d/condor_grid ] ; then
   if systemctl --quiet is-active condor_grid ; then
      echo -e "${GREEN}condor grid${NC}"
   else
      echo -e "${RED}condor grid${NC}"
      exitStatus=1
   fi
fi
if [ -e /etc/init.d/condor_osg ] ; then
   if systemctl --quiet is-active condor_osg ; then
      echo -e "${GREEN}condor osg${NC}"
   else
      echo -e "${RED}condor osg${NC}"
      exitStatus=1
   fi
fi

exit ${exitStatus}
