Skip to content

Commit d8c7a45

Browse files
committed
- Added support for _all_/_any_ in ELB_LIST
1 parent d30c8ff commit d8c7a45

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

load-balancing/elb/deregister_from_elb.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,27 @@ if [ $? == 0 -a -n "${asg}" ]; then
4949
fi
5050
fi
5151

52-
msg "Instance is not part of an ASG, continuing..."
52+
msg "Instance is not part of an ASG, trying with ELB..."
5353

54-
msg "Checking that user set at least one load balancer"
55-
if test -z "$ELB_LIST"; then
56-
error_exit "Must have at least one load balancer to deregister from"
54+
if [ -z "$ELB_LIST" ]; then
55+
error_exit "ELB_LIST is empty. Must have at least one load balancer to deregister from, or \"_all_\", \"_any_\" values."
56+
elif [ "${ELB_LIST}" = "_all_" ]; then
57+
msg "Automatically finding all the ELBs that this instance is registered to..."
58+
get_elb_list $INSTANCE_ID
59+
if [ $? != 0 ]; then
60+
error_exit "Couldn't find any. Must have at least one load balancer to deregister from."
61+
fi
62+
set_flag "ELBs" "$ELB_LIST"
63+
elif [ "${ELB_LIST}" = "_any_" ]; then
64+
msg "Automatically finding all the ELBs that this instance is registered to..."
65+
get_elb_list $INSTANCE_ID
66+
if [ $? != 0 ]; then
67+
msg "Couldn't find any, but ELB_LIST=any so finishing successfully without deregistering."
68+
set_flag "ELBs" ""
69+
finish_msg
70+
exit 0
71+
fi
72+
set_flag "ELBs" "$ELB_LIST"
5773
fi
5874

5975
# Loop through all LBs the user set, and attempt to deregister this instance from them.
@@ -73,7 +89,7 @@ for elb in $ELB_LIST; do
7389
fi
7490
done
7591

76-
# Wait for all Deregistrations to finish
92+
# Wait for all deregistrations to finish
7793
msg "Waiting for instance to de-register from its load balancers"
7894
for elb in $ELB_LIST; do
7995
wait_for_state "elb" $INSTANCE_ID "OutOfService" $elb

load-balancing/elb/register_with_elb.sh

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,27 @@ if [ $? == 0 -a -n "${asg}" ]; then
4949
fi
5050
fi
5151

52-
msg "Instance is not part of an ASG, continuing..."
52+
msg "Instance is not part of an ASG, continuing with ELB"
5353

54-
msg "Checking that user set at least one load balancer"
55-
if test -z "$ELB_LIST"; then
56-
error_exit "Must have at least one load balancer to register to"
54+
if [ -z "$ELB_LIST" ]; then
55+
error_exit "ELB_LIST is empty. Must have at least one load balancer to register to, or \"_all_\", \"_any_\" values."
56+
elif [ "${ELB_LIST}" = "_all_" ]; then
57+
msg "Finding all the ELBs that this instance was previously registered to"
58+
if ! ELB_LIST=$(get_flag "ELBs"); then
59+
error_exit "$FLAGFILE doesn't exist or is unreadble"
60+
elif [ -z $ELB_LIST ]; then
61+
error_exit "Couldn't find any. Must have at least one load balancer to register to."
62+
fi
63+
elif [ "${ELB_LIST}" = "_any_" ]; then
64+
msg "Finding all the ELBs that this instance was previously registered to"
65+
if ! ELB_LIST=$(get_flag "ELBs"); then
66+
error_exit "$FLAGFILE doesn't exist or is unreadble"
67+
elif [ -z $ELB_LIST ]; then
68+
msg "Couldn't find any, but ELB_LIST=any so finishing successfully without registering."
69+
remove_flagfile
70+
finish_msg
71+
exit 0
72+
fi
5773
fi
5874

5975
# Loop through all LBs the user set, and attempt to register this instance to them.
@@ -73,7 +89,7 @@ for elb in $ELB_LIST; do
7389
fi
7490
done
7591

76-
# Wait for all Registrations to finish
92+
# Wait for all registrations to finish
7793
msg "Waiting for instance to register to its load balancers"
7894
for elb in $ELB_LIST; do
7995
wait_for_state "elb" $INSTANCE_ID "InService" $elb
@@ -82,4 +98,6 @@ for elb in $ELB_LIST; do
8298
fi
8399
done
84100

101+
remove_flagfile
102+
85103
finish_msg

0 commit comments

Comments
 (0)