Skip to content

Commit 29607b6

Browse files
committed
Update deploy-minio.sh
1 parent 4ba79fe commit 29607b6

1 file changed

Lines changed: 82 additions & 21 deletions

File tree

deploy-minio.sh

Lines changed: 82 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,49 @@ sudo chmod +x /usr/local/bin/minio
4343

4444
echo "[5/10] Creating ZFS filesystem ${POOL_NAME}/minio..."
4545

46-
if sudo zfs list ${POOL_NAME}/minio &>/dev/null; then
47-
echo "❗ The ZFS dataset ${POOL_NAME}/minio already exists."
48-
read -p "Do you want to delete and recreate it? This will erase all data in it. (y/n): " RECREATE
49-
if [[ "$RECREATE" == "y" ]]; then
50-
echo "Destroying existing dataset ${POOL_NAME}/minio..."
51-
sudo zfs destroy -r ${POOL_NAME}/minio
52-
echo "Creating new dataset ${POOL_NAME}/minio..."
53-
sudo zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 ${POOL_NAME}/minio
54-
elif [[ "$RECREATE" == "n" ]]; then
55-
read -p "Do you want to deploy on top of existing data? (y/n): " REUSE
56-
if [[ "$REUSE" == "y" ]]; then
57-
echo "Reusing existing dataset ${POOL_NAME}/minio..."
58-
else
59-
echo "Exiting"
60-
exit 1
61-
fi
62-
else
63-
echo "Invalid option. Exiting."
64-
exit 1
46+
# Ensure pool exists
47+
if ! sudo zpool list -H -o name | grep -qx "${POOL_NAME}"; then
48+
echo "ERROR: ZFS pool '${POOL_NAME}' not found. Pools available:"
49+
sudo zpool list
50+
exit 1
51+
fi
52+
53+
DATASET="${POOL_NAME}/minio"
54+
55+
# Existence check with timeout so it cannot "stick"
56+
if timeout 10s sudo zfs list -H -o name "$DATASET" >/dev/null 2>&1; then
57+
echo "WARNING: The ZFS dataset $DATASET already exists."
58+
read -p "Do you want to delete and recreate it? This will erase all data in it. (y/n): " RECREATE
59+
if [[ "$RECREATE" == "y" ]]; then
60+
echo "Destroying existing dataset $DATASET..."
61+
sudo zfs destroy -r "$DATASET"
62+
echo "Creating new dataset $DATASET..."
63+
sudo zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 "$DATASET"
64+
elif [[ "$RECREATE" == "n" ]]; then
65+
read -p "Do you want to deploy on top of existing data? (y/n): " REUSE
66+
if [[ "$REUSE" != "y" ]]; then
67+
echo "Exiting"
68+
exit 1
6569
fi
70+
else
71+
echo "Invalid option. Exiting."
72+
exit 1
73+
fi
6674
else
67-
echo "Creating new dataset ${POOL_NAME}/minio..."
68-
sudo zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 ${POOL_NAME}/minio
75+
rc=$?
76+
if [ "$rc" -eq 124 ]; then
77+
echo "ERROR: ZFS command timed out. ZFS may be unhealthy or blocked."
78+
echo "Try: sudo zpool status ; sudo dmesg -T | tail -n 200 | grep -i zfs"
79+
exit 1
80+
fi
81+
echo "Creating new dataset $DATASET..."
82+
sudo zfs create -o recordsize=1M -o atime=off -o xattr=sa -o compression=lz4 "$DATASET"
6983
fi
7084

7185

7286

7387

88+
7489
echo "[6/10] Setting ownership for ZFS mount..."
7590
sudo chown -R minio-user:minio-user /${POOL_NAME}/minio/
7691

@@ -154,5 +169,51 @@ echo "Enabling and starting MinIO service..."
154169
sudo systemctl daemon-reload
155170
sudo systemctl enable --now minio
156171

172+
echo "Installing MinIO client (mc)..."
173+
sudo $PM install -y curl
174+
sudo curl -fL https://dl.min.io/client/mc/release/linux-amd64/mc -o /usr/local/bin/mc
175+
sudo chmod +x /usr/local/bin/mc
176+
177+
MC_BIN="/usr/local/bin/mc"
178+
if [[ ! -x "$MC_BIN" ]]; then
179+
echo "ERROR: mc not found or not executable at $MC_BIN"
180+
ls -l "$MC_BIN" || true
181+
exit 1
182+
fi
183+
184+
185+
# Determine scheme: https if cert exists, else http
186+
SCHEME="http"
187+
if [[ -f /etc/minio/certs/public.crt ]]; then
188+
SCHEME="https"
189+
190+
echo "Trusting MinIO certificate (self-signed)..."
191+
if [[ "$OS" == 'NAME="Rocky Linux"' ]]; then
192+
sudo cp /etc/minio/certs/public.crt /etc/pki/ca-trust/source/anchors/minio.crt
193+
sudo update-ca-trust
194+
elif [[ "$OS" == 'NAME="Ubuntu"' ]]; then
195+
sudo cp /etc/minio/certs/public.crt /usr/local/share/ca-certificates/minio.crt
196+
sudo update-ca-certificates
197+
fi
198+
fi
199+
200+
echo "Waiting for MinIO to become ready..."
201+
for i in {1..60}; do
202+
if curl -fsS -k "${SCHEME}://127.0.0.1:9000/minio/health/ready" >/dev/null 2>&1; then
203+
break
204+
fi
205+
sleep 1
206+
done
207+
208+
echo "Creating mc alias houston (for root)..."
209+
"$MC_BIN" alias set houston "${SCHEME}://127.0.0.1:9000" "${MINIO_USER}" "${MINIO_PASSWORD}"
210+
211+
echo "Verifying MinIO admin access via mc..."
212+
"$MC_BIN" --json admin info houston >/dev/null
213+
214+
echo "mc alias houston created and verified."
215+
216+
157217
echo "=== Setup Complete ==="
158218
echo "Visit https://YOUR_SERVER_IP:7575 to access the MinIO console."
219+

0 commit comments

Comments
 (0)