Skip to content

Commit

Permalink
Fixed Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
simonzhekoff committed Dec 10, 2024
1 parent b18ce46 commit b930804
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions modules/graphdb/templates/00_functions.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env bash

# Path to the flag file
ASG_CHECK_FLAG="/tmp/asg_check_complete"

# Function to log messages with a timestamp
log_with_timestamp() {
echo "$(date '+%Y-%m-%d %H:%M:%S'): $1"
Expand All @@ -10,7 +13,8 @@ wait_for_asg_nodes() {
local ASG_NAME="$1"
local RETRY_DELAY=10
# Get the desired capacity of the ASG
local NODE_COUNT=$(aws autoscaling describe-auto-scaling-groups \
local NODE_COUNT
NODE_COUNT=$(aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names "$ASG_NAME" \
--query "AutoScalingGroups[0].DesiredCapacity" \
--output text)
Expand All @@ -36,7 +40,6 @@ wait_for_asg_nodes() {
--query "AutoScalingGroups[0].Instances[?LifecycleState=='Terminating'] | length(@)" \
--output text)

# Check for instances in EC2 shutting-down state
local SHUTTING_DOWN_NODE_COUNT
SHUTTING_DOWN_NODE_COUNT=$(aws ec2 describe-instances \
--filters "Name=instance-state-name,Values=shutting-down" \
Expand All @@ -57,7 +60,7 @@ wait_for_asg_nodes() {
done
}

# Wait for the desired nodes count
# Main function to wait for ASG nodes, using a flag file to ensure the check runs only once
wait_desired_node_count() {
local ASG_NAME="$1"

Expand All @@ -66,9 +69,17 @@ wait_desired_node_count() {
exit 1
fi

# Check if the flag file exists
if [ -f "$ASG_CHECK_FLAG" ]; then
return 0
fi

log_with_timestamp "Starting script execution for ASG: $ASG_NAME"
wait_for_asg_nodes "$ASG_NAME"
log_with_timestamp "Proceeding with the rest of the script after ASG check."

# Create the flag file to mark completion
touch "$ASG_CHECK_FLAG"
log_with_timestamp "ASG check completed. Flag created."
}

# Execute the main function with the provided ASG name
Expand Down

0 comments on commit b930804

Please sign in to comment.