From b9a137ce5d31ca92e9ad8ffa2e19e6ef93c83fd9 Mon Sep 17 00:00:00 2001 From: Andrew Azores Date: Wed, 17 Jan 2024 10:41:15 -0500 Subject: [PATCH] bucket pre-create cleanup --- cryostat-entrypoint.bash | 44 +++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/cryostat-entrypoint.bash b/cryostat-entrypoint.bash index 18b01f7..821eeff 100755 --- a/cryostat-entrypoint.bash +++ b/cryostat-entrypoint.bash @@ -15,25 +15,37 @@ set -xe cfg="$(mktemp)" envsubst '$CRYOSTAT_ACCESS_KEY $CRYOSTAT_SECRET_KEY' < /etc/seaweed_conf.template.json > "${cfg}" +function waitForStartup() { + echo "cluster.check" | timeout "${BUCKET_CREATION_STARTUP_SECONDS:-30}"s weed shell 1>/dev/null 2>/dev/null || true + sleep "${BUCKET_CREATION_DELAY_SECONDS:-5}" +} + +function createBucket() { + echo "s3.bucket.create -name $1" | timeout "${BUCKET_CREATION_TIMEOUT_SECONDS:-5}"s weed shell +} + function createBuckets() { - for i in $(echo "$CRYOSTAT_BUCKETS" | tr ',' '\n'); do - local len - len="${#i}" - if [ "${len}" -lt 3 ]; then - echo "Bucket names must be at least 3 characters" - exit 1 - fi - if [ "${len}" -gt 63 ]; then - echo "Bucket names must be at most 63 characters" - exit 1 - fi - local cmd - # FIXME do something better than sleeping here - cmd="sleep ${BUCKET_CREATION_STARTUP_SECONDS:-30} ; echo \"s3.bucket.create -name ${i}\" | weed shell" - bash -c "${cmd}" & + waitForStartup + for name in "${names[@]}"; do + createBucket "${name}" done } -createBuckets + +names=() +for i in $(echo "$CRYOSTAT_BUCKETS" | tr ',' '\n'); do + len="${#i}" + if [ "${len}" -lt 3 ]; then + echo "Bucket names must be at least 3 characters" + exit 1 + fi + if [ "${len}" -gt 63 ]; then + echo "Bucket names must be at most 63 characters" + exit 1 + fi + names+=("${i}") +done + +createBuckets "${names[@]}" & exec /usr/bin/entrypoint.sh \ server -dir="${DATA_DIR:-/tmp}" \