|
| 1 | +#!/usr/bin/bash |
| 2 | + |
| 3 | +# This script was initially written to solve the bug: |
| 4 | +# https://bugzilla.redhat.com/show_bug.cgi?id=1405447 |
| 5 | +# |
| 6 | +# Comment #1: |
| 7 | +# 1. Disks ( RAID volumes ) should be blank and should not contain any |
| 8 | +# partition table. If there are MBR/GPT partition style information available, |
| 9 | +# gdeploy should throw proper warning and stop proceeding |
| 10 | + |
| 11 | +# 2. Network configuration. |
| 12 | +# The hostname of the server should resolve to the same IP address on all |
| 13 | +# the servers. |
| 14 | + |
| 15 | +DATE=`date '+%Y_%m_%d'` |
| 16 | +PATTERN=host_ip_${DATE}.txt |
| 17 | +FILE=/tmp/`hostname`_$PATTERN |
| 18 | + |
| 19 | +cleanup () |
| 20 | +{ |
| 21 | + # Clean up after the work is done |
| 22 | + /bin/rm /tmp/*_${PATTERN} |
| 23 | +} |
| 24 | + |
| 25 | +host_resolvability_check () |
| 26 | +{ |
| 27 | + # Check if the given hostnames resolve to same ip address on all the |
| 28 | + # machines. |
| 29 | + # Use ping to get the ip address (don't bother with `dig +short' or `host' |
| 30 | + # and other friends. If the hostsnames are configured in /etc/hosts the |
| 31 | + # above commands fail. ping is reliable source for now. |
| 32 | + |
| 33 | + # Cleanup any existing data |
| 34 | + :> $FILE |
| 35 | + |
| 36 | + # Choose one of the nodes as master |
| 37 | + MASTER=`echo $1 | cut -d, -f1` |
| 38 | + for hostname in `echo $1 | tr ',' ' '`; do |
| 39 | + # Get the ip address for the hostname, if ping fails we exit |
| 40 | + # immediately. The given hostname is not pingable |
| 41 | + ip=`ping -c1 -q $hostname | awk '/PING/ { print $3}' | |
| 42 | + sed -e 's/(//' -e 's/)//'` |
| 43 | + |
| 44 | + if [ -z $ip ]; then |
| 45 | + echo "ping failed unable to reach $hostname" |
| 46 | + fi |
| 47 | + |
| 48 | + if [ "X$hostname" = "X$MASTER" ]; then |
| 49 | + MASTERIP=$ip |
| 50 | + fi |
| 51 | + |
| 52 | + cat <<EOF>>${FILE} |
| 53 | +$hostname $ip |
| 54 | +EOF |
| 55 | + done |
| 56 | +
|
| 57 | + # Sort the contents of the file |
| 58 | + sort ${FILE} -o ${FILE} |
| 59 | +
|
| 60 | + # Copy all the files to MASTER and compare |
| 61 | + match=0 |
| 62 | + if ifconfig | egrep -q $MASTERIP; then |
| 63 | + # Give some time for the operation to finish on other nodes |
| 64 | + sleep 2 |
| 65 | + for node in `echo $1 | tr ',' ' '`; do |
| 66 | + if [ "$node" = "$MASTER" ]; then |
| 67 | + continue |
| 68 | + fi |
| 69 | + ip=`ping -c1 -q $node | awk '/PING/ { print $3}' | |
| 70 | + sed -e 's/(//' -e 's/)//'` |
| 71 | + scp $ip:/tmp/*_${PATTERN} /tmp/ |
| 72 | + done |
| 73 | + # Compare the files |
| 74 | + for file in /tmp/*_${PATTERN}; do |
| 75 | + if ! diff -q $FILE $file; then |
| 76 | + match=1 |
| 77 | + echo "ip address and hostname does not match" |
| 78 | + fi |
| 79 | + done |
| 80 | + if [ $match -eq 1 ]; then |
| 81 | + exit 2 |
| 82 | + fi |
| 83 | + fi |
| 84 | + # In case of successful run, clean up the files |
| 85 | + # We leave behind the files for the user to examine the errors |
| 86 | + cleanup |
| 87 | +} |
| 88 | +
|
| 89 | +partition_table_check () |
| 90 | +{ |
| 91 | + # Check the partition table, if GPT exit with non zero status |
| 92 | + for disk in `echo $1 | tr ',' ' '`; do |
| 93 | + # Handle absolute paths as well |
| 94 | + if fdisk -l /dev/`basename $disk` 2>/dev/null | \ |
| 95 | + grep 'Disk label.*gpt$' ; then |
| 96 | + echo "Disk $disk contains GPT disk label, exiting!" |
| 97 | + exit 2 |
| 98 | + fi |
| 99 | + done |
| 100 | +} |
| 101 | +
|
| 102 | +main () |
| 103 | +{ |
| 104 | + if [ $# -eq 0 ]; then |
| 105 | + echo "Usage: $0 -d disks -h hosts" |
| 106 | + fi |
| 107 | +
|
| 108 | + # Values to option -d should be like: -d vda,vdb or -d "vda vdb" |
| 109 | + while getopts "d:h:" opt; do |
| 110 | + case $opt in |
| 111 | + d) |
| 112 | + disks="$OPTARG" |
| 113 | + partition_table_check "$disks" |
| 114 | + ;; |
| 115 | + h) |
| 116 | + hosts="$OPTARG" |
| 117 | + host_resolvability_check $hosts |
| 118 | + ;; |
| 119 | + esac |
| 120 | + done |
| 121 | + shift $((OPTIND-1)) |
| 122 | +} |
| 123 | +
|
| 124 | +main "$@" |
0 commit comments