Created
September 2, 2016 19:01
-
-
Save sepulworld/886cb5edcca6f5c404e47d8873fd18f5 to your computer and use it in GitHub Desktop.
Service-watchdog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# First arg should be the systemd service to watch | |
# Requires cloud-utils apt package and pip awscli | |
# Requires IAM access to IAM action autoscaling:SetInstanceHealth | |
EC2_INSTANCE_ID=$(ec2metadata --instance-id) | |
PROCESS_CHECK=$1 | |
REGION=$2 | |
while : | |
do | |
if systemctl --no-pager status "$PROCESS_CHECK" | grep -q "active (running)" | |
then | |
aws autoscaling set-instance-health --instance-id "$EC2_INSTANCE_ID" --health-status Healthy --region ${REGION} | |
else | |
echo "unhealthy, alerting autoscaling group" | |
aws autoscaling set-instance-health --instance-id "$EC2_INSTANCE_ID" --health-status Unhealthy --region ${REGION} | |
fi | |
sleep 10 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment