Hi all,
I'm currently working with heartbeat in the Amazon cloud and (for
those that are familiar with Amazon EC2), I'm trying to use heartbeat
to re-allocate an elastic IP on detection of node failure. I'm not
experienced with writing my own heartbeat resource scripts, but this
is what I have:
usage() {
echo "usage: $0 start|stop"
exit 1
}
associate() {
CURRENT_IP=`curl -s http://169.254.169.254/latest/meta-data/public-ipv4
`
ELASTIC_IP=`head -n 1 /etc/loadbalancer.org/aws/elasticip | tr -d
'\n'`
if [ "$CURRENT_IP" != "$ELASTIC_IP" ]; then
INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id
`
ec2-associate-address -i $INSTANCE_ID $ELASTIC_IP > /dev/null
2>&1 & #re-associate the elastic ip with THIS instance
exit 0
else #do nothing and exit, as associating twice causes problems!
exit 0
fi
}
disassociate() {
ELASTIC_IP=`head -n 1 /etc/loadbalancer.org/aws/elasticip | tr -d
'\n'`
ec2-disassociate-address $ELASTIC_IP > /dev/null 2>&1 &
sleep 3 #put a small delay in to make sure that this IP will
definitely be disassociated by the time '$0 start' runs
exit 0
}
if [ $# != 1 ]; then
usage
fi
case "$1" in
"start" ) associate;;
"stop" ) disassociate;;
* ) usage;;
esac
and I've simply put this script in /etc/ha.d/resource.d. The script
definitely runs (via heartbeat) and I have put some debug stuff in to
confirm this (piping output to files etc.) but for some reason the ec2-
associate-address and ec2-disassociate-address commands have no
effect, but when tested manually these commands work ok. In fact this
whole script, when ran manually, behaves as expected. The heartbeat
log indicates that the script has ran.
I'm running heartbeat v2.1.3, but have not enabled CRM. I did think it
may be a timeout because the ec2 commands take a few seconds to run,
but I tested a trivial resource script that did 'sleep 10; echo
'stuff' > test-file' and that ran without problems, despite the 10
second sleep.
Any help greatly appreciated; thanks in advance...
--
Regards
James Little
Loadbalancer.org Limited
+44 (0)870 443 8779
www.loadbalancer.org
_______________________________________________
Linux-HA mailing list
[email protected]
http://lists.linux-ha.org/mailman/listinfo/linux-ha
See also: http://linux-ha.org/ReportingProblems