change to import .env
This commit is contained in:
parent
8b11035bfb
commit
69da95ce4c
1 changed files with 20 additions and 23 deletions
|
|
@ -1,43 +1,40 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# 1. Capture inputs from arguments
|
# 1. Look for the .env file in the periphery folder we standardized
|
||||||
# Usage: bash provision-minio.sh "${MINIO_NODE_NUMBER}" "${MINIO_BUCKET_REGISTRY}"
|
ENV_PATH="/docker/p0-infrastructure/minio/.env"
|
||||||
NODE_NUM=$1
|
|
||||||
BUCKET_LIST=$2
|
|
||||||
DATA_PATH="/docker/minio/data"
|
|
||||||
|
|
||||||
# Validation
|
if [ -f "$ENV_PATH" ]; then
|
||||||
if [ -z "$NODE_NUM" ] || [ -z "$BUCKET_LIST" ]; then
|
export $(grep -v '^#' "$ENV_PATH" | xargs)
|
||||||
echo "ERROR: Missing arguments."
|
echo "Successfully loaded variables from $ENV_PATH"
|
||||||
echo "Usage: bash provision-minio.sh [node_number] [bucket_list]"
|
else
|
||||||
|
echo "ERROR: Could not find .env at $ENV_PATH"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# 2. Now use the variables that were just loaded
|
||||||
|
NODE_NUM="${MINIO_NODE_NUMBER}"
|
||||||
|
BUCKET_LIST="${MINIO_BUCKET_REGISTRY}"
|
||||||
|
DATA_PATH="/docker/p0-infrastructure/minio/data"
|
||||||
|
|
||||||
|
if [ -z "$NODE_NUM" ]; then
|
||||||
|
echo "ERROR: MINIO_NODE_NUMBER not found in .env"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
CONTAINER_NAME="minio-node${NODE_NUM}"
|
CONTAINER_NAME="minio-node${NODE_NUM}"
|
||||||
|
|
||||||
echo "--- S3 Provisioning Started for ${CONTAINER_NAME} ---"
|
echo "--- S3 Provisioning Started for ${CONTAINER_NAME} ---"
|
||||||
|
|
||||||
# 2. Stop the clustered container to avoid file locks during folder creation
|
|
||||||
echo "Stopping ${CONTAINER_NAME}..."
|
|
||||||
docker stop "${CONTAINER_NAME}" 2>/dev/null || true
|
docker stop "${CONTAINER_NAME}" 2>/dev/null || true
|
||||||
|
sleep 2
|
||||||
|
|
||||||
# 3. Create the directories
|
|
||||||
# We split the space-separated list into a loop
|
|
||||||
for BUCKET in $BUCKET_LIST; do
|
for BUCKET in $BUCKET_LIST; do
|
||||||
TARGET_DIR="$DATA_PATH/$BUCKET"
|
TARGET_DIR="$DATA_PATH/$BUCKET"
|
||||||
|
if [ ! -d "$TARGET_DIR" ]; then
|
||||||
if [ -d "$TARGET_DIR" ]; then
|
echo "NEW: Creating $BUCKET"
|
||||||
echo "OK: Bucket '$BUCKET' exists."
|
|
||||||
else
|
|
||||||
echo "NEW: Creating bucket directory '$BUCKET'..."
|
|
||||||
mkdir -p "$TARGET_DIR"
|
mkdir -p "$TARGET_DIR"
|
||||||
# Ensure the MinIO user (usually 1000) owns the folder
|
|
||||||
chown -R 1000:1000 "$TARGET_DIR"
|
chown -R 1000:1000 "$TARGET_DIR"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# 4. Restart the real container
|
|
||||||
echo "Restarting ${CONTAINER_NAME}..."
|
|
||||||
docker start "${CONTAINER_NAME}"
|
docker start "${CONTAINER_NAME}"
|
||||||
|
|
||||||
echo "--- Provisioning Complete ---"
|
echo "--- Provisioning Complete ---"
|
||||||
Loading…
Reference in a new issue