github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/buildscripts/verify-healing.sh (about)

     1  #!/bin/bash -e
     2  #
     3  
     4  set -E
     5  set -o pipefail
     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="$PWD/.verify-$RANDOM"
    13  MINIO_CONFIG_DIR="$WORK_DIR/.minio"
    14  MINIO=("$PWD/minio" --config-dir "$MINIO_CONFIG_DIR" server)
    15  
    16  function start_minio_3_node() {
    17  	export MINIO_ROOT_USER=minio
    18  	export MINIO_ROOT_PASSWORD=minio123
    19  	export MINIO_ERASURE_SET_DRIVE_COUNT=6
    20  	export MINIO_CI_CD=1
    21  
    22  	start_port=$2
    23  	args=""
    24  	for i in $(seq 1 3); do
    25  		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/"
    26  	done
    27  
    28  	"${MINIO[@]}" --address ":$((start_port + 1))" $args >"${WORK_DIR}/dist-minio-server1.log" 2>&1 &
    29  	pid1=$!
    30  	disown ${pid1}
    31  
    32  	"${MINIO[@]}" --address ":$((start_port + 2))" $args >"${WORK_DIR}/dist-minio-server2.log" 2>&1 &
    33  	pid2=$!
    34  	disown $pid2
    35  
    36  	"${MINIO[@]}" --address ":$((start_port + 3))" $args >"${WORK_DIR}/dist-minio-server3.log" 2>&1 &
    37  	pid3=$!
    38  	disown $pid3
    39  
    40  	sleep "$1"
    41  
    42  	if ! ps -p $pid1 1>&2 >/dev/null; then
    43  		echo "server1 log:"
    44  		cat "${WORK_DIR}/dist-minio-server1.log"
    45  		echo "FAILED"
    46  		purge "$WORK_DIR"
    47  		exit 1
    48  	fi
    49  
    50  	if ! ps -p $pid2 1>&2 >/dev/null; then
    51  		echo "server2 log:"
    52  		cat "${WORK_DIR}/dist-minio-server2.log"
    53  		echo "FAILED"
    54  		purge "$WORK_DIR"
    55  		exit 1
    56  	fi
    57  
    58  	if ! ps -p $pid3 1>&2 >/dev/null; then
    59  		echo "server3 log:"
    60  		cat "${WORK_DIR}/dist-minio-server3.log"
    61  		echo "FAILED"
    62  		purge "$WORK_DIR"
    63  		exit 1
    64  	fi
    65  
    66  	if ! pkill minio; then
    67  		for i in $(seq 1 3); do
    68  			echo "server$i log:"
    69  			cat "${WORK_DIR}/dist-minio-server$i.log"
    70  		done
    71  		echo "FAILED"
    72  		purge "$WORK_DIR"
    73  		exit 1
    74  	fi
    75  
    76  	sleep 1
    77  	if pgrep minio; then
    78  		# forcibly killing, to proceed further properly.
    79  		if ! pkill -9 minio; then
    80  			echo "no minio process running anymore, proceed."
    81  		fi
    82  	fi
    83  }
    84  
    85  function check_online() {
    86  	if ! grep -q 'Status:' ${WORK_DIR}/dist-minio-*.log; then
    87  		echo "1"
    88  	fi
    89  }
    90  
    91  function purge() {
    92  	rm -rf "$1"
    93  }
    94  
    95  function __init__() {
    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 120 $2
   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  	set -x
   113  	start_minio_3_node 120 $2
   114  
   115  	rv=$(check_online)
   116  	if [ "$rv" == "1" ]; then
   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  		pkill -9 minio
   122  		echo "FAILED"
   123  		purge "$WORK_DIR"
   124  		exit 1
   125  	fi
   126  }
   127  
   128  function main() {
   129  	# use same ports for all tests
   130  	start_port=$(shuf -i 10000-65000 -n 1)
   131  
   132  	perform_test "2" ${start_port}
   133  	perform_test "1" ${start_port}
   134  	perform_test "3" ${start_port}
   135  }
   136  
   137  (__init__ "$@" && main "$@")
   138  rv=$?
   139  purge "$WORK_DIR"
   140  exit "$rv"