Charm: ~clint-fewbar:precise/elb   Revision: 5   Hook: elb-target-relation-departed
#!/bin/sh
#
set -ue

target_service=${JUJU_REMOTE_UNIT%%/*}

. `pwd`/elb_env.sh

my_instance_id=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`

# register local instance with elb for service X
elb-deregister-instances-from-lb $target_service --instances $my_instance_id

ninstances=`elb-describe-lbs $target_service|wc -l`
if [ $ninstances -eq 0 ] ; then
	juju-log "ELB appears to be empty. Leaving since other nodes may be adding themselves."
fi