File: //scripts/checkGeometra4Prod.sh
#!/bin/bash
PROJECT_DIR="/data/geometra-4-server-prod"
DEGRADED_LIST="$PROJECT_DIR/DegradedInstance.list"
LOG="$PROJECT_DIR/logs/autoHealDegradedInstance.log"
cd $PROJECT_DIR
/root/.ebcli-virtual-env/executables/eb health | grep Degraded | grep "i-" | awk '{print $1}'> $DEGRADED_LIST
if [ -s $DEGRADED_LIST ]
then
cat $DEGRADED_LIST | while read INSTANCE
do
echo "$(date) | Rebooting Degraded Instance: $INSTANCE" >> $LOG
/usr/local/bin/aws ec2 reboot-instances --instance-ids $INSTANCE
# curl --location --request POST 'https://marketing.wp.karmanye.in/api/Karmanye/send-message' --header 'Content-Type: application/json; charset=utf-8' --header 'Accept: application/json' --header 'Authorization: Bearer $2b$10$f7yAQHm3Y1eOxs92aiEJ9eohJ0AdUQ2YwXxUARzk3sVLgKIVw0k2q' -d '{ "phone": "919033595842", "message": "*Geometra-4-Server-Prod Degraded Instance: '"$INSTANCE"'* \n\n*Rebooting Instance for AutoHealing*"}'
done
else
echo "$(date) | Everything OK!"
fi