Skip to content

Commit 04cfc62

Browse files
author
Peng Zhou
committed
add retry logic to group configuration
1 parent b1f51e9 commit 04cfc62

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

pkg/k8sutil/scripts/poststart-hook.sh

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ log () {
5353
echo $message >> /tmp/script.log
5454
}
5555

56+
# Function to retry a command based on the return code
57+
# $1: The number of retries
58+
# $2: The command to run
59+
retry() {
60+
local retries=$1
61+
shift
62+
local count=0
63+
until "$@"; do
64+
exit_code=$?
65+
count=$((count + 1))
66+
if [ $count -ge $retries ]; then
67+
echo "Command failed after $retries attempts."
68+
return $exit_code
69+
fi
70+
echo "Attempt $count failed. Retrying..."
71+
sleep 5
72+
done
73+
}
74+
5675
###############################################################
5776
# Function to get the current host protocol
5877
# $1: The host name
@@ -699,10 +718,10 @@ if [[ "$IS_BOOTSTRAP_HOST" == "true" ]]; then
699718
if [[ "${MARKLOGIC_CLUSTER_TYPE}" == "bootstrap" ]]; then
700719
log "Info: bootstrap host is ready"
701720
init_security_db
702-
configure_group
721+
retry 5 configure_group
703722
else
704723
log "Info: bootstrap host is ready"
705-
configure_group
724+
retry 5 configure_group
706725
join_cluster $HOST_FQDN
707726
fi
708727
configure_path_based_routing

0 commit comments

Comments
 (0)