storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/buildscripts/verify-healing.sh (about) 1 #!/bin/bash 2 # 3 # MinIO Cloud Storage, (C) 2020 MinIO, Inc. 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 18 set -e 19 set -E 20 set -o pipefail 21 22 if [ ! -x "$PWD/minio" ]; then 23 echo "minio executable binary not found in current directory" 24 exit 1 25 fi 26 27 WORK_DIR="$PWD/.verify-$RANDOM" 28 MINIO_CONFIG_DIR="$WORK_DIR/.minio" 29 MINIO=( "$PWD/minio" --config-dir "$MINIO_CONFIG_DIR" server ) 30 31 export GOGC=25 32 33 function start_minio_3_node() { 34 export MINIO_ROOT_USER=minio 35 export MINIO_ROOT_PASSWORD=minio123 36 export MINIO_ERASURE_SET_DRIVE_COUNT=6 37 38 start_port=$(shuf -i 10000-65000 -n 1) 39 args="" 40 for i in $(seq 1 3); do 41 args="$args http://127.0.0.1:$[$start_port+$i]${WORK_DIR}/$i/1/ http://127.0.0.1:$[$start_port+$i]${WORK_DIR}/$i/2/ http://127.0.0.1:$[$start_port+$i]${WORK_DIR}/$i/3/ http://127.0.0.1:$[$start_port+$i]${WORK_DIR}/$i/4/ http://127.0.0.1:$[$start_port+$i]${WORK_DIR}/$i/5/ http://127.0.0.1:$[$start_port+$i]${WORK_DIR}/$i/6/" 42 done 43 44 "${MINIO[@]}" --address ":$[$start_port+1]" $args > "${WORK_DIR}/dist-minio-server1.log" 2>&1 & 45 disown $! 46 47 "${MINIO[@]}" --address ":$[$start_port+2]" $args > "${WORK_DIR}/dist-minio-server2.log" 2>&1 & 48 disown $! 49 50 "${MINIO[@]}" --address ":$[$start_port+3]" $args > "${WORK_DIR}/dist-minio-server3.log" 2>&1 & 51 disown $! 52 53 sleep "$1" 54 if [ "$(pgrep -c minio)" -ne 3 ]; then 55 for i in $(seq 1 3); do 56 echo "server$i log:" 57 cat "${WORK_DIR}/dist-minio-server$i.log" 58 done 59 echo "FAILED" 60 purge "$WORK_DIR" 61 exit 1 62 fi 63 if ! pkill minio; then 64 for i in $(seq 1 3); do 65 echo "server$i log:" 66 cat "${WORK_DIR}/dist-minio-server$i.log" 67 done 68 echo "FAILED" 69 purge "$WORK_DIR" 70 exit 1 71 fi 72 73 sleep 1; 74 if pgrep minio; then 75 # forcibly killing, to proceed further properly. 76 if ! pkill -9 minio; then 77 echo "no minio process running anymore, proceed." 78 fi 79 fi 80 } 81 82 83 function check_online() { 84 if grep -q 'Server switching to safe mode' ${WORK_DIR}/dist-minio-*.log; then 85 echo "1" 86 fi 87 } 88 89 function purge() 90 { 91 rm -rf "$1" 92 } 93 94 function __init__() 95 { 96 echo "Initializing environment" 97 mkdir -p "$WORK_DIR" 98 mkdir -p "$MINIO_CONFIG_DIR" 99 100 ## version is purposefully set to '3' for minio to migrate configuration file 101 echo '{"version": "3", "credential": {"accessKey": "minio", "secretKey": "minio123"}, "region": "us-east-1"}' > "$MINIO_CONFIG_DIR/config.json" 102 } 103 104 function perform_test() { 105 start_minio_3_node 60 106 107 echo "Testing Distributed Erasure setup healing of drives" 108 echo "Remove the contents of the disks belonging to '${1}' erasure set" 109 110 rm -rf ${WORK_DIR}/${1}/*/ 111 112 start_minio_3_node 60 113 114 rv=$(check_online) 115 if [ "$rv" == "1" ]; then 116 pkill -9 minio 117 for i in $(seq 1 3); do 118 echo "server$i log:" 119 cat "${WORK_DIR}/dist-minio-server$i.log" 120 done 121 echo "FAILED" 122 purge "$WORK_DIR" 123 exit 1 124 fi 125 } 126 127 function main() 128 { 129 perform_test "2" 130 perform_test "1" 131 perform_test "3" 132 } 133 134 ( __init__ "$@" && main "$@" ) 135 rv=$? 136 purge "$WORK_DIR" 137 exit "$rv"