Skip to content

Instantly share code, notes, and snippets.

@gswallow
Last active November 10, 2017 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gswallow/8d4d8ab4b0778c966cbf36fe39c9e58c to your computer and use it in GitHub Desktop.
Save gswallow/8d4d8ab4b0778c966cbf36fe39c9e58c to your computer and use it in GitHub Desktop.
auto-scaling re-launcher
#!/bin/bash
set -o errexit -o errtrace -o pipefail
trap signal_and_exit ERR
function my_instance_id
{
curl -sL http://169.254.169.254/latest/meta-data/instance-id/
}
function my_az
{
curl -sL http://169.254.169.254/latest/meta-data/placement/availability-zone/
}
function my_aws_region
{
local az
az=$(my_az)
echo "${az%?}"
}
# Signaling that this instance is unhealthy allows AWS auto scaling to launch a copy
# Provides for self healing and helps mitigate transient failures (e.g. package transfers)
function signal_and_exit
{
status=$?
if [ $status -gt 0 ]; then
sleep 180 # give me a few minutes to look around before croaking
/usr/local/bin/aws autoscaling set-instance-health \
--instance-id "$(my_instance_id)" \
--health-status Unhealthy \
--region "$(my_aws_region)"
fi
}
#-----^ AWS safety guards ^-----
# All of this, just to install python-pip.
for i in rhscl extras optional ; do
yum-config-manager --enable rhui-REGION-rhel-server-$i > /dev/null 2>&1
done
sudo rpmkeys --import https://getfedora.org/static/352C64E5.txt
rpm -i https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install python-pip setuptools awscli
curl -L https://bootstrap.saltstack.com -o install_salt.sh
sh install_salt.sh -A salt.ivytech.edu -L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment