change minio to use input vars

This commit is contained in:
admin 2026-02-01 17:24:12 -07:00
parent 5430a0cc5a
commit 8b11035bfb

View file

@ -1,35 +1,43 @@
#!/bin/bash #!/bin/bash
# 1. Setup variables from your environment # 1. Capture inputs from arguments
CONTAINER_NAME="minio-node${MINIO_NODE_NUMBER}" # Usage: bash provision-minio.sh "${MINIO_NODE_NUMBER}" "${MINIO_BUCKET_REGISTRY}"
NODE_NUM=$1
BUCKET_LIST=$2
DATA_PATH="/docker/minio/data" DATA_PATH="/docker/minio/data"
# Example: MINIO_BUCKET_REGISTRY="forgejo prometheus backups"
echo "Checking S3 Bucket Registry..." # Validation
if [ -z "$NODE_NUM" ] || [ -z "$BUCKET_LIST" ]; then
echo "ERROR: Missing arguments."
echo "Usage: bash provision-minio.sh [node_number] [bucket_list]"
exit 1
fi
# 2. Stop the clustered container to prevent file locks/sync conflicts CONTAINER_NAME="minio-node${NODE_NUM}"
docker stop $CONTAINER_NAME 2>/dev/null || true
# 3. Loop through the registry echo "--- S3 Provisioning Started for ${CONTAINER_NAME} ---"
for BUCKET in ${MINIO_BUCKET_REGISTRY}; do
# 2. Stop the clustered container to avoid file locks during folder creation
echo "Stopping ${CONTAINER_NAME}..."
docker stop "${CONTAINER_NAME}" 2>/dev/null || true
# 3. Create the directories
# We split the space-separated list into a loop
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 "Bucket '$BUCKET' already exists on host. Skipping." echo "OK: Bucket '$BUCKET' exists."
else else
echo "Bucket '$BUCKET' missing. Creating directory..." echo "NEW: Creating bucket directory '$BUCKET'..."
# We create it with the correct permissions (MinIO usually runs as 1000)
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"
# Optional: Use a standalone container to 'formalize' the bucket
# if you want MinIO metadata generated immediately
docker run --rm \
-v "$DATA_PATH":/data \
alpine:latest sh -c "mkdir -p /data/$BUCKET && chown -R 1000:1000 /data/$BUCKET"
fi fi
done done
# 4. Restart the real clustered container # 4. Restart the real container
echo "Restarting $CONTAINER_NAME..." echo "Restarting ${CONTAINER_NAME}..."
docker start $CONTAINER_NAME docker start "${CONTAINER_NAME}"
echo "--- Provisioning Complete ---"