Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
export EC2_HOME=/usr/local/share/ec2_tools/
export JAVA_HOME=/usr/lib/jvm/java
export PATH=$PATH:$EC2_HOME/bin
INSTANCEID=`curl -s http://169.254.169.254/latest/meta-data/instance-id`
case "$1" in
MASTER)
logger triggering notify master event
ADDRESS=`ec2-describe-addresses --aws-secret-key '<%= @secret_key%>' --aws-access-key '<%= @access_key%>' <%= @eip%>`
ASSOCIATED_INSTANCEID=`echo $ADDRESS | awk '{print $3}'`
ASSOCIATION_ID=`echo $ADDRESS | awk '{print $6}'`
ALLOCATION_ID=`echo $ADDRESS | awk '{print $5}'`
if [ ! "$INSTANCEID" == "$ASSOCIATED_INSTANCEID" ]; then
ec2-disassociate-address --aws-secret-key '<%= @secret_key%>' --aws-access-key '<%= @access_key%>' -a $ASSOCIATION_ID 2>&1
logger -p local0.warn associating EIP to instance: $INSTANCEID
ec2-associate-address --aws-secret-key '<%= @secret_key%>' --aws-access-key '<%= @access_key%>' -i $INSTANCEID -a $ALLOCATION_ID 2>&1
fi
;;
FAULT)
logger restarting keepalived
service keepalived restart
;;
*)
echo $"Usage: $0 {MASTER|FAULT}"
exit 2
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment