Skip to content

Instantly share code, notes, and snippets.

@chrissnell
Last active August 29, 2015 14:01
Show Gist options
  • Save chrissnell/40b9c4dd8d6f0b101099 to your computer and use it in GitHub Desktop.
Save chrissnell/40b9c4dd8d6f0b101099 to your computer and use it in GitHub Desktop.
Revinate Cloud Instance Provisioning
##
## Revinate Cloud Instance Provisioning
## Chris Snell <chris.snell@revinate.com>
##
# We only run this block if the file /etc/firstboot exists
if [ -f /etc/firstboot ]; then
# These are the URLs for the EC2-compatible metadata service running in our cloud
HOSTNAME_METADATA="http://169.254.169.254/2009-04-04/meta-data/hostname"
LOCAL_IP_METADATA="http://169.254.169.254/2009-04-04/meta-data/local-ipv4"
# The base domain for all of our instances
DOMAIN="revinate.net"
# Fetch the hostname from the metadata service
HOSTNAME=`curl -s $HOSTNAME_METADATA | sed -e 's/.novalocal//'`
LOCAL_IP=`curl -s $LOCAL_IP_METADATA`
FQDN=${HOSTNAME}.${DOMAIN}
echo "FQDN: $FQDN LOCAL_IP: $LOCAL_IP"
echo "" >> /etc/hosts
echo "# Set automatically at instance creation time by /etc/rc.local" >> /etc/hosts
echo "$LOCAL_IP $FQDN $HOSTNAME" >> /etc/hosts
# Save our hostname to /etc/hostname
echo $HOSTNAME > /etc/hostname
# And set the current hostname, too
hostname $HOSTNAME
# Remove /etc/firstboot now that we've provisoned
rm -f /etc/firstboot
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment