Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example check_status.sh for checking status of services in a service group #9

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions check_status.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/bash
#
# check_status.sh [Microservice|Infrastructure|Frontend|Dashboard|Frontend-non-essential]
#
# Checks whether services in the given group are all running, in which case writes "OK". Otherwise, if at least
# one service fails, write "FAIL: ..." listing the services that fail.
#

shopt -s expand_aliases
alias cedarcli='source $CEDAR_HOME/cedar-cli/cli.sh'

if [[ $# -eq 0 ]] ; then
echo 'Please provide the name of a service group as an argument.'
exit 0
fi

GROUP=$1
FOUND_GROUP=false
ALL_OK=true
FAILING_SERVICES=""

while read -r line ; do
if [[ $line == *"$GROUP"* ]] ; then
FOUND_GROUP=true
continue
fi

if [[ $FOUND_GROUP == true ]] ; then
if [[ $line == *"├"* || $line == *"┡"* || $line == *"└"* ]] ; then
break
fi

if [[ $line == *"❌"* ]] ; then
ALL_OK=false
FAILING_SERVICES+=$(echo $line | awk '{print $2}')" "
fi
fi
done < <(cedarcli server status)

if [[ $FOUND_GROUP == false ]] ; then
echo "Invalid service group provided: $GROUP"
exit 0
fi

if [[ $ALL_OK == true ]] ; then
echo 'OK'
else
echo "FAIL: $FAILING_SERVICES"
fi