github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/buildscripts/verify-healing-with-root-disks.sh (about) 1 #!/bin/bash -e 2 3 set -E 4 set -o pipefail 5 set -x 6 7 if [ ! -x "$PWD/minio" ]; then 8 echo "minio executable binary not found in current directory" 9 exit 1 10 fi 11 12 WORK_DIR="$(mktemp -d)" 13 MINIO_CONFIG_DIR="$WORK_DIR/.minio" 14 MINIO=("$PWD/minio" --config-dir "$MINIO_CONFIG_DIR" server) 15 16 function start_minio() { 17 start_port=$1 18 19 export MINIO_ROOT_USER=minio 20 export MINIO_ROOT_PASSWORD=minio123 21 unset MINIO_KMS_AUTO_ENCRYPTION # do not auto-encrypt objects 22 unset MINIO_CI_CD 23 unset CI 24 25 args=() 26 for i in $(seq 1 4); do 27 args+=("http://localhost:$((start_port + i))${WORK_DIR}/mnt/disk$i/ ") 28 done 29 30 for i in $(seq 1 4); do 31 "${MINIO[@]}" --address ":$((start_port + i))" ${args[@]} 2>&1 >"${WORK_DIR}/server$i.log" & 32 done 33 34 # Wait until all nodes return 403 35 for i in $(seq 1 4); do 36 while [ "$(curl -m 1 -s -o /dev/null -w "%{http_code}" http://localhost:$((start_port + i)))" -ne "403" ]; do 37 echo -n "." 38 sleep 1 39 done 40 done 41 42 } 43 44 # Prepare fake disks with losetup 45 function prepare_block_devices() { 46 set -e 47 mkdir -p ${WORK_DIR}/disks/ ${WORK_DIR}/mnt/ 48 sudo modprobe loop 49 for i in 1 2 3 4; do 50 dd if=/dev/zero of=${WORK_DIR}/disks/img.${i} bs=1M count=2000 51 device=$(sudo losetup --find --show ${WORK_DIR}/disks/img.${i}) 52 sudo mkfs.ext4 -F ${device} 53 mkdir -p ${WORK_DIR}/mnt/disk${i}/ 54 sudo mount ${device} ${WORK_DIR}/mnt/disk${i}/ 55 sudo chown "$(id -u):$(id -g)" ${device} ${WORK_DIR}/mnt/disk${i}/ 56 done 57 set +e 58 } 59 60 # Start a distributed MinIO setup, unmount one disk and check if it is formatted 61 function main() { 62 start_port=$(shuf -i 10000-65000 -n 1) 63 start_minio ${start_port} 64 65 # Unmount the disk, after the unmount the device id 66 # /tmp/xxx/mnt/disk4 will be the same as '/' and it 67 # will be detected as root disk 68 while [ "$u" != "0" ]; do 69 sudo umount ${WORK_DIR}/mnt/disk4/ 70 u=$? 71 sleep 1 72 done 73 74 # Wait until MinIO self heal kicks in 75 sleep 60 76 77 if [ -f ${WORK_DIR}/mnt/disk4/.minio.sys/format.json ]; then 78 echo "A root disk is formatted unexpectedely" 79 cat "${WORK_DIR}/server4.log" 80 exit -1 81 fi 82 } 83 84 function cleanup() { 85 pkill minio 86 sudo umount ${WORK_DIR}/mnt/disk{1..3}/ 87 sudo rm /dev/minio-loopdisk* 88 rm -rf "$WORK_DIR" 89 } 90 91 (prepare_block_devices) 92 (main "$@") 93 rv=$? 94 95 cleanup 96 exit "$rv"