Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

I am re-writing a services-checking script: https://github.com/sierracircle/services-checker
The original stopped working on Ubuntu 16.04, so I had to re-jigger it. So far so good; however, I would like to add a new feature.
Currently, the script checks all services you list for whatever interval you set your cronjob to.
…but, if the last thing happens, it goes through the same loop again and again, so you might wake up in the morning with hundreds of emails telling you that it was unable to restart that service.
I would like to change this script to only attempt to restart 3 times, and then leave it. That way, you get 3 emails.
Any clues on a simple way to do that?
Here is the loop the script goes through. It does this loop for each service you define:
for i in "${SERVICES[@]}"
do
###CHECK SERVICE####
`pgrep $i >/dev/null 2>&1`
STATS=$(echo $?)
###IF SERVICE IS NOT RUNNING####
if [[ $STATS == 1 ]]
then
##TRY TO RESTART THAT SERVICE###
service $i start
##CHECK IF RESTART WORKED###
`pgrep $i >/dev/null 2>&1`
RESTART=$(echo $?)
if [[ $RESTART == 0 ]]
##IF SERVICE HAS BEEN RESTARTED###
then
##SEND AN EMAIL###
MESSAGE="$i is down, but looks like I was able to restart it on on $(hostname) $(date) "
SUBJECT="$i down -but restarted- on $(hostname) $(date) "
echo $MESSAGE | mail -s "$SUBJECT" "$EMAIL"
else
##IF RESTART DID NOT WORK SEND A DIFFERENT EMAIL###
MESSAGE="$i is down on $(hostname) at $(date) "
SUBJECT=" $i down on $(hostname) $(date) "
echo $MESSAGE " I tried to restart it, but it did not work" | mail -s "$SUBJECT" "$EMAIL"
fi
fi
done
Erina Jones
05c643336f3a4578a0b414e11ed8fc
378226414b344d3d9ef057316f83e8
792d8c6065294b4da466a26b2a99e4
KFSys
fe9c7f1f3d29491e8c9905409bd159
LittleSeaGreenMorel
Guram Chankseliani
Wilson Karl
KFSys
KFSys
KFSys